-
Notifications
You must be signed in to change notification settings - Fork 5
/
run_tests.py
74 lines (56 loc) · 2.16 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
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
from __future__ import unicode_literals, print_function, division
from subprocess import call, check_output, STDOUT
import sys
import os
import errno
from os.path import dirname
TEST_FILES = ['test_zlog_server.py', 'tests.py', 'test_zlock_server.py']
COVERAGE_PROCESS_START = os.path.abspath('.coveragerc')
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def get_python_version(executable):
cmds = [executable, '--version']
return check_output(cmds, stderr=STDOUT).decode('utf8').strip()
def get_python_full_executable(executable):
cmds = [executable, '-c', 'import sys; print(sys.executable)']
return check_output(cmds).decode('utf8').strip()
def get_user_site(executable):
cmds = [executable, '-c', 'import site; print(site.getusersitepackages())']
return check_output(cmds).decode('utf8').strip()
def get_coverage_path(executable):
cmds = [executable, '-c', 'import coverage; print(coverage.__file__)']
return check_output(cmds).decode('utf8').strip()
def run_tests():
executable = sys.executable
version = get_python_version(executable)
full_executable = get_python_full_executable(executable)
print('doing tests for {}: {}'.format(full_executable, version))
environ = os.environ.copy()
environ['COVERAGE_PROCESS_START'] = COVERAGE_PROCESS_START
environ['PYTHONPATH'] = os.getcwd()
SITECUSTOMIZE = os.path.abspath('sitecustomize.py')
try:
with open(SITECUSTOMIZE, 'w') as f:
f.write("import coverage; coverage.process_startup()")
for test_file in TEST_FILES:
rc = call([executable, os.path.join('tests', test_file)], env=environ)
if rc:
sys.exit(rc)
finally:
try:
os.unlink(SITECUSTOMIZE)
except Exception:
pass
if __name__ == '__main__':
run_tests()
# try:
# # call([sys.executable, '-m', 'coverage', 'combine'])
# # call([sys.executable, '-m', 'coverage', 'html', '--rcfile=.coveragerc'])
# except Exception:
# pass