-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_unit.py
executable file
·38 lines (31 loc) · 1.21 KB
/
test_unit.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
#!/usr/bin/env python3
import unittest
import os
import shutil
import tempfile
import subprocess as sub
root_dir = (
sub.check_output("git rev-parse --show-toplevel", shell=True).decode().strip()
)
class TestExamples(unittest.TestCase):
def test_examples(self):
path = os.path.join(root_dir, "test")
pgm_path = os.path.join(path, "pgms")
for example in os.listdir(pgm_path):
script_path = os.path.join(pgm_path, example)
output_path = os.path.join(path, "pgm_outputs", "{}.out".format(example))
print("Testing {}".format(script_path))
process_result = sub.run(
["python3", script_path],
stdout=sub.PIPE,
stderr=sub.STDOUT, # merge output streams
)
with open(output_path, "r") as f:
expected_output = f.read()
if expected_output != process_result.stdout.decode():
print("Output mismatch")
print("Expected ouput: <{}>".format(expected_output))
print("Actual output: <{}>".format(process_result.stdout.decode()))
assert False, "Output mismatch"
if __name__ == "__main__":
unittest.main()