Repository navigation
Expand file tree
/
Copy pathtesting.py
More file actions
93 lines (75 loc) · 2.37 KB
/
Copy pathtesting.py
File metadata and controls
93 lines (75 loc) · 2.37 KB
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
from __future__ import print_function, division, absolute_import
import sys
import contextlib
if sys.version_info[0] >= 3:
from io import StringIO
else:
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
def discover_tests(startdir):
import numba.unittest_support as unittest
loader = unittest.TestLoader()
suite = loader.discover(startdir)
return suite
def run_tests(suite, descriptions=True, verbosity=2, buffer=True,
failfast=True):
import numba.unittest_support as unittest
runner = unittest.TextTestRunner(descriptions=descriptions,
verbosity=verbosity,
buffer=buffer, failfast=failfast)
result = runner.run(suite)
return result
def test():
suite = discover_tests("numba.tests")
return run_tests(suite).wasSuccessful()
def _flatten_suite(test):
"""Expand suite into list of tests
"""
from numba.unittest_support import TestSuite
if isinstance(test, TestSuite):
tests = []
for x in test:
tests.extend(_flatten_suite(x))
return tests
else:
return [test]
def multitest():
"""
Run tests in multiple processes.
"""
import numba.unittest_support as unittest
import multiprocessing as mp
loader = unittest.TestLoader()
startdir = "numba.tests"
suites = loader.discover(startdir)
tests = _flatten_suite(suites)
# Distribute tests to multiple processes
pool = mp.Pool(processes=mp.cpu_count())
results = pool.imap_unordered(_multiruntest, tests)
errct = 0
for ok, out in results:
if not ok:
print()
print("=== Error ===")
print(out)
errct += 1
else:
print('.', end='')
sys.stdout.flush()
print()
if errct == 0:
print("All passed!")
return True
else:
print("Error %d/%d" % (errct, len(tests)))
return False
def _multiruntest(suite):
import numba.unittest_support as unittest
stream = StringIO()
with contextlib.closing(stream):
runner = unittest.TextTestRunner(descriptions=False, verbosity=3,
buffer=True, stream=stream)
result = runner.run(suite)
return result.wasSuccessful(), stream.getvalue()