-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrun_tests.py
63 lines (48 loc) · 1.75 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
import sys
import traceback
from io import StringIO
import pylint.lint as pylint
from flake8.api import legacy
from pylint.reporters import text
def test_flake8():
style_guide = legacy.get_style_guide()
report = style_guide.check_files(['ksoftapi'])
statistics = report.get_statistics('E')
failed = bool(statistics)
return failed
def test_pylint():
stdout = StringIO()
reporter = text.TextReporter(stdout)
opts = ['--max-line-length=150', '--score=no', '--disable=missing-docstring, wildcard-import, '
'attribute-defined-outside-init, too-few-public-methods, '
'old-style-class,import-error,invalid-name,no-init,'
'too-many-instance-attributes,protected-access,too-many-arguments,'
'too-many-public-methods,logging-format-interpolation,'
'too-many-branches', 'ksoftapi']
pylint.Run(opts, reporter=reporter, do_exit=False)
out = reporter.out.getvalue()
failed = bool(out)
return failed
def test_import():
try:
import ksoftapi
except Exception as e:
traceback.print_exc()
return True
if __name__ == '__main__':
tests = [test_flake8, test_pylint, test_import]
fail_count = 0
for test in tests:
test_name = test.__name__
formatted_test_name = f'-- {test_name[5:]} test --'
print(formatted_test_name)
failed = test()
if failed:
print('Failed')
fail_count += 1
else:
print('Passed')
if fail_count == 0:
sys.exit(0)
else:
sys.exit(1)