forked from Aussiemon/ljd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·57 lines (42 loc) · 1.69 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
#!/usr/bin/env python3
import pathlib
import tempfile
from argparse import ArgumentParser
from test.config import Config
from test.testunit import TestResult
from test.testlist import tests as all_tests
from test.utils import Colour
def main():
parser = ArgumentParser()
parser.add_argument("tests", metavar="test", type=str, nargs="+", help="Names of tests to be run, or 'all'")
parser.add_argument("-v", "--verbose", action="store_true", help="Print per-test information")
parser.add_argument("--wait", action="store_true", help="Once the tests are complete, wait for user input before "
"deleting the artifacts")
parser.add_argument("--python", type=str, default="python3", help="Name of Python executable")
args = parser.parse_args()
config = Config()
config.verbose = args.verbose
config.python = args.python
by_name = dict()
for test in all_tests:
by_name[test.name] = test
if args.tests == ["all"]:
args.tests = sorted(by_name)
tempdir = tempfile.TemporaryDirectory(prefix="ljd-test-")
for name in args.tests:
test = by_name[name]
result = test.test(config, pathlib.Path(tempdir.name))
if result == TestResult.PASS:
Colour.GREEN.write("[*] PASS ")
elif result == TestResult.FAIL:
Colour.RED.write("[x] FAIL ")
else:
assert result == TestResult.ERROR
Colour.RED.set_bg()
Colour.WHITE.write("[!]")
Colour.RED.write(" ERR ")
print(name)
if args.wait:
input("Press enter to continue, files at %s " % tempdir.name)
if __name__ == "__main__":
main()