@@ -44,8 +44,6 @@ def __init__(self, coverage):
44
44
self .source_paths .add (files .canonical_filename (src ))
45
45
self .packages = {}
46
46
self .xml_out = None
47
- self .data = coverage .get_data ()
48
- self .has_arcs = self .data .has_arcs ()
49
47
50
48
def report (self , morfs , outfile = None ):
51
49
"""Generate a Cobertura-compatible XML report for `morfs`.
@@ -57,6 +55,7 @@ def report(self, morfs, outfile=None):
57
55
"""
58
56
# Initial setup.
59
57
outfile = outfile or sys .stdout
58
+ has_arcs = self .coverage .get_data ().has_arcs ()
60
59
61
60
# Create the DOM that will store the data.
62
61
impl = xml .dom .minidom .getDOMImplementation ()
@@ -73,7 +72,7 @@ def report(self, morfs, outfile=None):
73
72
74
73
# Call xml_file for each file in the data.
75
74
for fr , analysis in get_analysis_to_report (self .coverage , morfs ):
76
- self .xml_file (fr , analysis )
75
+ self .xml_file (fr , analysis , has_arcs )
77
76
78
77
xsources = self .xml_out .createElement ("sources" )
79
78
xcoverage .appendChild (xsources )
@@ -102,7 +101,7 @@ def report(self, morfs, outfile=None):
102
101
xclasses .appendChild (class_elt )
103
102
xpackage .setAttribute ("name" , pkg_name .replace (os .sep , '.' ))
104
103
xpackage .setAttribute ("line-rate" , rate (lhits , lnum ))
105
- if self . has_arcs :
104
+ if has_arcs :
106
105
branch_rate = rate (bhits , bnum )
107
106
else :
108
107
branch_rate = "0"
@@ -117,7 +116,7 @@ def report(self, morfs, outfile=None):
117
116
xcoverage .setAttribute ("lines-valid" , str (lnum_tot ))
118
117
xcoverage .setAttribute ("lines-covered" , str (lhits_tot ))
119
118
xcoverage .setAttribute ("line-rate" , rate (lhits_tot , lnum_tot ))
120
- if self . has_arcs :
119
+ if has_arcs :
121
120
xcoverage .setAttribute ("branches-valid" , str (bnum_tot ))
122
121
xcoverage .setAttribute ("branches-covered" , str (bhits_tot ))
123
122
xcoverage .setAttribute ("branch-rate" , rate (bhits_tot , bnum_tot ))
@@ -138,7 +137,7 @@ def report(self, morfs, outfile=None):
138
137
pct = 100.0 * (lhits_tot + bhits_tot ) / denom
139
138
return pct
140
139
141
- def xml_file (self , fr , analysis ):
140
+ def xml_file (self , fr , analysis , has_arcs ):
142
141
"""Add to the XML report for a single file."""
143
142
144
143
# Create the 'lines' and 'package' XML elements, which
@@ -182,7 +181,7 @@ def xml_file(self, fr, analysis):
182
181
# executed? If so, that should be recorded here.
183
182
xline .setAttribute ("hits" , str (int (line not in analysis .missing )))
184
183
185
- if self . has_arcs :
184
+ if has_arcs :
186
185
if line in branch_stats :
187
186
total , taken = branch_stats [line ]
188
187
xline .setAttribute ("branch" , "true" )
@@ -198,7 +197,7 @@ def xml_file(self, fr, analysis):
198
197
class_lines = len (analysis .statements )
199
198
class_hits = class_lines - len (analysis .missing )
200
199
201
- if self . has_arcs :
200
+ if has_arcs :
202
201
class_branches = sum (t for t , k in branch_stats .values ())
203
202
missing_branches = sum (t - k for t , k in branch_stats .values ())
204
203
class_br_hits = class_branches - missing_branches
@@ -208,7 +207,7 @@ def xml_file(self, fr, analysis):
208
207
209
208
# Finalize the statistics that are collected in the XML DOM.
210
209
xclass .setAttribute ("line-rate" , rate (class_hits , class_lines ))
211
- if self . has_arcs :
210
+ if has_arcs :
212
211
branch_rate = rate (class_br_hits , class_branches )
213
212
else :
214
213
branch_rate = "0"
0 commit comments