-
Notifications
You must be signed in to change notification settings - Fork 15
/
validatecoverage.py
executable file
·59 lines (42 loc) · 1.63 KB
/
validatecoverage.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
#!/usr/bin/env python
import json
import sys
from xml.etree.ElementTree import parse
exceptions_fname = '.coverage_exceptions.json'
coverage = parse(sys.argv[1])
fixes = []
errors = []
modules = {}
with open(exceptions_fname) as f:
exceptions = json.loads(f.read())
for module in coverage.findall('.//class'):
filename = module.attrib['filename']
if filename.endswith('__init__.py'):
continue
modules[filename] = module
current = float(module.attrib.get('line-rate')) * 100
# give a 1% room for small changes
expected = float(exceptions.get(filename, 101)) - 1
if current != 100 and filename not in exceptions:
errors.append("2: %s has a coverage of %s%%, but expected 100%%, "
"add it to %s:" % (
filename, current, exceptions_fname))
fixes.append(' "%s": %.2f' % (filename, current))
# The + 0.01 is to consider for the float arithmetic errors
elif (current + 0.01) < expected:
errors.append("1: %s has a coverage of %s%%, but expected %s%%, "
"add more tests or update %s" % (
filename, current, expected, exceptions_fname))
elif current == 100 and expected < 100:
errors.append("3: %s reached 100%%, remove it from %s" % (
filename, exceptions_fname))
for filename in exceptions:
if filename not in modules:
errors.append("4: %s not found, remove it from %s" % (
filename, exceptions_fname))
for error in sorted(errors):
print('ERROR:', error)
if fixes:
print("FIXES:")
print(',\n'.join(sorted(fixes)))
sys.exit(len(errors))