diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-09-06 13:26:04 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-09-06 13:26:04 -0400 |
commit | 35ddc1078ee2778f91e02df16f333e07657877f3 (patch) | |
tree | b6f028da1dc1b908de024c81a195176d760f5cda /coverage/xmlreport.py | |
parent | 48e3ee4479ad568abd7c89edda44afaacb3111fb (diff) | |
download | python-coveragepy-35ddc1078ee2778f91e02df16f333e07657877f3.tar.gz |
Format numbers with %g in xmlreport, since py3.2 uses more digits in str() than previous Pythons, throwing off the gold files. We didn't need 9 digits of precision anyway...
Diffstat (limited to 'coverage/xmlreport.py')
-rw-r--r-- | coverage/xmlreport.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 51405be..da318cc 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -8,8 +8,8 @@ from coverage.backward import sorted # pylint: disable-msg=W0622 from coverage.report import Reporter def rate(hit, num): - """Return the fraction of `hit`/`num`.""" - return float(hit) / (num or 1.0) + """Return the fraction of `hit`/`num`, as a string.""" + return "%.4g" % (float(hit) / (num or 1.0)) class XmlReporter(Reporter): @@ -69,17 +69,17 @@ class XmlReporter(Reporter): for className in sorted(class_elts.keys()): xclasses.appendChild(class_elts[className]) xpackage.setAttribute("name", pkg_name.replace(os.sep, '.')) - xpackage.setAttribute("line-rate", str(rate(lhits, lnum))) - xpackage.setAttribute("branch-rate", str(rate(bhits, bnum))) - xpackage.setAttribute("complexity", "0.0") + xpackage.setAttribute("line-rate", rate(lhits, lnum)) + xpackage.setAttribute("branch-rate", rate(bhits, bnum)) + xpackage.setAttribute("complexity", "0") lnum_tot += lnum lhits_tot += lhits bnum_tot += bnum bhits_tot += bhits - xcoverage.setAttribute("line-rate", str(rate(lhits_tot, lnum_tot))) - xcoverage.setAttribute("branch-rate", str(rate(bhits_tot, bnum_tot))) + xcoverage.setAttribute("line-rate", rate(lhits_tot, lnum_tot)) + xcoverage.setAttribute("branch-rate", rate(bhits_tot, bnum_tot)) # Use the DOM to write the output file. outfile.write(self.xml_out.toprettyxml()) @@ -103,7 +103,7 @@ class XmlReporter(Reporter): xclass.setAttribute("name", className) ext = os.path.splitext(cu.filename)[1] xclass.setAttribute("filename", cu.name + ext) - xclass.setAttribute("complexity", "0.0") + xclass.setAttribute("complexity", "0") branch_stats = analysis.branch_stats() @@ -125,24 +125,22 @@ class XmlReporter(Reporter): ) xlines.appendChild(xline) - class_lines = 1.0 * len(analysis.statements) + class_lines = len(analysis.statements) class_hits = class_lines - len(analysis.missing) if self.arcs: class_branches = sum([t for t,k in branch_stats.values()]) missing_branches = sum([t-k for t,k in branch_stats.values()]) - class_branch_hits = class_branches - missing_branches + class_br_hits = class_branches - missing_branches else: class_branches = 0.0 - class_branch_hits = 0.0 + class_br_hits = 0.0 # Finalize the statistics that are collected in the XML DOM. - line_rate = rate(class_hits, class_lines) - branch_rate = rate(class_branch_hits, class_branches) - xclass.setAttribute("line-rate", str(line_rate)) - xclass.setAttribute("branch-rate", str(branch_rate)) + xclass.setAttribute("line-rate", rate(class_hits, class_lines)) + xclass.setAttribute("branch-rate", rate(class_br_hits, class_branches)) package[0][className] = xclass package[1] += class_hits package[2] += class_lines - package[3] += class_branch_hits + package[3] += class_br_hits package[4] += class_branches |