-
Notifications
You must be signed in to change notification settings - Fork 626
/
Copy pathcoverage_filter.py
executable file
·66 lines (54 loc) · 1.91 KB
/
coverage_filter.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
#!/usr/bin/env python3
#
# Filter coverage reported by lcov/genhtml
#
# Copyright 2012 BlueKitchen GmbH
#
from lxml import html
import sys
import os
coverage_html_path = "coverage-html/index.html"
summary = {}
def update_category(name, value):
old = 0
if name in summary:
old = summary[name]
summary[name] = old + value
def list_category_table():
row = "%-11s |%11s |%11s |%11s"
print( row % ('', 'Hit', 'Total', 'Coverage'))
print("------------|------------|------------|------------")
categories = [ 'Line', 'Function', 'Branch'];
for category in categories:
hit = summary[category + "_hit"]
total = summary[category + "_total"]
coverage = 100.0 * hit / total
print ( row % ( category, hit, total, "%.1f" % coverage))
filter = sys.argv[1:]
print("\nParsing HTML Coverage Report")
tree = html.parse(coverage_html_path)
files = tree.xpath("//td[@class='coverFile']")
for file in files:
row = file.getparent()
children = row.getchildren()
path = children[0].text_content()
lineCov = children[3].text_content()
functionCov = children[5].text_content()
branchCov = children[7].text_content()
(lineHit, lineTotal) = [int(x) for x in lineCov.split("/")]
(functionHit, functionTotal) = [int(x) for x in functionCov.split("/")]
(branchHit, branchTotal) = [int(x) for x in branchCov.split("/")]
# print(path, lineHit, lineTotal, functionHit, functionTotal, branchHit, branchTotal)
# filter
if path in filter:
print("- Skipping " + path)
continue
print("- Adding " + path)
update_category('Line_hit', lineHit)
update_category('Line_total', lineTotal)
update_category('Function_hit', functionHit)
update_category('Function_total', functionTotal)
update_category('Branch_hit', branchHit)
update_category('Branch_total', branchTotal)
print("")
list_category_table()