From a6621b2ceaf4d0b72456903749ca1f6247a972fc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 6 Sep 2010 13:26:04 -0400 Subject: 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... --- coverage/xmlreport.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'coverage/xmlreport.py') diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 51405be6..da318cc7 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 -- cgit v1.2.1