summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS.txt1
-rw-r--r--CHANGES.txt4
-rw-r--r--coverage/xmlreport.py8
-rw-r--r--tests/farm/html/run_a_xml_1.py9
-rw-r--r--tests/farm/html/run_a_xml_2.py9
-rw-r--r--tests/farm/html/run_y_xml_branch.py9
6 files changed, 20 insertions, 20 deletions
diff --git a/AUTHORS.txt b/AUTHORS.txt
index e4e861af..d7e2d276 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -21,6 +21,7 @@ Imri Goldberg
Bill Hart
Christian Heimes
Roger Hu
+Stan Hu
Devin Jeanpierre
Ross Lawley
Edward Loper
diff --git a/CHANGES.txt b/CHANGES.txt
index 0c886fef..2812c1e1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -7,9 +7,13 @@ Change history for Coverage.py
- Python versions supported are now 2.6, 2.7, 3.2, 3.3.
+- The XML report now contains a <source> element, fixing `issue 94`_. Thanks
+ Stan Hu.
+
- The XML report will now create the output directory if need be, fixing
`issue 285`_. Thanks Chris Rose.
+.. _issue 94: https://bitbucket.org/ned/coveragepy/issue/94/coverage-xml-doesnt-produce-sources
.. _issue 285: https://bitbucket.org/ned/coveragepy/issue/285/xml-report-fails-if-output-file-directory
diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py
index 2fb51007..92a8975a 100644
--- a/coverage/xmlreport.py
+++ b/coverage/xmlreport.py
@@ -17,8 +17,8 @@ class XmlReporter(Reporter):
def __init__(self, coverage, config):
super(XmlReporter, self).__init__(coverage, config)
- self.source_paths = None
- self.packages = None
+ self.source_paths = set()
+ self.packages = {}
self.xml_out = None
self.arcs = coverage.data.has_arcs()
@@ -50,8 +50,6 @@ class XmlReporter(Reporter):
))
# 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")
@@ -112,7 +110,7 @@ class XmlReporter(Reporter):
package_name = cu.name.rpartition(".")[0]
className = cu.name
- path = self.source_paths.add(cu.file_locator.relative_dir.rstrip('/'))
+ 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/run_a_xml_1.py b/tests/farm/html/run_a_xml_1.py
index 04fdfd4b..83f8c86d 100644
--- a/tests/farm/html/run_a_xml_1.py
+++ b/tests/farm/html/run_a_xml_1.py
@@ -1,4 +1,4 @@
-relative_path = None
+source_path = None
def html_it():
"""Run coverage and make an XML report for a."""
@@ -8,8 +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('/')
+ global source_path
+ source_path = cov.file_locator.relative_dir.rstrip('/')
import os
if not os.path.exists("xml_1"):
@@ -20,8 +20,7 @@ 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'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_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 205ca453..6dd44225 100644
--- a/tests/farm/html/run_a_xml_2.py
+++ b/tests/farm/html/run_a_xml_2.py
@@ -1,4 +1,4 @@
-relative_path = None
+source_path = None
def html_it():
"""Run coverage and make an XML report for a."""
@@ -8,8 +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('/')
+ global source_path
+ source_path = cov.file_locator.relative_dir.rstrip('/')
import os
if not os.path.exists("xml_2"):
@@ -20,8 +20,7 @@ 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'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_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 18d7f7d9..9ae9a9f0 100644
--- a/tests/farm/html/run_y_xml_branch.py
+++ b/tests/farm/html/run_y_xml_branch.py
@@ -1,4 +1,4 @@
-relative_path = None
+source_path = None
def xml_it():
"""Run coverage and make an XML report for y."""
@@ -8,8 +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('/')
+ global source_path
+ source_path = cov.file_locator.relative_dir.rstrip('/')
import os
if not os.path.exists("xml_branch"):
@@ -20,8 +20,7 @@ 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'<source>\s*.*?\s*</source>', '<source>%s</source>' % source_path),
(r'/code/coverage/?[-.\w]*', '/code/coverage/VER'),
])
clean("xml_branch")