diff options
-rw-r--r-- | tests/test_config.py | 5 | ||||
-rw-r--r-- | tests/test_plugins.py | 7 | ||||
-rw-r--r-- | tests/test_results.py | 6 | ||||
-rw-r--r-- | tests/test_summary.py | 7 |
4 files changed, 15 insertions, 10 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index 9a64d5b1..d85dfc7b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -3,6 +3,7 @@ """Test the config file handling for coverage.py""" +import math from collections import OrderedDict from unittest import mock @@ -87,7 +88,7 @@ class ConfigTest(CoverageTest): assert cov.config.plugins == ["plugins.a_plugin"] assert cov.config.precision == 3 assert cov.config.html_title == "tabblo & «ταБЬℓσ»" - assert round(abs(cov.config.fail_under-90.5), 7) == 0 + assert math.isclose(cov.config.fail_under, 90.5) assert cov.config.get_plugin_options("plugins.a_plugin") == {"hello": "world"} # Test that our class doesn't reject integers when loading floats @@ -97,7 +98,7 @@ class ConfigTest(CoverageTest): fail_under = 90 """) cov = coverage.Coverage(config_file="pyproject.toml") - assert round(abs(cov.config.fail_under-90), 7) == 0 + assert math.isclose(cov.config.fail_under, 90) assert isinstance(cov.config.fail_under, float) def test_ignored_config_file(self): diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 2140f00c..45b3bc9e 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -5,6 +5,7 @@ import inspect import io +import math import os.path from xml.etree import ElementTree @@ -426,7 +427,7 @@ class GoodFileTracerTest(FileTracerTest): 'TOTAL 11 7 0 0 36%', ] assert expected == report - assert round(abs(total-36.36), 2) == 0 + assert math.isclose(total, 4 / 11 * 100) def test_plugin2_with_html_report(self): self.make_render_and_caller() @@ -437,7 +438,7 @@ class GoodFileTracerTest(FileTracerTest): self.start_import_stop(cov, "caller") total = cov.html_report(include=["*.html"], omit=["uni*.html"]) - assert round(abs(total-36.36), 2) == 0 + assert math.isclose(total, 4 / 11 * 100) self.assert_exists("htmlcov/index.html") self.assert_exists("htmlcov/bar_4_html.html") @@ -452,7 +453,7 @@ class GoodFileTracerTest(FileTracerTest): self.start_import_stop(cov, "caller") total = cov.xml_report(include=["*.html"], omit=["uni*.html"]) - assert round(abs(total-36.36), 2) == 0 + assert math.isclose(total, 4 / 11 * 100) dom = ElementTree.parse("coverage.xml") classes = {} diff --git a/tests/test_results.py b/tests/test_results.py index 8b2a737b..4138ffd4 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -3,6 +3,8 @@ """Tests for coverage.py's results analysis.""" +import math + import pytest from coverage.exceptions import ConfigError @@ -31,7 +33,7 @@ class NumbersTest(CoverageTest): assert n3.n_statements == 210 assert n3.n_executed == 182 assert n3.n_missing == 28 - assert round(abs(n3.pc_covered-86.666666666), 7) == 0 + assert math.isclose(n3.pc_covered, 86.666666666) def test_sum(self): n1 = Numbers(n_files=1, n_statements=200, n_missing=20) @@ -41,7 +43,7 @@ class NumbersTest(CoverageTest): assert n3.n_statements == 210 assert n3.n_executed == 182 assert n3.n_missing == 28 - assert round(abs(n3.pc_covered-86.666666666), 7) == 0 + assert math.isclose(n3.pc_covered, 86.666666666) @pytest.mark.parametrize("kwargs, res", [ (dict(n_files=1, n_statements=1000, n_missing=0), "100"), diff --git a/tests/test_summary.py b/tests/test_summary.py index dcf244a1..7e8f2919 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -5,6 +5,7 @@ import glob import io +import math import os import os.path import py_compile @@ -778,17 +779,17 @@ class ReportingReturnValueTest(CoverageTest): def test_report(self): cov = self.run_coverage() val = cov.report(include="*/doit.py") - assert round(abs(val-85.7), 1) == 0 + assert math.isclose(val, 6 / 7 * 100) def test_html(self): cov = self.run_coverage() val = cov.html_report(include="*/doit.py") - assert round(abs(val-85.7), 1) == 0 + assert math.isclose(val, 6 / 7 * 100) def test_xml(self): cov = self.run_coverage() val = cov.xml_report(include="*/doit.py") - assert round(abs(val-85.7), 1) == 0 + assert math.isclose(val, 6 / 7 * 100) class SummaryReporterConfigurationTest(CoverageTest): |