diff --git a/README.md b/README.md index aa9d51f..5c61899 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,14 @@ ## Requirements -The webserver is a python application that requires `>=python3.8` and the +The web server is a python application that requires `>=python3.11` and the package installer for python `pip`. The node package management `npm` is also -necessary in order to install the javascript libraries. +necessary in order to install javascript libraries. ```sh sudo apt install python3 python3-pip npm # Ubuntu -sudo pkg install python38 py38-sqlite3 py38-pip npm # FreeBSD -sudo port install python38 py38-pip py38-setuptools npm6 # MacOS (macports) +sudo pkg install python py311-sqlite3 py311-pip npm # FreeBSD +sudo port install python312 py312-pip py312-setuptools npm10 # MacOS (macports) ``` To make the `pip` install packages to a local directory, the file `pip.conf` diff --git a/perguntations/testfactory.py b/perguntations/testfactory.py index d9d98fd..93fea36 100644 --- a/perguntations/testfactory.py +++ b/perguntations/testfactory.py @@ -9,7 +9,8 @@ import random import logging # other libraries -import schema +# import schema +from schema import And, Or, Optional, Regex, Schema, Use # this project from .questions import QFactory, QuestionException, QDict @@ -41,34 +42,35 @@ def check_import_files(files: list) -> bool: return True -def normalize_question_list(questions: list) -> None: - """convert question ref from string to list of string""" - for question in questions: - if isinstance(question["ref"], str): - question["ref"] = [question["ref"]] - - -test_schema = schema.Schema( +test_schema = Schema( { - "ref": schema.Regex("^[a-zA-Z0-9_-]+$"), - "database": schema.And(str, path.isfile), - "answers_dir": schema.And(str, check_answers_directory), + "ref": Regex("^[a-zA-Z0-9_-]+$"), + "database": And(str, path.isfile), + "answers_dir": Use(check_answers_directory), "title": str, - schema.Optional("duration"): int, - schema.Optional("autosubmit"): bool, - schema.Optional("autocorrect"): bool, - schema.Optional("show_points"): bool, - schema.Optional("scale"): schema.And( - [schema.Use(float)], lambda s: len(s) == 2 - ), - "files": schema.And([str], check_import_files), - "questions": [{"ref": schema.Or(str, [str]), schema.Optional("points"): float}], + Optional("duration"): int, + Optional("autosubmit"): bool, + Optional("autocorrect"): bool, + Optional("show_points"): bool, + Optional("scale"): And([Use(float)], lambda s: len(s) == 2), + "files": And([str], check_import_files), + "questions": [{ + "ref": Or(str, [str]), + Optional("points"): float + }], }, ignore_extra_keys=True, ) # FIXME: schema error with 'testfile' which is added in the code # ============================================================================ +def normalize_question_list(questions: list) -> None: # FIXME: move inside the class? + """convert question ref from string to list of string""" + for question in questions: + if isinstance(question["ref"], str): + question["ref"] = [question["ref"]] + + class TestFactoryException(Exception): """exception raised in this module""" -- libgit2 0.21.2