forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
49 lines (39 loc) · 1.2 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
#!/usr/bin/env python
import unittest
import imp
import os
import re
try:
import coverage
except ImportError:
coverage = None
try:
for m in ('expecter', 'mock'):
imp.find_module(m)
except ImportError as ie:
print('Please install the test dependencies as documented in the README')
raise
TEST_DIR = 'tests'
def collect_tests():
# list files in directory tests/
names = os.listdir(TEST_DIR)
regex = re.compile("(?!_+)\w+\.py$")
join = '.'.join
# Make a list of the names like 'tests.test_name'
names = [join([TEST_DIR, f[:-3]]) for f in names if regex.match(f)]
return unittest.defaultTestLoader.loadTestsFromNames(names)
if __name__ == "__main__":
if coverage:
cov = coverage.coverage(source=['github3'],
omit=['github3/packages/*'])
cov.exclude('\(No coverage\)')
cov.exclude('def __repr__')
cov.start()
suite = collect_tests()
res = unittest.TextTestRunner(verbosity=1).run(suite)
if coverage:
cov.stop()
cov.save()
cov.report(show_missing=False)
# If it was successful, we don't want to exit with code 1
raise SystemExit(not res.wasSuccessful())