-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·106 lines (85 loc) · 2.84 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python3
# Name: Extract PLUnit results
# By Robbert Gurdeep Singh
##########################################################################
"""
The runner called by run,
Finds testfiles and executes them in the correct subjudge
Also executes the formatcheck for linting
"""
import os
import sys
import json
import itertools
from plunit import PLUnit
from quickcheck import QuickCheck
from simpltest import SimpleTest
from formcheck import FormCheck
# extract info from exercise configuration and set defaults
config = json.load(sys.stdin)
home = config['resources']
source = config['source']
workdir = config['workdir']
judge = config['judge']
time_limit = int(config['time_limit'])
memory_limit = int(config['memory_limit'])
programming_language = config['programming_language']
config.setdefault("prolog_stack_limit", "256m")
# Fallback for natural lanugage
if config.get("natural_language", None) not in ["en", "nl"]:
config["natural_language"] = "en"
# Collect tests to perform
# Always FormCheck, add others if the correct files exist
tests = [FormCheck(config)]
for f in os.listdir(home):
test = None
fullPath = os.path.join(home, f)
if f.endswith(".unit.pl"):
test = PLUnit(config, fullPath, f.replace(".unit.pl", ""))
elif f.endswith(".qc.pl"):
test = QuickCheck(config, fullPath, f.replace(".qc.pl", ""))
elif f.endswith(".simple.pl"):
test = SimpleTest(config, fullPath, f.replace(".simple.pl", ""))
if test is not None:
tests.append(test)
tabs = [t.getResult() for t in tests if t.getResult() is not None]
annotations = list(itertools.chain.from_iterable(
[t.getAnnotations() for t in tests if t.getAnnotations() is not None]))
numBad = sum([t["badgeCount"] for t in tabs])
accepted = all([t["accepted"] for t in tabs])
description = "issues({}).".format(numBad)
messages = []
annotationDescription = None
annotationCount = {"error": 0, "warning": 0, "info": 0}
if annotations:
for a in annotations:
annotationCount[a["type"]] += 1
for t in ["error", "warning", "info"]:
if annotationCount[t] > 0:
annotationDescription = "{}s({}).".format(t, annotationCount[t])
break
if accepted:
description = "true."
status = "correct"
if annotationDescription:
description = annotationDescription
if annotationCount["error"] > 0:
status = "compilation error"
accepted = False
else:
if numBad == 0:
description = "error."
status = "runtime error"
else:
status = "wrong"
if annotationCount["error"] > 0:
status = "compilation error"
feedback = {
"accepted": accepted,
"groups": tabs,
"status": status,
"messages": messages,
"description": description,
"annotations": annotations
}
print(json.dumps(feedback, indent=2, separators=(',', ': ')))