DebugClients/Python/coverage/xmlreport.py

changeset 6219
d6c795b5ce33
parent 5178
878ce843ca9f
child 6649
f1b3a73831c9
equal deleted inserted replaced
6218:bedab77d0fa3 6219:d6c795b5ce33
16 from coverage.report import Reporter 16 from coverage.report import Reporter
17 17
18 os = isolate_module(os) 18 os = isolate_module(os)
19 19
20 20
21 DTD_URL = ( 21 DTD_URL = 'https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd'
22 'https://raw.githubusercontent.com/cobertura/web/'
23 'f0366e5e2cf18f111cbd61fc34ef720a6584ba02'
24 '/htdocs/xml/coverage-03.dtd'
25 )
26 22
27 23
28 def rate(hit, num): 24 def rate(hit, num):
29 """Return the fraction of `hit`/`num`, as a string.""" 25 """Return the fraction of `hit`/`num`, as a string."""
30 if num == 0: 26 if num == 0:
112 lnum_tot += lnum 108 lnum_tot += lnum
113 lhits_tot += lhits 109 lhits_tot += lhits
114 bnum_tot += bnum 110 bnum_tot += bnum
115 bhits_tot += bhits 111 bhits_tot += bhits
116 112
113 xcoverage.setAttribute("lines-valid", str(lnum_tot))
114 xcoverage.setAttribute("lines-covered", str(lhits_tot))
117 xcoverage.setAttribute("line-rate", rate(lhits_tot, lnum_tot)) 115 xcoverage.setAttribute("line-rate", rate(lhits_tot, lnum_tot))
118 if self.has_arcs: 116 if self.has_arcs:
119 branch_rate = rate(bhits_tot, bnum_tot) 117 xcoverage.setAttribute("branches-valid", str(bnum_tot))
120 else: 118 xcoverage.setAttribute("branches-covered", str(bhits_tot))
121 branch_rate = "0" 119 xcoverage.setAttribute("branch-rate", rate(bhits_tot, bnum_tot))
122 xcoverage.setAttribute("branch-rate", branch_rate) 120 else:
121 xcoverage.setAttribute("branches-covered", "0")
122 xcoverage.setAttribute("branches-valid", "0")
123 xcoverage.setAttribute("branch-rate", "0")
124 xcoverage.setAttribute("complexity", "0")
123 125
124 # Use the DOM to write the output file. 126 # Use the DOM to write the output file.
125 out = self.xml_out.toprettyxml() 127 out = self.xml_out.toprettyxml()
126 if env.PY2: 128 if env.PY2:
127 out = out.encode("utf8") 129 out = out.encode("utf8")
146 rel_name = filename[len(source_path)+1:] 148 rel_name = filename[len(source_path)+1:]
147 break 149 break
148 else: 150 else:
149 rel_name = fr.relative_filename() 151 rel_name = fr.relative_filename()
150 152
151 dirname = os.path.dirname(rel_name) or "." 153 dirname = os.path.dirname(rel_name) or u"."
152 dirname = "/".join(dirname.split("/")[:self.config.xml_package_depth]) 154 dirname = "/".join(dirname.split("/")[:self.config.xml_package_depth])
153 package_name = dirname.replace("/", ".") 155 package_name = dirname.replace("/", ".")
154 156
155 if rel_name != fr.filename: 157 if rel_name != fr.filename:
156 self.source_paths.add(fr.filename[:-len(rel_name)].rstrip(r"\/")) 158 self.source_paths.add(fr.filename[:-len(rel_name)].rstrip(r"\/"))
162 164
163 xlines = self.xml_out.createElement("lines") 165 xlines = self.xml_out.createElement("lines")
164 xclass.appendChild(xlines) 166 xclass.appendChild(xlines)
165 167
166 xclass.setAttribute("name", os.path.relpath(rel_name, dirname)) 168 xclass.setAttribute("name", os.path.relpath(rel_name, dirname))
167 xclass.setAttribute("filename", fr.relative_filename().replace("\\", "/")) 169 xclass.setAttribute("filename", rel_name.replace("\\", "/"))
168 xclass.setAttribute("complexity", "0") 170 xclass.setAttribute("complexity", "0")
169 171
170 branch_stats = analysis.branch_stats() 172 branch_stats = analysis.branch_stats()
171 missing_branch_arcs = analysis.missing_branch_arcs() 173 missing_branch_arcs = analysis.missing_branch_arcs()
172 174
183 if line in branch_stats: 185 if line in branch_stats:
184 total, taken = branch_stats[line] 186 total, taken = branch_stats[line]
185 xline.setAttribute("branch", "true") 187 xline.setAttribute("branch", "true")
186 xline.setAttribute( 188 xline.setAttribute(
187 "condition-coverage", 189 "condition-coverage",
188 "%d%% (%d/%d)" % (100*taken/total, taken, total) 190 "%d%% (%d/%d)" % (100*taken//total, taken, total)
189 ) 191 )
190 if line in missing_branch_arcs: 192 if line in missing_branch_arcs:
191 annlines = ["exit" if b < 0 else str(b) for b in missing_branch_arcs[line]] 193 annlines = ["exit" if b < 0 else str(b) for b in missing_branch_arcs[line]]
192 xline.setAttribute("missing-branches", ",".join(annlines)) 194 xline.setAttribute("missing-branches", ",".join(annlines))
193 xlines.appendChild(xline) 195 xlines.appendChild(xline)

eric ide

mercurial