diff options
-rw-r--r-- | coverage/xmlreport.py | 30 | ||||
-rw-r--r-- | test/farm/html/gold_x_xml/coverage.xml | 6 | ||||
-rw-r--r-- | test/farm/html/gold_y_xml_branch/coverage.xml | 4 |
3 files changed, 19 insertions, 21 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 diff --git a/test/farm/html/gold_x_xml/coverage.xml b/test/farm/html/gold_x_xml/coverage.xml index c42e2c9..d558f5d 100644 --- a/test/farm/html/gold_x_xml/coverage.xml +++ b/test/farm/html/gold_x_xml/coverage.xml @@ -1,12 +1,12 @@ <?xml version="1.0" ?>
<!DOCTYPE coverage
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
-<coverage branch-rate="0.0" line-rate="0.666666666667" timestamp="1253972570431" version="3.1b1">
+<coverage branch-rate="0" line-rate="0.6667" timestamp="1253972570431" version="3.1b1">
<!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage/VER -->
<packages>
- <package branch-rate="0.0" complexity="0.0" line-rate="0.666666666667" name=".">
+ <package branch-rate="0" complexity="0" line-rate="0.6667" name=".">
<classes>
- <class branch-rate="0.0" complexity="0.0" filename="a.py" line-rate="0.666666666667" name="a">
+ <class branch-rate="0" complexity="0" filename="a.py" line-rate="0.6667" name="a">
<methods/>
<lines>
<line hits="1" number="3"/>
diff --git a/test/farm/html/gold_y_xml_branch/coverage.xml b/test/farm/html/gold_y_xml_branch/coverage.xml index 34e02dc..f7bf0b8 100644 --- a/test/farm/html/gold_y_xml_branch/coverage.xml +++ b/test/farm/html/gold_y_xml_branch/coverage.xml @@ -4,9 +4,9 @@ <coverage branch-rate="0.5" line-rate="0.8" timestamp="1259288252325" version="3.2b4">
<!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage/VER -->
<packages>
- <package branch-rate="0.5" complexity="0.0" line-rate="0.8" name=".">
+ <package branch-rate="0.5" complexity="0" line-rate="0.8" name=".">
<classes>
- <class branch-rate="0.5" complexity="0.0" filename="y.py" line-rate="0.8" name="y">
+ <class branch-rate="0.5" complexity="0" filename="y.py" line-rate="0.8" name="y">
<methods/>
<lines>
<line hits="1" number="3"/>
|