From a4968586f42d43b70ff7dd4ee114e2592c5f041d Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Fri, 13 Sep 2024 15:42:10 -0400 Subject: [PATCH] Add tests for _make_coverage_info --- tests/unit/test_coverage.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/unit/test_coverage.py b/tests/unit/test_coverage.py index 67a03d1c..621219da 100644 --- a/tests/unit/test_coverage.py +++ b/tests/unit/test_coverage.py @@ -150,6 +150,42 @@ def test_generate_coverage_markdown(mocker): assert result == "foo" +def test__make_coverage_info(): + result = coverage._make_coverage_info( + { + "covered_lines": 14, + "num_statements": 20, + "missing_lines": 6, + "excluded_lines": 0, + } + ) + assert isinstance(result, coverage.CoverageInfo) + assert result.percent_covered == decimal.Decimal(14) / decimal.Decimal(20) + assert result.num_branches == 0 + assert result.num_partial_branches == 0 + assert result.covered_branches == 0 + assert result.missing_branches == 0 + + +def test__make_coverage_info__with_branches(): + result = coverage._make_coverage_info( + { + "covered_lines": 4, + "num_statements": 10, + "missing_lines": 1, + "excluded_lines": 0, + "covered_branches": 4, + "num_branches": 6, + "num_partial_branches": 2, + } + ) + assert isinstance(result, coverage.CoverageInfo) + assert result.percent_covered == decimal.Decimal(4 + 4) / decimal.Decimal(10 + 6) + assert result.covered_branches == 4 + assert result.missing_branches == 0 + assert result.excluded_lines == 0 + + @pytest.mark.parametrize( "added_lines, update_obj, expected", [