diff options
Diffstat (limited to 'reflect.py')
-rw-r--r-- | reflect.py | 51 |
1 files changed, 26 insertions, 25 deletions
@@ -19,8 +19,6 @@ import re @dataclass class Reflect: client_code_path:str - assessment_struct:dict - zip_file:str imported_modules = {} def __post_init__(self): @@ -232,7 +230,7 @@ class Reflect: return str(doc[1]).rstrip() def gen_reflection_report(client_code_path, assessment_struct, student_no, configuration, zip_file): - reflection = Reflect(client_code_path, assessment_struct, zip_file) + reflection = Reflect(client_code_path) present_module_names = [i.name for i in reflection.client_modules] out = assessment_struct out["student_no"] = student_no @@ -336,35 +334,38 @@ def gen_reflection_report(client_code_path, assessment_struct, student_no, confi tests_to_run[filename] = [test] if "run" in required_files_features.keys(): + filename = list(assessment_struct["files"][i].keys())[0] with misc_classes.ExtractZipToTempDir(zip_file) as tempdir: with misc_classes.FileDependencies(assessment_struct, tempdir): with misc_classes.ChangeDirectory(tempdir): - for cmd, contents in jinja_helpers.flatten_struct(required_files_features["run"]).items(): - - lines = "" - if "monitor" in contents.keys(): - - if contents["monitor"] not in produced_files: - raise MonitoredFileNotInProducedFilesException("The monitored file %s is not in the list of produced files. It needs to be added." % contents["monitor"]) - - subprocess.run(cmd.split()) - with open(contents["monitor"], "r") as f: - lines = f.read() + for j, runtime in enumerate(assessment_struct["files"][i][required_file]["run"], 0): + for cmd, contents in runtime.items(): + lines = "" + if "monitor" in contents.keys(): + + if contents["monitor"] not in produced_files: + raise MonitoredFileNotInProducedFilesException("The monitored file %s is not in the list of produced files. It needs to be added." % contents["monitor"]) + + subprocess.run(cmd.split()) + with open(contents["monitor"], "r") as f: + lines = f.read() + + else: + proc = subprocess.Popen(cmd.split(), stdout = subprocess.PIPE) + while True: + line = proc.stdout.readline() + if not line: + break + lines += line.decode() - else: - proc = subprocess.Popen(cmd.split(), stdout = subprocess.PIPE) - while True: - line = proc.stdout.readline() - if not line: - break - lines += line.decode() - - print("===Lines===") - print(lines) + matches = {} + for regex_ in contents["regexes"]: + matches[regex_] = re.findall(regex_, lines) + required_files_features["run"][j][cmd]["regexes"] = matches out["test_results"] = reflection.run_tests(tests_to_run, configuration["out"] == "stdout" and configuration["format"] in ["text", "txt"]) out["class_tree"] = reflection.get_class_tree() - # return out + return out class MonitoredFileNotInProducedFilesException(Exception): pass |