summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--coverage/cmdline.py12
-rw-r--r--coverage/control.py2
-rw-r--r--test/farm/html/run_x_xml.py2
-rw-r--r--test/test_cmdline.py43
5 files changed, 54 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 53da94b5..74bdb345 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ clean:
-rm -f *.bak */*.bak */*/*.bak */*/*/*.bak */*/*/*/*.bak */*/*/*/*/*.bak
-rm -f coverage/*,cover
-rm -f MANIFEST
- -rm -f .coverage .coverage.*
+ -rm -f .coverage .coverage.* coverage.xml
-rm -f $(TEST_ZIP)
-rm -f setuptools-*.egg
-rm -rf doc/_build/*
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 26da9fd4..accade5b 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -43,6 +43,11 @@ class Opts:
help="Omit files when their filename path starts with one of these "
"prefixes."
)
+ output_xml = optparse.Option(
+ '-o', '', action='store', dest="outfile",
+ metavar="OUTFILE",
+ help="Write the XML report to this file. Defaults to 'coverage.xml'"
+ )
parallel_mode = optparse.Option(
'-p', '--parallel-mode', action='store_true',
help="Include the machine name and process id in the .coverage "
@@ -253,9 +258,11 @@ CMDS = {
[
Opts.ignore_errors,
Opts.omit,
+ Opts.output_xml,
Opts.help,
],
cmd = "xml",
+ defaults = {'outfile': 'coverage.xml'},
usage = "[options] [modules]",
description = "Generate an XML report of coverage results."
),
@@ -421,7 +428,10 @@ class CoverageScript:
self.coverage.html_report(
directory=options.directory, **report_args)
if 'xml' in options.actions:
- self.coverage.xml_report(**report_args)
+ outfile = options.outfile
+ if outfile == '-':
+ outfile = None
+ self.coverage.xml_report(outfile=outfile, **report_args)
return OK
diff --git a/coverage/control.py b/coverage/control.py
index d04445f8..4fdec930 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -328,5 +328,7 @@ class coverage:
The report is compatible with Cobertura reports.
"""
+ if outfile:
+ outfile = open(outfile, "w")
reporter = XmlReporter(self, ignore_errors)
reporter.report(morfs, omit_prefixes=omit_prefixes, outfile=outfile)
diff --git a/test/farm/html/run_x_xml.py b/test/farm/html/run_x_xml.py
index c1dbb163..b3682940 100644
--- a/test/farm/html/run_x_xml.py
+++ b/test/farm/html/run_x_xml.py
@@ -5,7 +5,7 @@ def html_it():
cov.start()
import x
cov.stop()
- cov.xml_report(x, outfile=open("../xml/coverage.xml", 'w'))
+ cov.xml_report(x, outfile="../xml/coverage.xml")
import os
if not os.path.exists("xml"):
diff --git a/test/test_cmdline.py b/test/test_cmdline.py
index eb4e7cd4..d2413712 100644
--- a/test/test_cmdline.py
+++ b/test/test_cmdline.py
@@ -13,6 +13,10 @@ OK, ERR = 0, 1
class CmdLineTest(CoverageTest):
"""Tests of execution paths through the command line interpreter."""
+ INIT_LOAD = """\
+ .coverage(cover_pylib=None, data_suffix=False, timid=None)
+ .load()\n"""
+
def command_line(self, args, ret=OK):
"""Run `args` through the command line.
@@ -80,10 +84,6 @@ class CmdLineTest(CoverageTest):
class ClassicCmdLineTest(CmdLineTest):
"""Tests of the classic coverage.py command line."""
- INIT_LOAD = """\
- .coverage(cover_pylib=None, data_suffix=False, timid=None)
- .load()\n"""
-
def testErase(self):
# coverage -e
self.cmd_executes("-e", """\
@@ -378,6 +378,41 @@ class NewCmdLineTest(CmdLineTest):
self.cmd_executes_same("run --timid f.py", "-e -x --timid f.py")
self.cmd_executes_same("run", "-x")
+ def testXml(self):
+ # coverage xml [-i] [--omit DIR,...] [FILE1 FILE2 ...]
+ self.cmd_executes("xml", self.INIT_LOAD + """\
+ .xml_report(ignore_errors=None, omit_prefixes=None, morfs=[],
+ outfile="coverage.xml")
+ """)
+ self.cmd_executes("xml -i", self.INIT_LOAD + """\
+ .xml_report(ignore_errors=True, omit_prefixes=None, morfs=[],
+ outfile="coverage.xml")
+ """)
+ self.cmd_executes("xml -o myxml.foo", self.INIT_LOAD + """\
+ .xml_report(ignore_errors=None, omit_prefixes=None, morfs=[],
+ outfile="myxml.foo")
+ """)
+ self.cmd_executes("xml -o -", self.INIT_LOAD + """\
+ .xml_report(ignore_errors=None, omit_prefixes=None, morfs=[],
+ outfile=None)
+ """)
+ self.cmd_executes("xml --omit fooey", self.INIT_LOAD + """\
+ .xml_report(ignore_errors=None, omit_prefixes=["fooey"], morfs=[],
+ outfile="coverage.xml")
+ """)
+ self.cmd_executes("xml --omit fooey,booey", self.INIT_LOAD + """\
+ .xml_report(ignore_errors=None, omit_prefixes=["fooey", "booey"],
+ morfs=[], outfile="coverage.xml")
+ """)
+ self.cmd_executes("xml mod1", self.INIT_LOAD + """\
+ .xml_report(ignore_errors=None, omit_prefixes=None, morfs=["mod1"],
+ outfile="coverage.xml")
+ """)
+ self.cmd_executes("xml mod1 mod2 mod3", self.INIT_LOAD + """\
+ .xml_report(ignore_errors=None, omit_prefixes=None,
+ morfs=["mod1", "mod2", "mod3"], outfile="coverage.xml")
+ """)
+
def testNoArgumentsAtAll(self):
self.cmd_help("", topic="minimum_help", ret=OK)