diff options
-rw-r--r-- | CHANGES.rst | 4 | ||||
-rw-r--r-- | coverage/xmlreport.py | 18 | ||||
-rw-r--r-- | tests/farm/html/gold_x_xml/coverage.xml | 4 | ||||
-rw-r--r-- | tests/farm/html/gold_y_xml_branch/coverage.xml | 4 |
4 files changed, 18 insertions, 12 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index e5de64e1..1cd10978 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,9 @@ Unreleased takes a list of these warning names to disable. Closes both `issue 96`_ and `issue 355`_. +- The XML report now includes attributes from version 4 of the Cobertura XML + format, fixing `issue 570`_. + - In previous versions, calling a method that used collected data would prevent further collection. For example, `save()`, `report()`, `html_report()`, and others would all stop collection. An explicit `start()` was needed to get it @@ -36,6 +39,7 @@ Unreleased .. _issue 96: https://bitbucket.org/ned/coveragepy/issues/96/unhelpful-warnings-produced-when-using .. _issue 355: https://bitbucket.org/ned/coveragepy/issues/355/warnings-should-be-suppressable .. _issue 448: https://bitbucket.org/ned/coveragepy/issues/448/save-and-html_report-prevent-further +.. _issue 570: https://bitbucket.org/ned/coveragepy/issues/570/cobertura-coverage-04dtd-support .. _changes_434: diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 694415fd..8af0d785 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -18,11 +18,7 @@ from coverage.report import Reporter os = isolate_module(os) -DTD_URL = ( - 'https://raw.githubusercontent.com/cobertura/web/' - 'f0366e5e2cf18f111cbd61fc34ef720a6584ba02' - '/htdocs/xml/coverage-03.dtd' -) +DTD_URL = 'https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd' def rate(hit, num): @@ -114,12 +110,18 @@ class XmlReporter(Reporter): bnum_tot += bnum bhits_tot += bhits + xcoverage.setAttribute("lines-valid", str(lnum_tot)) + xcoverage.setAttribute("lines-covered", str(lhits_tot)) xcoverage.setAttribute("line-rate", rate(lhits_tot, lnum_tot)) if self.has_arcs: - branch_rate = rate(bhits_tot, bnum_tot) + xcoverage.setAttribute("branches-valid", str(bnum_tot)) + xcoverage.setAttribute("branches-covered", str(bhits_tot)) + xcoverage.setAttribute("branch-rate", rate(bhits_tot, bnum_tot)) else: - branch_rate = "0" - xcoverage.setAttribute("branch-rate", branch_rate) + xcoverage.setAttribute("branches-covered", "0") + xcoverage.setAttribute("branches-valid", "0") + xcoverage.setAttribute("branch-rate", "0") + xcoverage.setAttribute("complexity", "0") # Use the DOM to write the output file. out = self.xml_out.toprettyxml() diff --git a/tests/farm/html/gold_x_xml/coverage.xml b/tests/farm/html/gold_x_xml/coverage.xml index b3e9854f..162824a0 100644 --- a/tests/farm/html/gold_x_xml/coverage.xml +++ b/tests/farm/html/gold_x_xml/coverage.xml @@ -1,7 +1,7 @@ <?xml version="1.0" ?> -<coverage branch-rate="0" line-rate="0.6667" timestamp="1437745880639" version="4.0a7"> +<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.6667" lines-covered="2" lines-valid="3" timestamp="1437745880639" version="4.0a7"> <!-- Generated by coverage.py: https://coverage.readthedocs.io/en/coverage-4.0a7 --> - <!-- Based on https://raw.githubusercontent.com/cobertura/web/f0366e5e2cf18f111cbd61fc34ef720a6584ba02/htdocs/xml/coverage-03.dtd --> + <!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd --> <sources> <source>/Users/ned/coverage/trunk/tests/farm/html/src</source> </sources> diff --git a/tests/farm/html/gold_y_xml_branch/coverage.xml b/tests/farm/html/gold_y_xml_branch/coverage.xml index d8ff0bb7..bcf1137b 100644 --- a/tests/farm/html/gold_y_xml_branch/coverage.xml +++ b/tests/farm/html/gold_y_xml_branch/coverage.xml @@ -1,7 +1,7 @@ <?xml version="1.0" ?> -<coverage branch-rate="0.5" line-rate="0.8" timestamp="1437745880882" version="4.0a7"> +<coverage branch-rate="0.5" branches-covered="1" branches-valid="2" complexity="0" line-rate="0.8" lines-covered="4" lines-valid="5" timestamp="1437745880882" version="4.0a7"> <!-- Generated by coverage.py: https://coverage.readthedocs.io/en/coverage-4.0a7 --> - <!-- Based on https://raw.githubusercontent.com/cobertura/web/f0366e5e2cf18f111cbd61fc34ef720a6584ba02/htdocs/xml/coverage-03.dtd --> + <!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd --> <sources> <source>/Users/ned/coverage/trunk/tests/farm/html/src</source> </sources> |