From d7ae412cb45573ad4f8864f083dad24d822e9d9b Mon Sep 17 00:00:00 2001 From: Juno Steegmans Date: Mon, 19 Feb 2024 20:26:14 +0100 Subject: [PATCH 1/3] Minor fixes+additions to CLI Changes to tested.cli: - Fixed the -f/--full options actually disabling the full output rather than enabling as its documentation explains - Added a -v/--verbose and -d/--debug options that change the logger to add output info/debug level messages to the standard output stream, analogous to tested module itself enables these. Additionally if both are selected debug is used as it is a higher level than info - Fied the suite path not properly being passed to the DodonaConfig, as the config expects it relative to the resources path --- tested/cli.py | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/tested/cli.py b/tested/cli.py index 77d8c3e0..76c20c07 100644 --- a/tested/cli.py +++ b/tested/cli.py @@ -134,9 +134,20 @@ def find_status_enum(self) -> list[str]: parser.add_argument( "-f", "--full", - action="store_false", - help="If the output should be shown in full (default: false)", - default=None, + action="store_true", + help="If the output should be shown in full (default: false)" + ) + parser.add_argument( + "-v", + "--verbose", + action="store_true", + help="If the judge should be verbose in its output (default: false)" + ) + parser.add_argument( + "-d", + "--debug", + action="store_true", + help="If the judge should be outputing the debug messages (default: false)" ) parser.add_argument( "-p", @@ -177,22 +188,36 @@ def find_status_enum(self) -> list[str]: suite_path = args.testsuite.relative_to(evaluation_path) elif "evaluation" in config_file and "test_suite" in config_file["evaluation"]: # The config file contains a location, so try to use it. - suite_path = evaluation_path / config_file["evaluation"]["test_suite"] - if not suite_path.is_file(): + suite_path = config_file["evaluation"]["test_suite"] + suite_full_path = evaluation_path / suite_path + if not suite_full_path.is_file(): raise FileNotFoundError( - f"The test suite at {suite_path} does not exist (read value from the config file).\n" - "Create the file, correct the config.json file or provide the path to the test suite via the --testsuite parameter on the command line." + f"The test suite at {suite_full_path} does not exist (read value {suite_path} from the config file).\n" + "Create the file, correct the config.json file or provide the full path to the test suite via the --testsuite parameter on the command line." ) else: - suite_path = evaluation_path / "suite.yaml" - if not suite_path.is_file(): + suite_path = "suite.yaml" + suite_full_path = evaluation_path / suite_path + if not suite_full_path.is_file(): raise FileNotFoundError( - f"The test suite at {suite_path} does not exist (used default value).\n" - "Create the file, add the location to the config.json file or provide the path to the test suite via the --testsuite parameter on the command line." + f"The test suite at {suite_full_path} does not exist (used default value).\n" + "Create the file, add the location to the config.json file or provide the full path to the test suite via the --testsuite parameter on the command line." ) submission_path = find_submission() workdir_path = judge_path / "workdir" + if args.verbose or args.debug: + import logging, sys + logger = logging.getLogger() + if args.debug: + logger.setLevel(logging.DEBUG) + elif args.verbose: + logger.setLevel(logging.INFO) + ch = logging.StreamHandler(stream=sys.stdout) + formatter = logging.Formatter("%(levelname)s:%(name)s:%(message)s") + ch.setFormatter(formatter) + logger.addHandler(ch) + dodona_config = DodonaConfig( resources=evaluation_path, source=submission_path, @@ -211,7 +236,7 @@ def find_status_enum(self) -> list[str]: print(f"Locally executing exercise {exercise_path}...") print("The following options will be used:") - print(f" - Test suite: {suite_path}") + print(f" - Test suite: {evaluation_path}/{suite_path}") print(f" - Submission: {submission_path}") print("") print( From 5762b8f2710394ccb1e91b7166b94ffa0a2256cf Mon Sep 17 00:00:00 2001 From: Niko Strijbol Date: Wed, 21 Feb 2024 11:45:54 +0100 Subject: [PATCH 2/3] Update readme for changes to CLI --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11cd3bac..86e14857 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ The second way is: ```bash # Run an exercise with CLI paramaters $ python -m tested.cli --help -usage: cli.py [-h] -e EXERCISE [-s SUBMISSION] [-t TESTSUITE] [-f] [-p PROGRAMMING_LANGUAGE] +usage: cli.py [-h] -e EXERCISE [-s SUBMISSION] [-t TESTSUITE] [-f] [-v] [-d] [-p PROGRAMMING_LANGUAGE] Simple CLI for TESTed @@ -202,6 +202,8 @@ options: -t TESTSUITE, --testsuite TESTSUITE Path to a test suite -f, --full If the output should be shown in full (default: false) + -v, --verbose If the judge should be verbose in its output (default: false) + -d, --debug If the judge should be outputing the debug messages (default: false) -p PROGRAMMING_LANGUAGE, --programming_language PROGRAMMING_LANGUAGE The programming language to use From f9d704bf16d57596ac74e2538367a9134711bb97 Mon Sep 17 00:00:00 2001 From: Niko Strijbol Date: Wed, 21 Feb 2024 11:54:29 +0100 Subject: [PATCH 3/3] Apply formatting --- tested/cli.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tested/cli.py b/tested/cli.py index 76c20c07..76c9c48e 100644 --- a/tested/cli.py +++ b/tested/cli.py @@ -135,19 +135,19 @@ def find_status_enum(self) -> list[str]: "-f", "--full", action="store_true", - help="If the output should be shown in full (default: false)" + help="If the output should be shown in full (default: false)", ) parser.add_argument( "-v", "--verbose", action="store_true", - help="If the judge should be verbose in its output (default: false)" + help="If the judge should be verbose in its output (default: false)", ) parser.add_argument( "-d", "--debug", action="store_true", - help="If the judge should be outputing the debug messages (default: false)" + help="If the judge should be outputing the debug messages (default: false)", ) parser.add_argument( "-p", @@ -207,7 +207,9 @@ def find_status_enum(self) -> list[str]: workdir_path = judge_path / "workdir" if args.verbose or args.debug: - import logging, sys + import logging + import sys + logger = logging.getLogger() if args.debug: logger.setLevel(logging.DEBUG)