-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit_tests.py
49 lines (44 loc) · 1.38 KB
/
unit_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
import os
import coverage
from behave.__main__ import main as behave_main
dir_path = os.path.dirname(os.path.realpath(__file__))
# change dir to make sure data is loaded and saved to the correct directory
os.chdir(dir_path)
MINIMUM_COVERAGE = 65
START_GREEN = "\x1b[1;36;40m"
START_RED = "\x1b[6;30;41m"
END_COLOR = "\x1b[0m"
cov = coverage.Coverage()
cov.start()
print()
print("-----------------------------------------")
print("------------------ TESTS ----------------")
print("-----------------------------------------")
print()
result = behave_main("tests")
cov.stop()
print()
print("-----------------------------------------")
print("--------------CODE COVERAGE--------------")
print("-----------------------------------------")
print()
cov.save()
total_cover = cov.report()
print()
if total_cover < MINIMUM_COVERAGE:
print("-----------------------------------------")
print("---Code coverage requirements %sNOT%s met!---" % (START_RED, END_COLOR))
print(
"----------Minimum coverage %s%d%%%s!----------"
% (START_GREEN, MINIMUM_COVERAGE, END_COLOR)
)
print("-----------------------------------------")
print()
print("-----------------------------------------")
print("See full reports at ./htmlcov/index.html")
print("-----------------------------------------")
cov.html_report()
if result != 0:
exit(result)
if total_cover < MINIMUM_COVERAGE:
exit(1)