Skip to content

Commit 9c04cbb

Browse files
committed
Adjust tests for branch coverage support
1 parent f22d2c6 commit 9c04cbb

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

tests/conftest.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ def _(code: str, has_branches: bool = True) -> coverage_module.Coverage:
282282
percent_covered=decimal.Decimal("1.0"),
283283
missing_lines=0,
284284
excluded_lines=0,
285-
num_branches=0 if has_branches else None,
286-
num_partial_branches=0 if has_branches else None,
287-
covered_branches=0 if has_branches else None,
288-
missing_branches=0 if has_branches else None,
285+
num_branches=0,
286+
num_partial_branches=0,
287+
covered_branches=0,
288+
missing_branches=0,
289289
),
290290
files={},
291291
)
@@ -313,10 +313,10 @@ def _(code: str, has_branches: bool = True) -> coverage_module.Coverage:
313313
percent_covered=decimal.Decimal("1.0"),
314314
missing_lines=0,
315315
excluded_lines=0,
316-
num_branches=0 if has_branches else None,
317-
num_partial_branches=0 if has_branches else None,
318-
covered_branches=0 if has_branches else None,
319-
missing_branches=0 if has_branches else None,
316+
num_branches=0,
317+
num_partial_branches=0,
318+
covered_branches=0,
319+
missing_branches=0,
320320
),
321321
)
322322
if set(line.split()) & {
@@ -340,7 +340,6 @@ def _(code: str, has_branches: bool = True) -> coverage_module.Coverage:
340340
coverage_obj.files[current_file].excluded_lines.append(line_number)
341341
coverage_obj.files[current_file].info.excluded_lines += 1
342342
coverage_obj.info.excluded_lines += 1
343-
344343
if has_branches and "branch" in line:
345344
coverage_obj.files[current_file].info.num_branches += 1
346345
coverage_obj.info.num_branches += 1
@@ -353,21 +352,22 @@ def _(code: str, has_branches: bool = True) -> coverage_module.Coverage:
353352
elif "branch missing" in line:
354353
coverage_obj.files[current_file].info.missing_branches += 1
355354
coverage_obj.info.missing_branches += 1
356-
357355
info = coverage_obj.files[current_file].info
358356
coverage_obj.files[
359357
current_file
360358
].info.percent_covered = coverage_module.compute_coverage(
361359
num_covered=info.covered_lines,
362360
num_total=info.num_statements,
361+
num_branches_covered=info.covered_branches,
362+
num_branches_total=info.num_branches,
363363
)
364-
365364
info = coverage_obj.info
366365
coverage_obj.info.percent_covered = coverage_module.compute_coverage(
367366
num_covered=info.covered_lines,
368367
num_total=info.num_statements,
368+
num_branches_covered=info.covered_branches,
369+
num_branches_total=info.num_branches,
369370
)
370-
371371
return coverage_obj
372372

373373
return _
@@ -446,7 +446,7 @@ def coverage_json():
446446
"summary": {
447447
"covered_lines": 6,
448448
"num_statements": 10,
449-
"percent_covered": 60.0,
449+
"percent_covered": 53.84615384615384615384615385,
450450
"missing_lines": 4,
451451
"excluded_lines": 0,
452452
"num_branches": 3,
@@ -461,7 +461,7 @@ def coverage_json():
461461
"totals": {
462462
"covered_lines": 6,
463463
"num_statements": 10,
464-
"percent_covered": 60.0,
464+
"percent_covered": 53.84615384615384615384615385,
465465
"missing_lines": 4,
466466
"excluded_lines": 0,
467467
"num_branches": 3,

tests/unit/test_template.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_get_comment_markdown(coverage_obj, diff_coverage_obj):
4444
.split(maxsplit=4)
4545
)
4646

47-
expected = ["92%", "60%", "50%", "bar", "<!-- foo -->"]
47+
expected = ["92%", "53.84%", "50%", "bar", "<!-- foo -->"]
4848

4949
assert result == expected
5050

@@ -79,17 +79,17 @@ def test_template(coverage_obj, diff_coverage_obj):
7979
expected = """## Coverage report (foo)
8080
8181
82-
<img title="Coverage for the whole project went from 92% to 60%" src="https://img.shields.io/badge/Coverage%20evolution-92%25%20%3E%2060%25-red.svg"> <img title="50% of the statement lines added by this PR are covered" src="https://img.shields.io/badge/PR%20Coverage-50%25-orange.svg"><details><summary>Click to see where and how coverage changed</summary><table><thead>
82+
<img title="Coverage for the whole project went from 92% to 53.84%" src="https://img.shields.io/badge/Coverage%20evolution-92%25%20%3E%2053%25-red.svg"> <img title="50% of the statement lines added by this PR are covered" src="https://img.shields.io/badge/PR%20Coverage-50%25-orange.svg"><details><summary>Click to see where and how coverage changed</summary><table><thead>
8383
<tr><th>File</th><th>Statements</th><th>Missing</th><th>Coverage</th><th>Coverage<br>(new stmts)</th><th>Lines missing</th></tr>
8484
</thead>
8585
<tbody><tr>
8686
<td colspan="6">&nbsp;&nbsp;<b>codebase</b></td><tr>
8787
<td>&nbsp;&nbsp;<a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3">code.py</a></td>
88-
<td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="This PR adds 10 statements to codebase/code.py. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/10-%28%2B10%29-007ec6.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="This PR adds 4 statements missing coverage to codebase/code.py. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/4-%28%2B4%29-red.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="The coverage rate of codebase/code.py is 60% (6/10). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/60%25-%286/10%29-orange.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="In this PR, 4 new statements are added to codebase/code.py, 2 of which are covered (50%)." src="https://img.shields.io/badge/50%25-%282/4%29-orange.svg"></a></td><td><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3R6-R8">6-8</a></td></tbody>
88+
<td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="This PR adds 10 statements to codebase/code.py. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/10-%28%2B10%29-007ec6.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="This PR adds 4 statements missing coverage to codebase/code.py. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/4-%28%2B4%29-red.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="The coverage rate of codebase/code.py is 53.84% (6/10). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/53%25-%286/10%29-orange.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="In this PR, 4 new statements are added to codebase/code.py, 2 of which are covered (50%)." src="https://img.shields.io/badge/50%25-%282/4%29-orange.svg"></a></td><td><a href="https://github.com/org/repo/pull/5/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3R6-R8">6-8</a></td></tbody>
8989
<tfoot>
9090
<tr>
9191
<td><b>Project Total</b></td>
92-
<td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="This PR adds 10 statements to the whole project. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/10-%28%2B10%29-007ec6.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="This PR adds 4 statements missing coverage to the whole project. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/4-%28%2B4%29-red.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="The coverage rate of the whole project is 60% (6/10). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/60%25-%286/10%29-orange.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="In this PR, 4 new statements are added to the whole project, 2 of which are covered (50%)." src="https://img.shields.io/badge/50%25-%282/4%29-orange.svg"></a></td><td>&nbsp;</td>
92+
<td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="This PR adds 10 statements to the whole project. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/10-%28%2B10%29-007ec6.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="This PR adds 4 statements missing coverage to the whole project. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/4-%28%2B4%29-red.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="The coverage rate of the whole project is 53.84% (6/10). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/53%25-%286/10%29-orange.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/5/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="In this PR, 4 new statements are added to the whole project, 2 of which are covered (50%)." src="https://img.shields.io/badge/50%25-%282/4%29-orange.svg"></a></td><td>&nbsp;</td>
9393
</tr>
9494
</tfoot>
9595
</table>

0 commit comments

Comments
 (0)