diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-01-09 20:57:37 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-01-09 20:57:37 -0500 |
commit | 1bec288c62eca5f608e047c009730a43da7df725 (patch) | |
tree | cf4784f5aa045684f705a24c11935aadaafe5b0a | |
parent | 0d54199f9c087c230d6e7d1bc0fd933ffb5ac82a (diff) | |
download | python-coveragepy-git-1bec288c62eca5f608e047c009730a43da7df725.tar.gz |
XML output file is configurable in .rc file.
--HG--
rename : test/farm/html/run_a_xml.py => test/farm/html/run_a_xml_1.py
-rw-r--r-- | coverage/cmdline.py | 2 | ||||
-rw-r--r-- | coverage/config.py | 7 | ||||
-rw-r--r-- | coverage/control.py | 13 | ||||
-rw-r--r-- | test/farm/html/run_a_xml_1.py (renamed from test/farm/html/run_a_xml.py) | 12 | ||||
-rw-r--r-- | test/farm/html/run_a_xml_2.py | 20 | ||||
-rw-r--r-- | test/farm/html/src/coverage.xml | 20 | ||||
-rw-r--r-- | test/farm/html/src/run_a_xml_2.ini | 3 | ||||
-rw-r--r-- | test/test_cmdline.py | 2 | ||||
-rw-r--r-- | test/test_config.py | 6 |
9 files changed, 73 insertions, 12 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index e82cf27c..60f9cdd3 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -506,8 +506,6 @@ class CoverageScript(object): directory=options.directory, **report_args) if 'xml' in options.actions: outfile = options.outfile - if outfile == '-': - outfile = None self.coverage.xml_report(outfile=outfile, **report_args) return OK diff --git a/coverage/config.py b/coverage/config.py index 9307fad7..8f508f28 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -29,6 +29,9 @@ class CoverageConfig(object): # Defaults for [html] self.html_dir = "htmlcov" + # Defaults for [xml] + self.xml_output = "coverage.xml" + def from_environment(self, env_var): """Read configuration from the `env_var` environment variable.""" # Timidity: for nose users, read an environment variable. This is a @@ -86,3 +89,7 @@ class CoverageConfig(object): # [html] if cp.has_option('html', 'directory'): self.html_dir = cp.get('html', 'directory') + + # [xml] + if cp.has_option('xml', 'output'): + self.xml_output = cp.get('xml', 'output') diff --git a/coverage/control.py b/coverage/control.py index 3a1b7f0f..5c253808 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -366,14 +366,21 @@ class coverage(object): """Generate an XML report of coverage results. The report is compatible with Cobertura reports. + + Each module in `morfs` is included in the report. `outfile` is the + path to write the file to, "-" will write to stdout. """ self.config.from_args( ignore_errors=ignore_errors, - omit_prefixes=omit_prefixes + omit_prefixes=omit_prefixes, + xml_output=outfile, ) - if outfile: - outfile = open(outfile, "w") + if self.config.xml_output: + if self.config.xml_output == '-': + outfile = sys.stdout + else: + outfile = open(self.config.xml_output, "w") try: reporter = XmlReporter(self, self.config.ignore_errors) reporter.report( diff --git a/test/farm/html/run_a_xml.py b/test/farm/html/run_a_xml_1.py index dabfa61f..7f4805ef 100644 --- a/test/farm/html/run_a_xml.py +++ b/test/farm/html/run_a_xml_1.py @@ -1,20 +1,20 @@ def html_it(): - """Run coverage and make an XML report for x.""" + """Run coverage and make an XML report for a.""" import coverage cov = coverage.coverage() cov.start() import a cov.stop() - cov.xml_report(a, outfile="../xml/coverage.xml") + cov.xml_report(a, outfile="../xml_1/coverage.xml") import os -if not os.path.exists("xml"): - os.makedirs("xml") +if not os.path.exists("xml_1"): + os.makedirs("xml_1") runfunc(html_it, rundir="src") -compare("gold_x_xml", "xml", scrubs=[ +compare("gold_x_xml", "xml_1", scrubs=[ (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), (r' version="[-.\w]+"', ' version="VERSION"'), ]) -clean("xml") +clean("xml_1") diff --git a/test/farm/html/run_a_xml_2.py b/test/farm/html/run_a_xml_2.py new file mode 100644 index 00000000..b08d7960 --- /dev/null +++ b/test/farm/html/run_a_xml_2.py @@ -0,0 +1,20 @@ +def html_it(): + """Run coverage and make an XML report for a.""" + import coverage + cov = coverage.coverage(config_file="run_a_xml_2.ini") + cov.start() + import a + cov.stop() + cov.xml_report(a) + +import os +if not os.path.exists("xml_2"): + os.makedirs("xml_2") + +runfunc(html_it, rundir="src") + +compare("gold_x_xml", "xml_2", scrubs=[ + (r' timestamp="\d+"', ' timestamp="TIMESTAMP"'), + (r' version="[-.\w]+"', ' version="VERSION"'), + ]) +clean("xml_2") diff --git a/test/farm/html/src/coverage.xml b/test/farm/html/src/coverage.xml new file mode 100644 index 00000000..bc517328 --- /dev/null +++ b/test/farm/html/src/coverage.xml @@ -0,0 +1,20 @@ +<?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="1263087779313" version="3.3a1">
+ <!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage -->
+ <packages>
+ <package branch-rate="0.0" complexity="0.0" line-rate="0.666666666667" name=".">
+ <classes>
+ <class branch-rate="0.0" complexity="0.0" filename="a.py" line-rate="0.666666666667" name="a">
+ <methods/>
+ <lines>
+ <line hits="1" number="3"/>
+ <line hits="1" number="5"/>
+ <line hits="0" number="7"/>
+ </lines>
+ </class>
+ </classes>
+ </package>
+ </packages>
+</coverage>
diff --git a/test/farm/html/src/run_a_xml_2.ini b/test/farm/html/src/run_a_xml_2.ini new file mode 100644 index 00000000..8d28f97b --- /dev/null +++ b/test/farm/html/src/run_a_xml_2.ini @@ -0,0 +1,3 @@ +# Put all the XML output in xml_2 +[xml] +output = ../xml_2/coverage.xml diff --git a/test/test_cmdline.py b/test/test_cmdline.py index 9196873f..56242681 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -482,7 +482,7 @@ class NewCmdLineTest(CmdLineTest): """) self.cmd_executes("xml -o -", self.INIT_LOAD + """\ .xml_report(ignore_errors=None, omit_prefixes=None, morfs=[], - outfile=None) + outfile="-") """) self.cmd_executes("xml --omit fooey", self.INIT_LOAD + """\ .xml_report(ignore_errors=None, omit_prefixes=["fooey"], morfs=[], diff --git a/test/test_config.py b/test/test_config.py index 478f1150..f4bd65bf 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -93,6 +93,7 @@ class ConfigFileTest(CoverageTest): """Tests of the config file settings in particular.""" def test_config_file_settings(self): + # This sample file tries to use lots of variation of syntax... self.make_file(".coveragerc", """\ # This is a settings file for coverage.py [run] @@ -119,6 +120,9 @@ class ConfigFileTest(CoverageTest): directory = c:\\tricky\\dir.somewhere + [xml] + output=mycov.xml + """) cov = coverage.coverage() @@ -137,3 +141,5 @@ class ConfigFileTest(CoverageTest): ) self.assertEqual(cov.config.html_dir, r"c:\tricky\dir.somewhere") + + self.assertEqual(cov.config.xml_output, "mycov.xml") |