Skip to content

Commit

Permalink
test: add a test of json regions with branches
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jul 11, 2024
1 parent 8b89764 commit a9992d2
Showing 1 changed file with 166 additions and 21 deletions.
187 changes: 166 additions & 21 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ def _assert_expected_json_report_with_regions(
Helper that creates an example file for regions tests.
"""
self.make_file("b.py", """\
a = {'b': 1}
a = {"b": 1}
def c():
return 1
return 4
class C:
pass
class D:
def e(self):
return 2
if a.get("a"):
return 12
return 13
def f(self):
return 3
return 15
""")
self._compare_json_reports(cov, expected_result, "b")

Expand Down Expand Up @@ -187,16 +189,16 @@ def test_regions_coverage(self) -> None:
},
"files": {
"b.py": {
"executed_lines": [1, 3, 6, 7, 9, 10, 12],
"executed_lines": [1, 3, 6, 7, 9, 10, 14],
"summary": {
"covered_lines": 7,
"num_statements": 10,
"percent_covered": 70.0,
"percent_covered_display": "70",
"missing_lines": 3,
"num_statements": 12,
"percent_covered": 58.333333333333336,
"percent_covered_display": "58",
"missing_lines": 5,
"excluded_lines": 0,
},
"missing_lines": [4, 11, 13],
"missing_lines": [4, 11, 12, 13, 15],
"excluded_lines": [],
"function": {
"c": {
Expand All @@ -216,13 +218,13 @@ def test_regions_coverage(self) -> None:
"executed_lines": [],
"summary": {
"covered_lines": 0,
"num_statements": 1,
"num_statements": 3,
"percent_covered": 0.0,
"percent_covered_display": "0",
"missing_lines": 1,
"missing_lines": 3,
"excluded_lines": 0,
},
"missing_lines": [11],
"missing_lines": [11, 12, 13],
"excluded_lines": [],
},
"D.f": {
Expand All @@ -235,7 +237,7 @@ def test_regions_coverage(self) -> None:
"missing_lines": 1,
"excluded_lines": 0,
},
"missing_lines": [13],
"missing_lines": [15],
"excluded_lines": [],
},
},
Expand All @@ -257,25 +259,168 @@ def test_regions_coverage(self) -> None:
"executed_lines": [],
"summary": {
"covered_lines": 0,
"num_statements": 2,
"num_statements": 4,
"percent_covered": 0.0,
"percent_covered_display": "0",
"missing_lines": 4,
"excluded_lines": 0,
},
"missing_lines": [11, 12, 13, 15],
"excluded_lines": [],
},
},
},
},
"totals": {
"covered_lines": 7,
"num_statements": 12,
"percent_covered": 58.333333333333336,
"percent_covered_display": "58",
"missing_lines": 5,
"excluded_lines": 0,
},
}
self._assert_expected_json_report_with_regions(cov, expected_result)

def test_branch_regions_coverage(self) -> None:
cov = coverage.Coverage(branch=True)
expected_result = {
"files": {
"b.py": {
"class": {
"C": {
"excluded_lines": [],
"executed_branches": [],
"executed_lines": [],
"missing_branches": [],
"missing_lines": [],
"summary": {
"covered_branches": 0,
"covered_lines": 0,
"excluded_lines": 0,
"missing_branches": 0,
"missing_lines": 0,
"num_branches": 0,
"num_partial_branches": 0,
"num_statements": 0,
"percent_covered": 100.0,
"percent_covered_display": "100",
},
},
"D": {
"excluded_lines": [],
"executed_branches": [],
"executed_lines": [],
"missing_branches": [[11, 12], [11, 13]],
"missing_lines": [11, 12, 13, 15],
"summary": {
"covered_branches": 0,
"covered_lines": 0,
"excluded_lines": 0,
"missing_branches": 2,
"missing_lines": 4,
"num_branches": 2,
"num_partial_branches": 0,
"num_statements": 4,
"percent_covered": 0.0,
"percent_covered_display": "0",
},
},
},
"excluded_lines": [],
"executed_branches": [],
"executed_lines": [1, 3, 6, 7, 9, 10, 14],
"function": {
"D.e": {
"excluded_lines": [],
"executed_branches": [],
"executed_lines": [],
"missing_branches": [[11, 12], [11, 13]],
"missing_lines": [11, 12, 13],
"summary": {
"covered_branches": 0,
"covered_lines": 0,
"excluded_lines": 0,
"missing_branches": 2,
"missing_lines": 3,
"num_branches": 2,
"num_partial_branches": 0,
"num_statements": 3,
"percent_covered": 0.0,
"percent_covered_display": "0",
"missing_lines": 2,
},
},
"D.f": {
"excluded_lines": [],
"executed_branches": [],
"executed_lines": [],
"missing_branches": [],
"missing_lines": [15],
"summary": {
"covered_branches": 0,
"covered_lines": 0,
"excluded_lines": 0,
"missing_branches": 0,
"missing_lines": 1,
"num_branches": 0,
"num_partial_branches": 0,
"num_statements": 1,
"percent_covered": 0.0,
"percent_covered_display": "0",
},
"missing_lines": [11, 13],
},
"c": {
"excluded_lines": [],
"executed_branches": [],
"executed_lines": [],
"missing_branches": [],
"missing_lines": [4],
"summary": {
"covered_branches": 0,
"covered_lines": 0,
"excluded_lines": 0,
"missing_branches": 0,
"missing_lines": 1,
"num_branches": 0,
"num_partial_branches": 0,
"num_statements": 1,
"percent_covered": 0.0,
"percent_covered_display": "0",
},
},
},
"missing_branches": [[11, 12], [11, 13]],
"missing_lines": [4, 11, 12, 13, 15],
"summary": {
"covered_branches": 0,
"covered_lines": 7,
"excluded_lines": 0,
"missing_branches": 2,
"missing_lines": 5,
"num_branches": 2,
"num_partial_branches": 0,
"num_statements": 12,
"percent_covered": 50.0,
"percent_covered_display": "50",
},
},
},
"meta": {
"branch_coverage": True,
"format": 2,
"show_contexts": False,
},
"totals": {
"covered_branches": 0,
"covered_lines": 7,
"num_statements": 10,
"percent_covered": 70.0,
"percent_covered_display": "70",
"missing_lines": 3,
"excluded_lines": 0,
"missing_branches": 2,
"missing_lines": 5,
"num_branches": 2,
"num_partial_branches": 0,
"num_statements": 12,
"percent_covered": 50.0,
"percent_covered_display": "50",
},
}
self._assert_expected_json_report_with_regions(cov, expected_result)
Expand Down

0 comments on commit a9992d2

Please sign in to comment.