summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-07-10 17:15:43 -0400
committerNed Batchelder <ned@nedbatchelder.com>2016-07-10 17:15:43 -0400
commit9a69a43b43f89408fe7afcea76954cbdcf1c09b9 (patch)
tree8b5e286d949be6ffe7434eb6559062ad378fc504
parentdf006b4ec86d0325e54414305c1f6ea3d856e6ca (diff)
downloadpython-coveragepy-git-9a69a43b43f89408fe7afcea76954cbdcf1c09b9.tar.gz
Cover a few more lines in cmdline.py
-rw-r--r--coverage/cmdline.py15
-rw-r--r--tests/test_cmdline.py5
-rw-r--r--tests/test_process.py38
3 files changed, 49 insertions, 9 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 1b54e863..09e82323 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -216,7 +216,7 @@ class GlobalOptionParser(CoverageOptionParser):
class CmdOptionParser(CoverageOptionParser):
"""Parse one of the new-style commands for coverage.py."""
- def __init__(self, action, options=None, defaults=None, usage=None, description=None):
+ def __init__(self, action, options, defaults=None, usage=None, description=None):
"""Create an OptionParser for a coverage.py command.
`action` is the slug to put into `options.action`.
@@ -233,8 +233,7 @@ class CmdOptionParser(CoverageOptionParser):
description=description,
)
self.set_defaults(action=action, **(defaults or {}))
- if options:
- self.add_options(options)
+ self.add_options(options)
self.cmd = action
def __eq__(self, other):
@@ -277,7 +276,7 @@ CMDS = {
[
Opts.append,
] + GLOBAL_ARGS,
- usage="<path1> <path2> ... <pathN>",
+ usage="[options] <path1> <path2> ... <pathN>",
description=(
"Combine data from multiple coverage files collected "
"with 'run -p'. The combined results are written to a single "
@@ -301,7 +300,6 @@ CMDS = {
'erase': CmdOptionParser(
"erase", GLOBAL_ARGS,
- usage=" ",
description="Erase previously collected coverage data.",
),
@@ -522,10 +520,9 @@ class CoverageScript(object):
self.coverage.set_option("report:fail_under", options.fail_under)
if self.coverage.get_option("report:fail_under"):
- # Total needs to be rounded, but be careful of 0 and 100.
- if 0 < total < 1:
- total = 1
- elif 99 < total < 100:
+ # 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)
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 3f471b88..1e72c4f4 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -654,6 +654,11 @@ class CmdLineStdoutTest(BaseCmdLineTest):
self.assertIn("--timid", out)
self.assertGreater(out.count("\n"), 10)
+ def test_unknown_topic(self):
+ # Should probably be an ERR return, but meh.
+ self.command_line("help foobar")
+ self.assertEqual(self.stdout(), "Don't know topic 'foobar'\n")
+
def test_error(self):
self.command_line("fooey kablooey", ret=ERR)
out = self.stdout()
diff --git a/tests/test_process.py b/tests/test_process.py
index 5298b722..5848b9ff 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -913,6 +913,44 @@ class FailUnderEmptyFilesTest(CoverageTest):
self.assertEqual(st, 2)
+class FailUnder100Test(CoverageTest):
+ """Tests of the --fail-under switch."""
+
+ def test_99_8(self):
+ self.make_file("ninety_nine_eight.py",
+ "".join("v{i} = {i}\n".format(i=i) for i in range(498)) +
+ "if v0 > 498:\n v499 = 499\n"
+ )
+ st, _ = self.run_command_status("coverage run ninety_nine_eight.py")
+ self.assertEqual(st, 0)
+ st, out = self.run_command_status("coverage report")
+ self.assertEqual(st, 0)
+ self.assertEqual(
+ self.last_line_squeezed(out),
+ "ninety_nine_eight.py 500 1 99%"
+ )
+
+ st, _ = self.run_command_status("coverage report --fail-under=100")
+ self.assertEqual(st, 2)
+
+
+ def test_100(self):
+ self.make_file("one_hundred.py",
+ "".join("v{i} = {i}\n".format(i=i) for i in range(500))
+ )
+ st, _ = self.run_command_status("coverage run one_hundred.py")
+ self.assertEqual(st, 0)
+ st, out = self.run_command_status("coverage report")
+ self.assertEqual(st, 0)
+ self.assertEqual(
+ self.last_line_squeezed(out),
+ "one_hundred.py 500 0 100%"
+ )
+
+ st, _ = self.run_command_status("coverage report --fail-under=100")
+ self.assertEqual(st, 0)
+
+
class UnicodeFilePathsTest(CoverageTest):
"""Tests of using non-ascii characters in the names of files."""