-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtype_check_test.py
37 lines (28 loc) · 1.1 KB
/
type_check_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
# python -m unittest parse_test.py
import unittest
from os import walk, path
import re
from n import run_file
from parse import basepath
class AssertionTestCases(unittest.TestCase):
@classmethod
def add_assertion_test_case(cls, file_name):
file_path = path.join(basepath, "../tests/assertions/", file_name)
def test_method(self):
errors = run_file(file_path)
if isinstance(errors, str):
raise Exception(errors)
for unit_test in errors.unit_tests:
if not unit_test["hasPassed"]:
raise Exception(unit_test)
# Dynamically add methods to the class
# https://stackoverflow.com/a/17930262
setattr(cls, "test_" + re.sub(r"\W", "_", file_name[0:-2]), test_method)
# Get files in directory https://stackoverflow.com/a/3207973
_, _, file_names = next(walk(path.join(basepath, "../tests/assertions/")))
for file_name in file_names:
if not file_name.endswith(".n"):
continue
AssertionTestCases.add_assertion_test_case(file_name)
if __name__ == "__main__":
unittest.main()