-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathvalidTest.py
More file actions
72 lines (57 loc) · 2.02 KB
/
validTest.py
File metadata and controls
72 lines (57 loc) · 2.02 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys
def check_output(outtext, f):
if outtext == "OK\n":
pass
else:
raise RuntimeError("Function failed", outtext, f.__name__)
def check_test_function(f):
from io import StringIO
import sys
capturer = StringIO()
old_stdout = sys.stdout
sys.stdout = capturer
f()
sys.stdout = old_stdout
check_output(capturer.getvalue(), f)
def check_async_test_function(f):
from io import StringIO
import sys
import asyncio
capturer = StringIO()
old_stdout = sys.stdout
sys.stdout = capturer
asyncio.run(f())
sys.stdout = old_stdout
check_output(capturer.getvalue(), f)
def check_tests_valid(testFile):
import importlib
tests = importlib.import_module(testFile)
for i in dir(tests):
# print("Considering", i)
if i.startswith("test_"):
item = getattr(tests, i)
if callable(item):
print("Checking", testFile, item.__name__)
check_test_function(item)
elif i.startswith("atest_"):
item = getattr(tests, i)
if callable(item):
print("Checking", testFile, item.__name__)
check_async_test_function(item)
if __name__ == "__main__":
check_tests_valid("coverage.classes")
check_tests_valid("coverage.test")
check_tests_valid("coverage.argumentPassing")
check_tests_valid("variable-capture.in")
check_tests_valid("variable-capture.nonlocal")
check_tests_valid("variable-capture.dict")
check_tests_valid("module-initialization.multiphase")
check_tests_valid("fieldflow.test")
if sys.version_info[:2] >= (3, 10):
print("INFO: Will run `match` tests since we're running Python 3.10 or newer")
check_tests_valid("match.test")
else:
print("WARN: Skipping `match` tests since we're not running 3.10 or newer")
# The below fails when trying to import modules
# check_tests_valid("module-initialization.test")
# check_tests_valid("module-initialization.testOnce")