-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrun_tests.py
58 lines (53 loc) · 1.62 KB
/
run_tests.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
48
49
50
51
52
53
54
55
56
57
58
import argparse
import re
import unittest
from io import StringIO
from ed_utils.json_test_runner import JSONTestRunner
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument(
"task",
help=(
"The task number you'd like to run. "
"Leave blank for all tasks.\n\n"
"Example: local_run_tests.py 3\n"
"Runs the tests with @number('3.x')."
),
default="",
nargs="?",
)
p.add_argument(
"-a",
"--advanced",
help="Run the 1054 advanced tasks.",
action="store_true",
)
p.add_argument(
"-e",
"--for_ed",
help="Use if running on Ed.",
action="store_true",
)
args = p.parse_args()
suite = unittest.defaultTestLoader.discover('test_actual' if args.for_ed else '.')
for s in suite:
for t in s:
if "FailedTest" in str(type(t)):
continue
marked_remove = set()
for t2 in t:
func = getattr(t2, t2._testMethodName)
if getattr(func, "__advanced__", None) is True and not args.advanced:
marked_remove.add(t2)
elif args.task and not re.match(rf"^{args.task}\.", getattr(func, "__number__", "")):
marked_remove.add(t2)
for t2 in marked_remove:
t._tests.remove(t2)
if args.for_ed:
f = StringIO("")
runner = JSONTestRunner(stream=f)
runner.run(suite)
print(f.getvalue())
else:
runner = unittest.runner.TextTestRunner()
runner.run(suite)