forked from python/pyperformance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
executable file
·93 lines (73 loc) · 2.19 KB
/
runtests.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
#!/usr/bin/env python3
import os.path
import shutil
import subprocess
import sys
import tempfile
def run_cmd(cmd):
print("Execute: %s" % ' '.join(cmd))
proc = subprocess.Popen(cmd)
try:
proc.wait()
except: # noqa
proc.kill()
proc.wait()
raise
exitcode = proc.returncode
if exitcode:
sys.exit(exitcode)
print("")
def run_tests(venv):
# Move to the root directly
root = os.path.dirname(__file__)
if root:
os.chdir(root)
python = sys.executable
script = 'pyperformance'
if os.name == "nt":
python_executable = os.path.basename(python)
venv_python = os.path.join(venv, 'Scripts', python_executable)
else:
venv_python = os.path.join(venv, 'bin', 'python')
def run_bench(*cmd):
cmd = cmd + ('--venv', venv)
run_cmd(cmd)
run_bench(python, script, 'venv', 'create')
egg_info = "pyperformance.egg-info"
print("Remove directory %s" % egg_info)
try:
shutil.rmtree(egg_info)
except FileNotFoundError:
pass
run_bench(python, script, 'venv')
for filename in (
os.path.join('pyperformance', 'tests', 'data', 'py36.json'),
os.path.join('pyperformance', 'tests', 'data', 'mem1.json'),
):
run_cmd((python, script, 'show', filename))
run_bench(python, script, 'list')
run_bench(python, script, 'list_groups')
json = os.path.join(venv, 'bench.json')
# -b all: check that *all* benchmark work
#
# --debug-single-value: benchmark results don't matter, we only
# check that running benchmarks don't fail.
run_bench(python, script, 'run', '-b', 'all', '--debug-single-value',
'-o', json)
# Display slowest benchmarks
run_cmd((venv_python, '-m', 'pyperf', 'slowest', json))
run_bench(python, script, 'venv', 'remove')
def main():
# Unit tests
cmd = [sys.executable,
os.path.join('pyperformance', 'tests', 'test_compare.py')]
run_cmd(cmd)
# Functional tests
tmpdir = tempfile.mkdtemp()
try:
run_tests(tmpdir)
finally:
if os.path.exists(tmpdir):
shutil.rmtree(tmpdir)
if __name__ == "__main__":
main()