grading_lib.common#
Module Contents#
Classes#
TextTestResult without the traceback. |
|
A base class for test case. |
|
A generator that will be run during the generation.yml workflow. |
Functions#
Return True if the DEBUG envrionment variable is presence with value representing ‘True’. |
|
Run a command at the cwd. |
Data#
API#
- grading_lib.common.COMMAND_FAILED_TEXT_TEMPLATE = <Multiline-String>#
- grading_lib.common.FILE_NOT_EXIST_TEXT_TEMPLATE = "File '{path}' does not exist"#
- grading_lib.common.DEFAULT_FILENAME_POOL = ['main.cpp', 'file.txt']#
- grading_lib.common.FILE_SUFFIX_POOL = ['.cpp', '.txt', '.md', '.zip', '.py', '.toml', '.yml', '.yaml']#
- grading_lib.common.NAME_POOL = ['herta', 'cat', 'dog', 'dolphin', 'falcon', 'dandilion', 'fox', 'jett']#
- grading_lib.common.is_debug_mode(variable_name: str = 'DEBUG', vals_for_true: list[str] = ['true', 't', 'on', '1']) bool#
Return True if the DEBUG envrionment variable is presence with value representing ‘True’.
- grading_lib.common.get_seed_from_env(variable_name: str = 'SEED') int#
- grading_lib.common.get_mtime_as_datetime(path: pathlib.Path | str) datetime.datetime#
- grading_lib.common.has_file_changed(last_known_mtime: datetime.datetime, path: pathlib.Path | str) bool#
- grading_lib.common.populate_folder_with_filenames(path: pathlib.Path | str, filnames: list[str])#
- grading_lib.common.CommandResult = 'namedtuple(...)'#
- grading_lib.common.run_executable(args, cwd: Optional[str | pathlib.Path] = None) grading_lib.common.CommandResult#
Run a command at the cwd.
Return - (True, command, output) when the command completes without any error. - (False, command, output) when the command completes with error.
It will redirect stderr to stdout and capture stdout as output.
- class grading_lib.common.MinimalistTestResult(*args, **kwargs)#
Bases:
unittest.TextTestResultTextTestResult without the traceback.
Traceback is too verbose for our purpose.
Initialization
Construct a TextTestResult. Subclasses should accept **kwargs to ensure compatibility as the interface changes.
- getDescription(test)#
- addFailure(test, err)#
- class grading_lib.common.BaseTestCase(methodName='runTest')#
Bases:
unittest.TestCaseA base class for test case.
- Variables:
with_temporary_dir – When True, create a temporary directory for each test.
Initialization
Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.
- with_temporary_dir: bool = None#
- setUp()#
- tearDown() None#
- assertFileExists(path: pathlib.Path, msg_template: str = FILE_NOT_EXIST_TEXT_TEMPLATE) None#
Pass if the file at path exist.
- assertAllFilesExist(paths: list[pathlib.Path], msg=None) None#
Pass if all the listed files exist.
- assertCommandSuccessful(result: grading_lib.common.CommandResult, msg_template: str = COMMAND_FAILED_TEXT_TEMPLATE) None#
Pass if the command run successfully.
- assertCommandOutputEqual(result: grading_lib.common.CommandResult, expected_output: str, msg: Optional[str] = None) None#
Pass if the command’s output is equal to output.
The msg will be formatted with command, expected_output, output
- class grading_lib.common.GeneratorBase#
A generator that will be run during the generation.yml workflow.
It may be called by the grading script to prepare a clean copy of the content generated during the generation phase.
- abstract generate(path: pathlib.Path | str) None#
- run(path: pathlib.Path | str) None#