-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
94 lines (71 loc) · 2.11 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from tests.tester import Test, tests, load
import coverage
from junit_xml import TestSuite, TestCase
from lib.debcfg import cfg, logger
from logging import DEBUG
import trio
import sys
# for c in cfg:
# cfg[c] = False
# logger.setLevel(DEBUG)
# cfg['events'] = True
repeat = 3
junit = False
if sys.argv[-1] == '--junit':
junit = True
sys.argv.pop()
load(*sys.argv[1].split('.')) if len(sys.argv) > 1 else load(igndirs=['broken'])
res = []
# has this tuple (test, success?, time we took, error)
async def run(test: Test, nurs: trio.Nursery):
t = trio.current_time()
suc, err = await test.test(nurs)
t = trio.current_time() - t
res.append((test, suc, t, err))
# async def a(nurs):
# while len(nurs.child_tasks) > 1:
# print(nurs.child_tasks, len(nurs.child_tasks))
# await trio.sleep(2.5)
async def main():
cov = coverage.Coverage()
cov.start()
for test in tests:
async with trio.open_nursery() as nurs:
# nurs.start_soon(a, nurs)
for _ in range(repeat):
nurs.start_soon(run, test, nurs)
cov.stop()
cov.save()
trio.run(main)
if junit:
path = 'junit/test-results.xml'
suits = {}
for test, suc, t, err in res:
sname = test.sname
if sname not in suits:
suits[sname] = TestSuite(sname)
tcase = TestCase(name=test._lable, elapsed_sec=t)
# TODO: logging
if not suc:
tcase.add_failure_info(f'encountered {err}')
suits[sname].test_cases.append(tcase)
open(path, 'w').write(TestSuite.to_xml_string(suits.values()))
else:
succeeded = [test for (test, suc, _, _) in res if suc]
failed = [test for (test, suc, _, _) in res if not suc]
suc = len(succeeded)
fai = len(failed)
tot = suc + fai
print(
f'''
Summary:
succeeded: {suc}
({round(suc/tot*100, 1)}%, {suc}/{tot})
failed: {fai}
({round(fai/tot*100, 1)}%, {fai}/{tot})'''
+ (
(':\n ' + '\n '.join([f.lable for f in failed]))
if failed
else ''
)
)