-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (44 loc) · 1.48 KB
/
main.py
File metadata and controls
56 lines (44 loc) · 1.48 KB
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
from pathlib import Path
from cli import parse_args
from runner.test_case import TestCase
from runner.executor import execute
from runner.comparator import compare
from runner.reporter import TestReport, print_report
from runner.errors import InvalidTestDirectory
def main():
args = parse_args()
test_dir = Path(args.tests)
if not test_dir.exists() or not test_dir.is_dir():
raise InvalidTestDirectory(test_dir)
base_names = sorted({p.stem for p in test_dir.glob("*.in")})
reports = []
for name in base_names:
test = TestCase.from_directory(test_dir, name, args.timeout)
result = execute(args.program, test.input_data, test.timeout)
if result.timeout:
reports.append(
TestReport(
name=name,
passed=False,
reason="timeout",
)
)
continue
comparison = compare(
actual_stdout=result.stdout,
actual_stderr=result.stderr,
actual_returncode=result.returncode,
expected_stdout=test.expected_stdout,
expected_stderr=test.expected_stderr,
expected_returncode=test.expected_returncode,
)
reports.append(
TestReport(
name=name,
passed=comparison.success,
reason=comparison.reason or "",
)
)
print_report(reports)
if __name__ == "__main__":
main()