summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-05-31 19:37:53 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-05-31 19:37:53 -0400
commit1157999dc5c6c3aa3129a7cd4bf249fe73598501 (patch)
treecba407bacb180fb8fcb46a1b5eaf7da2e0fd88fb /tests
parent65d9e0edbca0dc893ca70fbf64969e2ddc5a3680 (diff)
downloadpython-coveragepy-git-1157999dc5c6c3aa3129a7cd4bf249fe73598501.tar.gz
fix: --fail-under=100 could report 100 is less than 100.
Use the same rounding rules for the fail-under message that are used for totals everywhere else, so that it won't say: total of 100 is less than fail-under=100
Diffstat (limited to 'tests')
-rw-r--r--tests/test_process.py16
-rw-r--r--tests/test_results.py12
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_process.py b/tests/test_process.py
index 9c695b2a..04a8a2d5 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -1249,6 +1249,22 @@ class FailUnderTest(CoverageTest):
expected = "Coverage failure: total of 42.86 is less than fail-under=42.88"
assert expected == self.last_line_squeezed(out)
+ def test_report_99p9_is_not_ok(self):
+ # A file with 99.99% coverage:
+ self.make_file("ninety_nine_plus.py", """\
+ a = 1
+ """ + """
+ b = 2
+ """ * 20000 + """
+ if a > 3:
+ c = 4
+ """)
+ self.run_command("coverage run --source=. ninety_nine_plus.py")
+ st, out = self.run_command_status("coverage report --fail-under=100")
+ assert st == 2
+ expected = "Coverage failure: total of 99 is less than fail-under=100"
+ assert expected == self.last_line_squeezed(out)
+
class FailUnderNoFilesTest(CoverageTest):
"""Test that nothing to report results in an error exit status."""
diff --git a/tests/test_results.py b/tests/test_results.py
index 5811b0c2..fa239e92 100644
--- a/tests/test_results.py
+++ b/tests/test_results.py
@@ -68,6 +68,18 @@ class NumbersTest(CoverageTest):
assert n10000.pc_covered_str == "0.0"
Numbers.set_precision(0)
+ @pytest.mark.parametrize("prec, pc, res", [
+ (0, 47.87, "48"),
+ (1, 47.87, "47.9"),
+ (0, 99.995, "99"),
+ (2, 99.99995, "99.99"),
+ ])
+ def test_display_covered(self, prec, pc, res):
+ # Numbers._precision is a global, which is bad.
+ Numbers.set_precision(prec)
+ assert Numbers.display_covered(pc) == res
+ Numbers.set_precision(0)
+
def test_covered_ratio(self):
n = Numbers(n_files=1, n_statements=200, n_missing=47)
assert n.ratio_covered == (153, 200)