-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathrun_tests.py
executable file
·79 lines (68 loc) · 1.92 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/python
"""Script to run PyType tests.
Usage:
$> python run_tests.py [TARGET] [TARGET] ...
A TARGET is a fully qualified name of a test target within the PyType
source tree. If no target is specified, all test targets listed in the
CMake files will be run.
"""
import argparse
import sys
import build_utils
def parse_args():
"""Parse the args to this script and return them."""
parser = argparse.ArgumentParser()
parser.add_argument(
"targets",
metavar="TARGET",
nargs="*",
help="List of test targets to run.",
)
parser.add_argument(
"--fail_fast",
"-f",
action="store_true",
default=False,
help="Fail as soon as one build target fails.",
)
parser.add_argument(
"--debug",
"-d",
action="store_true",
default=False,
help="Build targets in the debug mode.",
)
parser.add_argument(
"--verbose",
"-v",
action="store_true",
default=False,
help="Print failing test logs to stderr.",
)
args = parser.parse_args()
for target in args.targets:
if "." in target:
_, target_name = target.rsplit(".", 1)
else:
target_name = target
if not (target_name.startswith("test_") or target_name.endswith("_test")):
sys.exit(f"The name '{target}' is not a valid test target name.")
return args
def main():
opts = parse_args()
targets = opts.targets or ["test_all"]
if not build_utils.run_cmake(log_output=True, debug_build=opts.debug):
sys.exit(1)
fail_collector = build_utils.FailCollector()
print("Running tests (build steps will be executed as required) ...\n")
if not build_utils.run_ninja(
targets, fail_collector, opts.fail_fast, opts.verbose
):
fail_collector.print_report(opts.verbose)
sys.exit(1)
print(
"!!! All tests passed !!!\n"
"Some tests might not have been run because they were already passing."
)
if __name__ == "__main__":
main()