summaryrefslogtreecommitdiff
path: root/coverage/cmdline.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/cmdline.py')
-rw-r--r--coverage/cmdline.py37
1 files changed, 16 insertions, 21 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 89420241..63e4eb1f 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -3,6 +3,8 @@
"""Command-line support for coverage.py."""
+from __future__ import print_function
+
import glob
import optparse
import os.path
@@ -12,9 +14,10 @@ import traceback
from coverage import env
from coverage.collector import CTracer
-from coverage.execfile import run_python_file, run_python_module
-from coverage.misc import CoverageException, ExceptionDuringRun, NoSource
from coverage.debug import info_formatter, info_header
+from coverage.execfile import run_python_file, run_python_module
+from coverage.misc import BaseCoverageException, ExceptionDuringRun, NoSource
+from coverage.results import should_fail_under
class Opts(object):
@@ -248,7 +251,7 @@ class CmdOptionParser(CoverageOptionParser):
program_name = super(CmdOptionParser, self).get_prog_name()
# Include the sub-command for this parser as part of the command.
- return "%(command)s %(subcommand)s" % {'command': program_name, 'subcommand': self.cmd}
+ return "{command} {subcommand}".format(command=program_name, subcommand=self.cmd)
GLOBAL_ARGS = [
@@ -320,6 +323,7 @@ CMDS = {
Opts.include,
Opts.omit,
Opts.title,
+ Opts.skip_covered,
] + GLOBAL_ARGS,
usage="[options] [modules]",
description=(
@@ -458,7 +462,7 @@ class CoverageScript(object):
debug = unshell_list(options.debug)
# Do something.
- self.coverage = self.covpkg.coverage(
+ self.coverage = self.covpkg.Coverage(
data_suffix=options.parallel_mode,
cover_pylib=options.pylib,
timid=options.timid,
@@ -510,7 +514,7 @@ class CoverageScript(object):
elif options.action == "html":
total = self.coverage.html_report(
directory=options.directory, title=options.title,
- **report_args)
+ skip_covered=options.skip_covered, **report_args)
elif options.action == "xml":
outfile = options.outfile
total = self.coverage.xml_report(outfile=outfile, **report_args)
@@ -521,18 +525,9 @@ class CoverageScript(object):
if options.fail_under is not None:
self.coverage.set_option("report:fail_under", options.fail_under)
- if self.coverage.get_option("report:fail_under"):
- # Total needs to be rounded, but don't want to report 100
- # unless it is really 100.
- if 99 < total < 100:
- total = 99
- else:
- total = round(total)
-
- if total >= self.coverage.get_option("report:fail_under"):
- return OK
- else:
- return FAIL_UNDER
+ fail_under = self.coverage.get_option("report:fail_under")
+ if should_fail_under(total, fail_under):
+ return FAIL_UNDER
return OK
@@ -540,8 +535,8 @@ class CoverageScript(object):
"""Display an error message, or the named topic."""
assert error or topic or parser
if error:
- print(error)
- print("Use '%s help' for help." % (self.program_name,))
+ print(error, file=sys.stderr)
+ print("Use '%s help' for help." % (self.program_name,), file=sys.stderr)
elif parser:
print(parser.format_help().strip())
else:
@@ -757,9 +752,9 @@ def main(argv=None):
# An exception was caught while running the product code. The
# sys.exc_info() return tuple is packed into an ExceptionDuringRun
# exception.
- traceback.print_exception(*err.args)
+ traceback.print_exception(*err.args) # pylint: disable=no-value-for-parameter
status = ERR
- except CoverageException as err:
+ except BaseCoverageException as err:
# A controlled error inside coverage.py: print the message to the user.
print(err)
status = ERR