diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/cmdline.py | 17 | ||||
-rw-r--r-- | coverage/results.py | 20 |
2 files changed, 24 insertions, 13 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index ce929f48..97acdc42 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -12,9 +12,10 @@ import traceback from coverage import env from coverage.collector import CTracer +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.debug import info_formatter, info_header +from coverage.results import should_fail_under class Opts(object): @@ -522,18 +523,8 @@ 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 + if should_fail_under(self.coverage, total): + return FAIL_UNDER return OK diff --git a/coverage/results.py b/coverage/results.py index 9df5d5b2..1ca55e87 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -269,3 +269,23 @@ class Numbers(SimpleRepr): if other == 0: return self return NotImplemented + + +def should_fail_under(cov, total): + """Determine if a total should fail due to fail-under. + + Returns True if the total should fail. + + """ + if cov.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 < cov.get_option("report:fail_under"): + return True + + return False |