summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2022-02-10 14:32:13 +0000
committerjwansek <eddie.atten.ea29@gmail.com>2022-02-10 14:32:13 +0000
commitd7485e7632c3625a6c179e12cecbc5b0c1bb73bd (patch)
tree920b290c4d22786d93da111a67098dca2f69efd8
parent8966f20ccb9897282d2ac7c174b87934fc38fc15 (diff)
downloadSmarker-d7485e7632c3625a6c179e12cecbc5b0c1bb73bd.tar.gz
Smarker-d7485e7632c3625a6c179e12cecbc5b0c1bb73bd.zip
finished runtime analysis, added text output
-rw-r--r--ExampleAssessments/example.yml4
-rw-r--r--examplerun.bat2
-rw-r--r--jinja_helpers.py3
-rw-r--r--reflect.py51
-rw-r--r--smarker.conf5
-rw-r--r--templates/txt.jinja224
6 files changed, 61 insertions, 28 deletions
diff --git a/ExampleAssessments/example.yml b/ExampleAssessments/example.yml
index b6e7b12..c8192a1 100644
--- a/ExampleAssessments/example.yml
+++ b/ExampleAssessments/example.yml
@@ -23,6 +23,9 @@ files:
dateTwo = example.MyDate(day = 5, month = 4, year = 1999)
assert dateOne == dateTwo
run:
+ - python example.py 3:
+ regexes:
+ - hello world\!
- python example.py 1:
regexes:
- hello world\!
@@ -46,6 +49,7 @@ files:
monitor: animals.txt
regexes:
- TURRÓN
+ - meow \(but cuter\)
produced_files:
- animals.txt
dependencies:
diff --git a/examplerun.bat b/examplerun.bat
index 8ddbc7d..2c5217d 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 -f txt -o auto
rm 100301654.zip \ No newline at end of file
diff --git a/jinja_helpers.py b/jinja_helpers.py
index faf6266..86b02e2 100644
--- a/jinja_helpers.py
+++ b/jinja_helpers.py
@@ -45,6 +45,9 @@ def len_documentation(comments, docs):
return commentlen + docslen
+def len_(obj):
+ return len(obj)
+
def get_source_numlines(source):
return "%d lines (%d characters)" % (source.count("\n"), len(source))
diff --git a/reflect.py b/reflect.py
index 531c41b..6ee470a 100644
--- a/reflect.py
+++ b/reflect.py
@@ -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
diff --git a/smarker.conf b/smarker.conf
index 44aea24..84d8c5c 100644
--- a/smarker.conf
+++ b/smarker.conf
@@ -9,5 +9,6 @@ show_full_docs = True
show_source = True
[txt]
-show_full_docs = True
-show_source = True \ No newline at end of file
+show_full_docs = False
+show_source = False
+show_all_regex_occurrences = True \ No newline at end of file
diff --git a/templates/txt.jinja2 b/templates/txt.jinja2
index 5ab8776..df63288 100644
--- a/templates/txt.jinja2
+++ b/templates/txt.jinja2
@@ -103,6 +103,30 @@ Report generated at {{ get_datetime() }}
{{ expand_function(function_name, function_contents)|indent(12, False) }}
{%- endfor -%}
{%- endif -%}
+ {% if "run" in files_contents.keys() %}
+ Runtime Analysis:
+ {%- set flat_runtime = flatten_struct(files_contents["run"]) %}
+ {%- for cmd, runtime_contents in flat_runtime.items() %}
+ Command `{{ cmd }}`:
+ Monitor:
+ {%- if "monitor" in runtime_contents.keys() %}
+ {{ runtime_contents["monitor"] }}
+ {%- else %}
+ stdout
+ {%- endif %}
+ Regexes:
+ {%- for regex_, results in runtime_contents["regexes"].items() %}
+ `{{regex_}}`:
+ Found occurrences: {{ len_(results) }}
+ {%- if txt_show_all_regex_occurrences == "True" and len_(results) > 0 %}
+ Occurrences list:
+ {%- for result in results %}
+ {{ result }}
+ {%- endfor -%}
+ {%- endif -%}
+ {%- endfor -%}
+ {%- endfor -%}
+ {%- endif -%}
{%- endif -%}
{% else %}
*** File not present ***