-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
72 lines (59 loc) · 1.75 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
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
#!/usr/bin/env python3
# #############################################################################
# test.py
# =======
# Author : Matthieu Simeoni [matthieu.simeoni@gmail.com]
# #############################################################################
"""
Run tests.
"""
import argparse
import pathlib
import subprocess
import sys
project_root_dir = pathlib.Path(__file__).parent.absolute()
cmds = dict(
doctest=[f'sphinx-build -b doctest "{project_root_dir}/doc" "{project_root_dir}/build/doctest"']
)
parser = argparse.ArgumentParser(
description="pycsou-gsp test runner.",
epilog="When run with no arguments, all tests are executed.",
)
parser.add_argument("-e", help="Name of test to run.", type=str, choices=cmds.keys())
args = parser.parse_args()
def run_test(test_name):
"""
Execute a test on the command line.
Parameters
----------
test_name : str
Name of a key in `cmds`.
"""
if not isinstance(test_name, str):
raise ValueError("Parameter[test_name] must be a str.")
if test_name not in cmds:
raise ValueError("Parameter[test_name] is not a valid test.")
status = subprocess.run(
"; ".join(cmds[test_name]),
stdin=None,
stdout=sys.stdout,
stderr=sys.stderr,
shell=True,
cwd=project_root_dir,
)
return status
if __name__ == "__main__":
status = []
if args.e is None:
for test in cmds:
s = run_test(test)
status.append(s)
else:
s = run_test(args.e)
status.append(s)
print("\nSummary\n=======")
for s in status:
print("Success" if (s.returncode == 0) else "Failure")
cmd_list = s.args.split("; ")
for c in cmd_list:
print(f" {c}")