summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-05-31 12:22:34 -0400
committerNed Batchelder <ned@nedbatchelder.com>2010-05-31 12:22:34 -0400
commitd1deb9a0bccae2f478e054f8dcc134eef7bf140d (patch)
tree78f6eebd3ae48ca570743de83a137af48db72766 /coverage
parentf16cd373f1939788df624ebb69c862c295738a13 (diff)
downloadpython-coveragepy-d1deb9a0bccae2f478e054f8dcc134eef7bf140d.tar.gz
Clean up the plugins more. Add the rcfile and include options. Omit can no longer be a file of omissions, use the rcfile for that.
Diffstat (limited to 'coverage')
-rw-r--r--coverage/cmdline.py38
-rw-r--r--coverage/runners/noseplugin.py17
-rw-r--r--coverage/runners/plugin.py73
3 files changed, 70 insertions, 58 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index a0184af..c96bba9 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -442,10 +442,10 @@ class CoverageScript(object):
# Listify the list options.
omit = None
if options.omit:
- omit = self.pattern_list(options.omit)
+ omit = pattern_list(options.omit)
include = None
if options.include:
- include = self.pattern_list(options.include)
+ include = pattern_list(options.include)
# Do something.
self.coverage = self.covpkg.coverage(
@@ -509,13 +509,12 @@ class CoverageScript(object):
self.coverage.save()
# Remaining actions are reporting, with some common options.
- report_args = {
- 'morfs': args,
- 'ignore_errors': options.ignore_errors,
- }
-
- report_args['omit'] = omit
- report_args['include'] = include
+ report_args = dict(
+ morfs = args,
+ ignore_errors = options.ignore_errors,
+ omit = omit,
+ include = include,
+ )
if 'report' in options.actions:
self.coverage.report(
@@ -532,16 +531,17 @@ class CoverageScript(object):
return OK
- def pattern_list(self, s):
- """Turn an argument into a list of patterns."""
- if sys.platform == 'win32':
- # When running coverage as coverage.exe, some of the behavior
- # of the shell is emulated: wildcards are expanded into a list of
- # filenames. So you have to single-quote patterns on the command
- # line, but (not) helpfully, the single quotes are included in the
- # argument, so we have to strip them off here.
- s = s.strip("'")
- return s.split(',')
+
+def pattern_list(s):
+ """Turn an argument into a list of patterns."""
+ if sys.platform == 'win32':
+ # When running coverage as coverage.exe, some of the behavior
+ # of the shell is emulated: wildcards are expanded into a list of
+ # filenames. So you have to single-quote patterns on the command
+ # line, but (not) helpfully, the single quotes are included in the
+ # argument, so we have to strip them off here.
+ s = s.strip("'")
+ return s.split(',')
HELP_TOPICS = r"""
diff --git a/coverage/runners/noseplugin.py b/coverage/runners/noseplugin.py
index dceb9f7..79c4a46 100644
--- a/coverage/runners/noseplugin.py
+++ b/coverage/runners/noseplugin.py
@@ -3,18 +3,23 @@
import logging
from nose.plugins import Plugin
-from coverage.runners.plugin import CoverageTestWrapper, options as coverage_opts
+from coverage.runners.plugin import CoverageTestWrapper
+from coverage.runners.plugin import options as coverage_opts
-log = logging.getLogger(__name__)
+log = logging.getLogger("nose.plugins.coverage")
class Coverage(Plugin):
- """Nose plugin for coverage reporting."""
+ """The nose plugin to measure test coverage."""
- score = 1
+ score = 200
status = {}
+ def help(self):
+ """The help for the --with-coverage option."""
+ return "Measure test coverage using coverage.py."
+
def options(self, parser, env):
"""Add command-line options."""
@@ -34,13 +39,13 @@ class Coverage(Plugin):
self.config = config
self.status['active'] = True
- self.options = options
+ self.opts = options
def begin(self):
"""Begin recording coverage information."""
log.debug("Coverage begin")
- self.coverage = CoverageTestWrapper(self.options)
+ self.coverage = CoverageTestWrapper(self.opts)
self.coverage.start()
def report(self, stream):
diff --git a/coverage/runners/plugin.py b/coverage/runners/plugin.py
index e9d75b2..e0591bd 100644
--- a/coverage/runners/plugin.py
+++ b/coverage/runners/plugin.py
@@ -2,6 +2,8 @@
import optparse, sys
import coverage
+from coverage.cmdline import pattern_list
+
class CoverageTestWrapper(object):
"""A coverage test wrapper.
@@ -27,15 +29,20 @@ class CoverageTestWrapper(object):
self.coverPackages = options.cover_package
def start(self):
+ # cover_omit is a ',' separated list if provided
+ self.omit = pattern_list(self.options.cover_omit)
+ self.include = pattern_list(self.options.cover_omit)
+
self.coverage = self.covpkg.coverage(
+ config_file = self.options.cover_rcfile,
data_suffix = bool(self.options.cover_parallel_mode),
cover_pylib = self.options.cover_pylib,
timid = self.options.cover_timid,
branch = self.options.cover_branch,
+ include = self.include,
+ omit = self.omit,
)
- self.skipModules = sys.modules.keys()[:] #TODO: is this necessary??
-
self.coverage.start()
def finish(self, stream=None):
@@ -45,31 +52,25 @@ class CoverageTestWrapper(object):
modules = [module for name, module in sys.modules.items()
if self._want_module(name, module)]
- # Remaining actions are reporting, with some common self.options.
- report_args = {
- 'morfs': modules,
- 'ignore_errors': self.options.cover_ignore_errors,
- }
-
- try: # try looking for an omit file
- omit_file = open(self.options.cover_omit)
- omit = [line.strip() for line in omit_file.readlines()]
- report_args['omit'] = omit
- except: # assume cover_omit is a ',' separated list if provided
- omit = self.options.cover_omit.split(',')
- report_args['omit'] = omit
-
- if 'report' in self.options.cover_actions:
+ # Remaining actions are reporting, with some common options.
+ report_args = dict(
+ morfs = modules,
+ ignore_errors = True,
+ omit = self.omit,
+ include = self.include,
+ )
+
+ if 'report' in self.options.cover_reports:
self.coverage.report(
show_missing=self.options.cover_show_missing,
file=stream, **report_args)
- if 'annotate' in self.options.cover_actions:
+ if 'annotate' in self.options.cover_reports:
self.coverage.annotate(
directory=self.options.cover_directory, **report_args)
- if 'html' in self.options.cover_actions:
+ if 'html' in self.options.cover_reports:
self.coverage.html_report(
directory=self.options.cover_directory, **report_args)
- if 'xml' in self.options.cover_actions:
+ if 'xml' in self.options.cover_reports:
outfile = self.options.cover_outfile
if outfile == '-':
outfile = None
@@ -86,15 +87,19 @@ class CoverageTestWrapper(object):
options = [
- optparse.Option('--cover-action', action='append', default=['report'],
- dest='cover_actions', type="choice",
+ optparse.Option('--cover-rcfile', action='store', metavar="RC",
+ help="Specify configuration file. ['.coveragerc']",
+ default=True),
+
+ optparse.Option('--cover-report', action='append', default=['report'],
+ dest='cover_reports', type="choice",
choices=['annotate', 'html', 'report', 'xml'],
- help="""\
-annotate Annotate source files with execution information.
-html Create an HTML report.
-report Report coverage stats on modules.
-xml Create an XML report of coverage results.
- """.strip()),
+ help=("Choose what coverage report(s) to create: "
+ "annotate: Annotated source files; "
+ "html: Browsable HTML report; "
+ "report: Simple text report; "
+ "xml: Cobertura-compatible XML report.")
+ ),
optparse.Option('--cover-package', action='append', default=[],
dest="cover_package", metavar="COVER_PACKAGE",
@@ -111,9 +116,6 @@ xml Create an XML report of coverage results.
optparse.Option('--cover-directory', action='store', metavar="DIR",
help="Write the output files to DIR."),
- optparse.Option('--cover-ignore-errors', action='store_true',
- help="Ignore errors while reading source files."),
-
optparse.Option('--cover-pylib', action='store_true',
help=("Measure coverage even inside the Python installed "
"library, which isn't done by default.")),
@@ -122,10 +124,15 @@ xml Create an XML report of coverage results.
help=("Show line numbers of statements in each module "
"that weren't executed.")),
+ optparse.Option('--cover-include', action='store',
+ metavar="PAT1,PAT2,...", default='',
+ help=("Include files when their filename path matches one "
+ "of these file patterns.")),
+
optparse.Option('--cover-omit', action='store',
- metavar="PRE1,PRE2,...", default='',
+ metavar="PAT1,PAT2,...", default='',
help=("Omit files when their filename path matches one "
- "of these patterns.")),
+ "of these file patterns.")),
optparse.Option('--cover-outfile', action='store', metavar="OUTFILE",
help=("Write the XML report to this file. Defaults to "