-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests
executable file
·103 lines (83 loc) · 2.24 KB
/
runtests
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import subprocess
import unittest
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
def heading(str):
print('\n' + color.BOLD + str + color.END)
sys.stdout.flush()
def err(str):
print(color.RED + str + color.END)
def success(str):
print(color.GREEN + str + color.END)
def is_set(flag):
try:
sys.argv.remove(flag)
except ValueError:
return False
else:
return True
def run_tests(args):
os.environ.setdefault('S3_BUCKET', 'test_bucket')
suite = unittest.TestLoader().discover('./tests')
results = unittest.TextTestRunner().run(suite)
if results.errors or results.failures:
err("Tests failed.")
sys.exit(1)
success("Tests passed.")
def run_coverage(args):
"""
Run tests with coverage tooling.
"""
# Run tests
heading('TESTS')
cmd = 'coverage run ' + ' '.join(args) + ' --only-tests'
ret = subprocess.call(cmd, shell=True)
if ret:
return ret
# Run coverage
heading('COVERAGE REPORT')
proc = subprocess.Popen(
'coverage report', shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = [out.decode('utf-8') for out in proc.communicate()]
exitcode = proc.returncode
print(stdout)
if exitcode:
err("Coverage failed to run.")
if stderr:
err(stderr)
return 1
# Analyze coverage report
coverage = stdout.split()[-1]
if coverage == '100%':
success("Coverage at 100%.")
return 0
else:
err("Failure, coverage not at 100% (got {})".format(coverage))
return 1
def run_flake8():
heading('FLAKE8')
ret = subprocess.call("flake8 app", shell=True)
if not ret:
success("Flake8 found no issues.")
return ret
if __name__ == "__main__":
if is_set('--only-flake8'):
sys.exit(run_flake8())
if is_set('--only-tests'):
sys.exit(run_tests(sys.argv))
else:
sys.exit(run_coverage(sys.argv) + run_flake8())