Skip to content

Commit

Permalink
Merge pull request #171 from econchick/round-perc-covered
Browse files Browse the repository at this point in the history
Merge pull request #170 from econchick/include-deleters
  • Loading branch information
econchick authored Apr 7, 2024
2 parents 4e7e967 + d3cddca commit 1a28d80
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Fixed
^^^^^

* Include support for deleters when ignoring property decorators (`#126 <https://github.com/econchick/interrogate/issues/126>_`).
* Support floats for `--fail-under` values (`#114 <https://github.com/econchick/interrogate/issues/114>`_).

Removed
^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion src/interrogate/coverage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2020 Lynn Root
"""Measure and report on documentation coverage in Python modules."""
import ast
import decimal
import os
import pathlib
import sys
Expand Down Expand Up @@ -240,7 +241,10 @@ def _get_coverage(self, filenames):

results.combine()

if self.config.fail_under > results.perc_covered:
fail_under_str = str(self.config.fail_under)
round_to = -decimal.Decimal(fail_under_str).as_tuple().exponent

if self.config.fail_under > round(results.perc_covered, round_to):
results.ret_code = 1

return results
Expand Down
29 changes: 29 additions & 0 deletions tests/functional/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,32 @@ def test_print_results_single_file(capsys, monkeypatch):
else:
assert "tests\\functional\\sample\\" in captured.out
assert "tests\\functional\\sample\\full.py" not in captured.out


@pytest.mark.parametrize(
"fail_under,perc_covered,exp_ret",
[
(48.3, 48.27, 0),
(48.36, 48.359, 0),
(48.35, 48.349, 0),
(48.55, 48.500, 1),
(50.999999, 50.999998, 1),
(50.999999, 50.999999, 0),
],
)
def test_pass_when_fail_under_exact(
fail_under, perc_covered, exp_ret, monkeypatch
):
"""Pass if actual coverage is exactly the `--fail-under` value.
See issue `#114 <https://github.com/econchick/interrogate/issues/114>`_.
"""
monkeypatch.setattr(
coverage.InterrogateResults, "perc_covered", perc_covered
)

interrogate_config = config.InterrogateConfig(fail_under=fail_under)
interrogate_coverage = coverage.InterrogateCoverage(
paths=[SAMPLE_DIR], conf=interrogate_config
)
results = interrogate_coverage.get_coverage()
assert exp_ret == results.ret_code

0 comments on commit 1a28d80

Please sign in to comment.