-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
47 lines (40 loc) · 1.67 KB
/
test.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
import json
import os
import subprocess
from termcolor import colored
ERROR_DIR = "./test/error_tests/"
ERROR_STRINGS = "./test/err_strings.json"
ERROR_CODE = 1
VALID_DIR = "./test/valid_tests/"
OPTIONS = ["-i", "-1", "-2"]
def run_valid_tests():
for input in os.listdir(VALID_DIR):
if input.endswith(".in"):
print("Test " + input + ": ", end=" ")
for option in OPTIONS:
out = subprocess.check_output(["./plg-2-nka", option, VALID_DIR + input])
with open(VALID_DIR + input.split('.')[0] + option + ".out", 'r') as ref_out:
test = out.decode("utf-8") == ref_out.read()
if test:
print(colored(option + ", ", "green"), end=" ")
else:
print(colored(option + ", ", "red"), end=" ")
print()
def run_error_tests():
with open(ERROR_STRINGS, 'r') as json_file:
error_strings = json.load(json_file)
for input in os.listdir(ERROR_DIR):
try:
subprocess.check_output(["./plg-2-nka", ERROR_DIR + input], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as output_exc:
if error_strings[input.split('.')[0]] == output_exc.output.decode("utf-8") and \
ERROR_CODE == output_exc.returncode:
print(colored("Test " + input + " successful.", 'green'))
else:
print(colored("Test " + input + " unsuccessful.", 'red'))
if __name__ == '__main__':
print(colored("Error tests:", 'blue'))
run_error_tests()
print("----------------------")
print(colored("Valid tests:", 'blue'))
run_valid_tests()