summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
Diffstat (limited to 'coverage')
-rw-r--r--coverage/cmdline.py5
-rw-r--r--coverage/config.py4
-rw-r--r--coverage/results.py24
3 files changed, 14 insertions, 19 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 841d8f4a..7b86054e 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -51,7 +51,7 @@ class Opts(object):
help="Write the output files to DIR.",
)
fail_under = optparse.make_option(
- '', '--fail-under', action='store', metavar="MIN", type="int",
+ '', '--fail-under', action='store', metavar="MIN", type="float",
help="Exit with a status of 2 if the total coverage is less than MIN.",
)
help = optparse.make_option(
@@ -528,7 +528,8 @@ class CoverageScript(object):
self.coverage.set_option("report:fail_under", options.fail_under)
fail_under = self.coverage.get_option("report:fail_under")
- if should_fail_under(total, fail_under):
+ precision = self.coverage.get_option("report:precision")
+ if should_fail_under(total, fail_under, precision):
return FAIL_UNDER
return OK
diff --git a/coverage/config.py b/coverage/config.py
index 500c2119..7b8f2bd0 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -199,7 +199,7 @@ class CoverageConfig(object):
# Defaults for [report]
self.exclude_list = DEFAULT_EXCLUDE[:]
- self.fail_under = 0
+ self.fail_under = 0.0
self.ignore_errors = False
self.report_include = None
self.report_omit = None
@@ -335,7 +335,7 @@ class CoverageConfig(object):
# [report]
('exclude_list', 'report:exclude_lines', 'regexlist'),
- ('fail_under', 'report:fail_under', 'int'),
+ ('fail_under', 'report:fail_under', 'float'),
('ignore_errors', 'report:ignore_errors', 'boolean'),
('partial_always_list', 'report:partial_branches_always', 'regexlist'),
('partial_list', 'report:partial_branches', 'regexlist'),
diff --git a/coverage/results.py b/coverage/results.py
index 81ce2a68..5f84a689 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -6,7 +6,7 @@
import collections
from coverage.backward import iitems
-from coverage.misc import format_lines, SimpleRepr
+from coverage.misc import contract, format_lines, SimpleRepr
class Analysis(object):
@@ -271,25 +271,19 @@ class Numbers(SimpleRepr):
return NotImplemented
-def should_fail_under(total, fail_under):
+@contract(total='number', fail_under='number', precision=int, returns=bool)
+def should_fail_under(total, fail_under, precision):
"""Determine if a total should fail due to fail-under.
`total` is a float, the coverage measurement total. `fail_under` is the
- fail_under setting to compare with.
+ fail_under setting to compare with. `precision` is the number of digits
+ to consider after the decimal point.
Returns True if the total should fail.
"""
- # The fail_under option defaults to 0.
- if 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 < fail_under:
- return True
+ # Special case for fail_under=100, it must really be 100.
+ if fail_under == 100.0 and total != 100.0:
+ return True
- return False
+ return round(total, precision) < fail_under