-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·80 lines (66 loc) · 2.19 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
#!/usr/bin/env python3
from glob import glob
from json import dumps, load
from os import environ
from os.path import isdir, join
from sys import argv, exit
def run_single_test(data_dir, output_dir):
from pytest import main
exit(main(['-vvs', '-p', 'no:cacheprovider', join(data_dir, 'test.py')]))
def check_test(data_dir):
pass
def grade(data_path):
results = load(open(join(data_path, 'results.json')))
max_mark = 20
grade_mapping = [
0.5, 0.5, 1.0, 1.5, 2.0, 1.0, 2.0,
1.0, 2.0, 1.5, 2.0, 1.0, 1.0, 3.0
]
total_grade = 0
ok_count = 0
for result, grade in zip(results, grade_mapping):
if result['status'] == 'Ok':
total_grade += grade
ok_count += 1
total_count = len(results)
description = '%02d/%02d' % (ok_count, total_count)
mark = total_grade / sum(grade_mapping[:len(results)]) * max_mark
res = {'description': description, 'mark': mark}
if environ.get('CHECKER'):
print(dumps(res))
return res
if __name__ == '__main__':
if environ.get('CHECKER'):
# Script is running in testing system
if len(argv) != 4:
print('Usage: %s mode data_dir output_dir' % argv[0])
exit(0)
mode = argv[1]
data_dir = argv[2]
output_dir = argv[3]
if mode == 'run_single_test':
run_single_test(data_dir, output_dir)
elif mode == 'check_test':
check_test(data_dir)
elif mode == 'grade':
grade(data_dir)
else:
# Script is running locally
if len(argv) != 3:
print(f'Usage: {argv[0]} test/unittest test_name')
exit(0)
mode = argv[1]
test_name = argv[2]
if not isdir('tests'):
print(
"Directory `tests` not found\n"
"Please create it and extract there all "
"folders with tests from public_data.zip"
)
exit(1)
test_dir = glob(f'tests/[0-9][0-9]_{mode}_{test_name}_input')
if not test_dir:
print('Test not found')
exit(0)
from pytest import main
exit(main(['-vvxs', join(test_dir[0], 'test.py')]))