diff options
-rw-r--r-- | ExampleSubmission/animals.py | 2 | ||||
-rw-r--r-- | examplerun.bat | 2 | ||||
-rw-r--r-- | mark.py | 9 | ||||
-rw-r--r-- | pytest_template.jinja2 | 8 | ||||
-rw-r--r-- | reflect.py | 37 | ||||
l--------- | templates/text.jinja2 | bin | 10 -> 28 bytes | |||
-rw-r--r-- | templates/txt.jinja2 | 3 |
7 files changed, 38 insertions, 23 deletions
diff --git a/ExampleSubmission/animals.py b/ExampleSubmission/animals.py index a8c76d8..d32d6ff 100644 --- a/ExampleSubmission/animals.py +++ b/ExampleSubmission/animals.py @@ -20,3 +20,5 @@ class Kitten(Cat): """
def speak(self):
return "meow (but cuter)"
+
+print()
\ No newline at end of file diff --git a/examplerun.bat b/examplerun.bat index 6ca9a04..338908c 100644 --- a/examplerun.bat +++ b/examplerun.bat @@ -1,3 +1,3 @@ zip -r 100301654.zip .\ExampleSubmission\
-python .\mark.py -s 100301654.zip -a .\ExampleAssessments\example.yml -f yaml
+python .\mark.py -s 100301654.zip -a .\ExampleAssessments\example.yml
rm 100301654.zip
\ No newline at end of file @@ -38,10 +38,11 @@ class FileDependencies: pass for file_dep in stuff_to_remove: - if os.path.isfile(file_dep): - os.remove(file_dep) - else: - shutil.rmtree(file_dep) + if os.path.exists(file_dep): + if os.path.isfile(file_dep): + os.remove(file_dep) + else: + shutil.rmtree(file_dep) def main(**kwargs): student_no = os.path.splitext(os.path.split(args["submission"])[-1])[0] diff --git a/pytest_template.jinja2 b/pytest_template.jinja2 new file mode 100644 index 0000000..fad41db --- /dev/null +++ b/pytest_template.jinja2 @@ -0,0 +1,8 @@ +{# generating python with python :3 #} + +import {{ module }} + +{% for i, test_code in enumerate(filestests, 1) %} +def test_{{ i }}(): +{{ test_code|indent(4, True) }} {# the code in the config file must be indented with 4 spaces only #} +{% endfor %}
\ No newline at end of file @@ -9,6 +9,7 @@ import tempfile import inspect import pkgutil import shutil +import jinja2 import sys import os import re @@ -186,22 +187,23 @@ class Reflect: """ test_results = {} test_results["pytest_report"] = "" - for filename, filestests in tests.items(): - with open(os.path.join(self.client_code_path, "test_" + filename), "a") as f: - for m in self.client_modules: - f.write("import %s\n" % m.name) - f.write("\n") + + with open("pytest_template.jinja2", "r") as f: + jinja_template = jinja2.Template(f.read()) - for i, test_code in enumerate(filestests, 1): - f.write("def test_%d():\n" % i) - for line in test_code.split("\n"): - f.write(" %s\n" % line.rstrip()) - f.write("\n") + for filename, filestests in tests.items(): + with open(os.path.join(self.client_code_path, "test_" + filename), "w") as f: + f.write(jinja_template.render( + module = os.path.splitext(filename)[0], + filestests = filestests, + enumerate = enumerate # a function thats needed + )) with tempfile.TemporaryDirectory() as tmp: junitxmlpath = os.path.join(tmp, "report.xml") test_files = [os.path.join(self.client_code_path, "test_%s" % f) for f in tests.keys()] cmd = ["pytest", "-v"] + test_files + ["--junitxml=%s" % junitxmlpath] + # print("cmd: ", " ".join(cmd)) if test_files == []: test_results["pytest_report"] = "*** No Tests ***" return test_results @@ -318,13 +320,14 @@ def gen_reflection_report(client_code_path, assessment_struct, student_no, confi if "tests" in required_files_features.keys(): filename = list(assessment_struct["files"][i].keys())[0] - for j, test in enumerate(assessment_struct["files"][i][required_file]["tests"], 0): - try: - tests_to_run[filename].append(test) - except KeyError: - tests_to_run[filename] = [test] - - out["test_results"] = reflection.run_tests(tests_to_run, configuration["out"] == "stdout") + if not out["files"][i][filename]["has_exception"]: + for j, test in enumerate(assessment_struct["files"][i][required_file]["tests"], 0): + try: + tests_to_run[filename].append(test) + except KeyError: + tests_to_run[filename] = [test] + + 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 diff --git a/templates/text.jinja2 b/templates/text.jinja2 Binary files differindex aad87bd..eca6ebd 120000 --- a/templates/text.jinja2 +++ b/templates/text.jinja2 diff --git a/templates/txt.jinja2 b/templates/txt.jinja2 index 0a9cdb5..97752fd 100644 --- a/templates/txt.jinja2 +++ b/templates/txt.jinja2 @@ -11,7 +11,8 @@ {%- if files_contents["present"] -%} {%- if files_contents["has_exception"] %} *** File cannot be run - has compile time exception *** - Please note that this file cannot be analysed or have tests preformed upon it + Please note that this file cannot be analysed or have tests preformed upon it- + this can lead to the whole test suite failing if another module imports this. Exception Type: {{ files_contents["exception"]["type"] }} Exception String: |