forked from perfguru87/perftracker-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·116 lines (96 loc) · 4.44 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/env python
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import sys
from os import sys, path
root = os.path.join(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(root)
from execute import execute
libs = [("perftrackerlib/client.py", 73),
("perftrackerlib/helpers/tee.py", 100),
("perftrackerlib/helpers/ptshell.py", 50),
("perftrackerlib/helpers/decorators.py", 75),
("perftrackerlib/helpers/timeparser.py", 98),
("perftrackerlib/helpers/timeline.py", 89),
("perftrackerlib/helpers/largelogfile.py", 98),
("perftrackerlib/helpers/httppool.py", 34),
("perftrackerlib/helpers/texttable.py", 82),
("perftrackerlib/helpers/timehelpers.py", 100),
("perftrackerlib/helpers/textparser.py", 100),
("perftrackerlib/helpers/html.py", 100),
("perftrackerlib/browser/browser_base.py", 45),
("perftrackerlib/browser/browser_webdriver.py", 20),
("perftrackerlib/browser/browser_python.py", 55),
("perftrackerlib/browser/utils.py", 19),
("perftrackerlib/browser/html_report.py", 70),
("perftrackerlib/browser/page.py", 15),
("perftrackerlib/browser/cp_engine.py", 30),
("perftrackerlib/browser/wpa_cp_engine.py", 40),
("perftrackerlib/browser/browser_chrome.py", 77),
("perftrackerlib/browser/browser_firefox.py", 35),
("perftrackerlib/browser/cp_crawler.py", 50),
]
tests = [("./tools/pt-artifact-ctl.py list"),
("./tools/pt-artifact-ctl.py upload ./test.py 11111111-4444-11e8-85cb-8c85907924ab -iz"),
("./tools/pt-artifact-ctl.py info 11111111-4444-11e8-85cb-8c85907924ab"),
("./tools/pt-artifact-ctl.py update 11111111-4444-11e8-85cb-8c85907924ab --description=desc -t 0"),
("./tools/pt-artifact-ctl.py dump 11111111-4444-11e8-85cb-8c85907924ab"),
("./tools/pt-artifact-ctl.py link 11111111-4444-11e8-85cb-8c85907924ab 11111111-3333-11e8-85cb-8c85907924ab"),
("./tools/pt-artifact-ctl.py unlink 11111111-4444-11e8-85cb-8c85907924ab "
"11111111-3333-11e8-85cb-8c85907924ab"),
("./tools/pt-suite-uploader.py -f ./examples/data/sample.txt --pt-project Test --pt-replace "
"11111111-5555-11e8-85cb-8c85907924ab"),
("./tools/pt-suite-uploader.py -f ./examples/data/sample.json -j --pt-project Test --pt-replace "
"11111111-5555-11e8-85cb-8c85907924ab"),
]
def test_one(cmdline):
print("Testing: %s ..." % cmdline, end=' ')
sys.stdout.flush()
execute(cmdline)
print("OK")
def lib2mod(lib):
modname = lib[0:len(lib) - 3] if lib.endswith(".py") else lib
return modname.replace("/", ".")
def coverage_one(lib, coverage_target):
# Use '# pragma: no cover' to exclude code
# see http://coverage.readthedocs.io/en/coverage-4.2/excluding.html
print("coverage run %s ..." % lib, end=' ')
execute("coverage run -m \"%s\"" % lib2mod(lib))
_, out, ext = execute("coverage report | grep %s" % lib)
try:
coverage = out.split()[3].decode("utf-8")
if not coverage.endswith("%"):
raise RuntimeError("can't parse: %s" % coverage)
coverage = int(coverage[:-1])
if coverage < coverage_target:
print("FAILED, code coverage is %d%%, must be >= %d%%" % (coverage, coverage_target))
print("NOTE: to debug the problem manually run:")
print(" coverage run -m \"%s\"" % lib2mod(lib))
print(" coverage report -m")
sys.exit(-1)
print("OK, %d%%" % coverage)
except RuntimeError as e:
print("FAILED, can't parse coverage")
raise
def test_all():
csopts = "--max-line-length=120 --ignore=E402"
test_one("pycodestyle %s *.py" % csopts)
for lib, _ in libs:
test_one("pycodestyle %s \"%s\"" % (csopts, os.path.join(root, lib)))
for lib, coverage_target in libs:
coverage_one(lib, coverage_target)
for test in tests:
test_one("python2.7 %s" % test)
test_one("python3 %s" % test)
for lib, _ in libs:
mod = lib2mod(lib)
test_one("python2.7 -m \"%s\"" % mod)
test_one("python3 -m \"%s\"" % mod)
# test_one("2to3 -p \"%s\"" % root)
# for t in tests:
# test_one("python2 -m \"tests.%s\"" % t)
# test_one("python3 -m \"tests.%s\"" % t)
if __name__ == '__main__':
test_all()
print(("=" * 80))
print("Good job, no errors")