summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/xmlreport.py18
-rw-r--r--tests/farm/html/gold_x_xml/coverage.xml3
-rw-r--r--tests/farm/html/gold_y_xml_branch/coverage.xml3
-rw-r--r--tests/farm/html/run_a_xml_1.py6
-rw-r--r--tests/farm/html/run_a_xml_2.py6
-rw-r--r--tests/farm/html/run_y_xml_branch.py6
-rw-r--r--tests/farm/html/src/coverage.xml3
-rw-r--r--tests/test_farm.py19
8 files changed, 51 insertions, 13 deletions
diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py
index f5a4c1ba..2fb51007 100644
--- a/coverage/xmlreport.py
+++ b/coverage/xmlreport.py
@@ -17,6 +17,7 @@ class XmlReporter(Reporter):
def __init__(self, coverage, config):
super(XmlReporter, self).__init__(coverage, config)
+ self.source_paths = None
self.packages = None
self.xml_out = None
self.arcs = coverage.data.has_arcs()
@@ -47,16 +48,28 @@ class XmlReporter(Reporter):
xcoverage.appendChild(self.xml_out.createComment(
" Generated by coverage.py: %s " % __url__
))
- xpackages = self.xml_out.createElement("packages")
- xcoverage.appendChild(xpackages)
# Call xml_file for each file in the data.
+ self.source_paths = set()
self.packages = {}
self.report_files(self.xml_file, morfs)
+ xsources = self.xml_out.createElement("sources")
+ xcoverage.appendChild(xsources)
+
+ # Populate the XML DOM with the source info.
+ for path in sorted(self.source_paths):
+ xsource = self.xml_out.createElement("source")
+ xsources.appendChild(xsource)
+ txt = self.xml_out.createTextNode(path)
+ xsource.appendChild(txt)
+
lnum_tot, lhits_tot = 0, 0
bnum_tot, bhits_tot = 0, 0
+ xpackages = self.xml_out.createElement("packages")
+ xcoverage.appendChild(xpackages)
+
# Populate the XML DOM with the package info.
for pkg_name in sorted(self.packages.keys()):
pkg_data = self.packages[pkg_name]
@@ -99,6 +112,7 @@ class XmlReporter(Reporter):
package_name = cu.name.rpartition(".")[0]
className = cu.name
+ path = self.source_paths.add(cu.file_locator.relative_dir.rstrip('/'))
package = self.packages.setdefault(package_name, [{}, 0, 0, 0, 0])
xclass = self.xml_out.createElement("class")
diff --git a/tests/farm/html/gold_x_xml/coverage.xml b/tests/farm/html/gold_x_xml/coverage.xml
index 912112f2..d5a8c442 100644
--- a/tests/farm/html/gold_x_xml/coverage.xml
+++ b/tests/farm/html/gold_x_xml/coverage.xml
@@ -3,6 +3,9 @@
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0" line-rate="0.6667" timestamp="1253972570431" version="3.1b1">
<!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage/VER -->
+ <sources>
+ <source></source>
+ </sources>
<packages>
<package branch-rate="0" complexity="0" line-rate="0.6667" name="">
<classes>
diff --git a/tests/farm/html/gold_y_xml_branch/coverage.xml b/tests/farm/html/gold_y_xml_branch/coverage.xml
index ecbe0073..86e9e73c 100644
--- a/tests/farm/html/gold_y_xml_branch/coverage.xml
+++ b/tests/farm/html/gold_y_xml_branch/coverage.xml
@@ -3,6 +3,9 @@
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0.5" line-rate="0.8" timestamp="1259288252325" version="3.2b4">
<!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage/VER -->
+ <sources>
+ <source></source>
+ </sources>
<packages>
<package branch-rate="0.5" complexity="0" line-rate="0.8" name="">
<classes>
diff --git a/tests/farm/html/run_a_xml_1.py b/tests/farm/html/run_a_xml_1.py
index 3d187023..04fdfd4b 100644
--- a/tests/farm/html/run_a_xml_1.py
+++ b/tests/farm/html/run_a_xml_1.py
@@ -1,3 +1,5 @@
+relative_path = None
+
def html_it():
"""Run coverage and make an XML report for a."""
import coverage
@@ -6,6 +8,8 @@ def html_it():
import a # pragma: nested
cov.stop() # pragma: nested
cov.xml_report(a, outfile="../xml_1/coverage.xml")
+ global relative_path
+ relative_path = cov.file_locator.relative_dir.rstrip('/')
import os
if not os.path.exists("xml_1"):
@@ -16,6 +20,8 @@ runfunc(html_it, rundir="src")
compare("gold_x_xml", "xml_1", scrubs=[
(r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
(r' version="[-.\w]+"', ' version="VERSION"'),
+ (r'<source>(\s)*?(.*)(\s)*?</source>',
+ '<source>%s</source>' % relative_path),
(r'/code/coverage/?[-.\w]*', '/code/coverage/VER'),
])
clean("xml_1")
diff --git a/tests/farm/html/run_a_xml_2.py b/tests/farm/html/run_a_xml_2.py
index 53691ead..205ca453 100644
--- a/tests/farm/html/run_a_xml_2.py
+++ b/tests/farm/html/run_a_xml_2.py
@@ -1,3 +1,5 @@
+relative_path = None
+
def html_it():
"""Run coverage and make an XML report for a."""
import coverage
@@ -6,6 +8,8 @@ def html_it():
import a # pragma: nested
cov.stop() # pragma: nested
cov.xml_report(a)
+ global relative_path
+ relative_path = cov.file_locator.relative_dir.rstrip('/')
import os
if not os.path.exists("xml_2"):
@@ -16,6 +20,8 @@ runfunc(html_it, rundir="src")
compare("gold_x_xml", "xml_2", scrubs=[
(r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
(r' version="[-.\w]+"', ' version="VERSION"'),
+ (r'<source>(\s)*?(.*)(\s)*?</source>',
+ '<source>%s</source>' % relative_path),
(r'/code/coverage/?[-.\w]*', '/code/coverage/VER'),
])
clean("xml_2")
diff --git a/tests/farm/html/run_y_xml_branch.py b/tests/farm/html/run_y_xml_branch.py
index 88a2e44e..18d7f7d9 100644
--- a/tests/farm/html/run_y_xml_branch.py
+++ b/tests/farm/html/run_y_xml_branch.py
@@ -1,3 +1,5 @@
+relative_path = None
+
def xml_it():
"""Run coverage and make an XML report for y."""
import coverage
@@ -6,6 +8,8 @@ def xml_it():
import y # pragma: nested
cov.stop() # pragma: nested
cov.xml_report(y, outfile="../xml_branch/coverage.xml")
+ global relative_path
+ relative_path = cov.file_locator.relative_dir.rstrip('/')
import os
if not os.path.exists("xml_branch"):
@@ -16,6 +20,8 @@ runfunc(xml_it, rundir="src")
compare("gold_y_xml_branch", "xml_branch", scrubs=[
(r' timestamp="\d+"', ' timestamp="TIMESTAMP"'),
(r' version="[-.\w]+"', ' version="VERSION"'),
+ (r'<source>(\s)*?(.*)(\s)*?</source>',
+ '<source>%s</source>' % relative_path),
(r'/code/coverage/?[-.\w]*', '/code/coverage/VER'),
])
clean("xml_branch")
diff --git a/tests/farm/html/src/coverage.xml b/tests/farm/html/src/coverage.xml
index 128cf750..e20cdaec 100644
--- a/tests/farm/html/src/coverage.xml
+++ b/tests/farm/html/src/coverage.xml
@@ -3,6 +3,9 @@
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0.0" line-rate="0.666666666667" timestamp="1263087779313" version="3.3a1">
<!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage -->
+ <sources>
+ <source></source>
+ </sources>
<packages>
<package branch-rate="0.0" complexity="0.0" line-rate="0.666666666667" name="">
<classes>
diff --git a/tests/test_farm.py b/tests/test_farm.py
index c86983e5..65016b34 100644
--- a/tests/test_farm.py
+++ b/tests/test_farm.py
@@ -256,8 +256,8 @@ class FarmTestCase(object):
# ourselves.
text_diff = []
for f in diff_files:
- left = open(os.path.join(dir1, f), "rU").readlines()
- right = open(os.path.join(dir2, f), "rU").readlines()
+ left = open(os.path.join(dir1, f), "rU").read()
+ right = open(os.path.join(dir2, f), "rU").read()
if scrubs:
left = self._scrub(left, scrubs)
right = self._scrub(right, scrubs)
@@ -271,19 +271,16 @@ class FarmTestCase(object):
if not right_extra:
assert not right_only, "Files in %s only: %s" % (dir2, right_only)
- def _scrub(self, strlist, scrubs):
- """Scrub uninteresting data from the strings in `strlist`.
+ def _scrub(self, strdata, scrubs):
+ """Scrub uninteresting data from the payload in `strdata`.
`scrubs is a list of (find, replace) pairs of regexes that are used on
- each string in `strlist`. A list of scrubbed strings is returned.
+ `strdata`. A string is returned.
"""
- scrubbed = []
- for s in strlist:
- for rgx_find, rgx_replace in scrubs:
- s = re.sub(rgx_find, rgx_replace, s)
- scrubbed.append(s)
- return scrubbed
+ for rgx_find, rgx_replace in scrubs:
+ strdata = re.sub(rgx_find, rgx_replace, strdata)
+ return strdata
def contains(self, filename, *strlist):
"""Check that the file contains all of a list of strings.