Skip to content

Commit ca41318

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

File tree

2 files changed

+64
-38
lines changed

2 files changed

+64
-38
lines changed

tests/conftest.py

Lines changed: 57 additions & 31 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 _
@@ -425,9 +425,19 @@ def coverage_code():
425425
9
426426
10 branch missing
427427
11 missing
428-
12
428+
12 covered
429429
13 branch covered
430430
14 covered
431+
15 branch partial
432+
16 branch covered
433+
17 branch missing
434+
18 covered
435+
19 covered
436+
20 branch partial
437+
21 branch missing
438+
22 branch covered
439+
23 branch covered
440+
24 branch covered
431441
"""
432442

433443

@@ -442,32 +452,48 @@ def coverage_json():
442452
},
443453
"files": {
444454
"codebase/code.py": {
445-
"executed_lines": [1, 2, 3, 5, 13, 14],
455+
"executed_lines": [
456+
1,
457+
2,
458+
3,
459+
5,
460+
12,
461+
13,
462+
14,
463+
15,
464+
16,
465+
18,
466+
19,
467+
20,
468+
22,
469+
23,
470+
24,
471+
],
446472
"summary": {
447-
"covered_lines": 6,
448-
"num_statements": 10,
449-
"percent_covered": 60.0,
450-
"missing_lines": 4,
473+
"covered_lines": 15,
474+
"num_statements": 21,
475+
"percent_covered": 0.625,
476+
"missing_lines": 6,
451477
"excluded_lines": 0,
452-
"num_branches": 3,
453-
"num_partial_branches": 1,
454-
"covered_branches": 1,
455-
"missing_branches": 1,
478+
"num_branches": 11,
479+
"num_partial_branches": 3,
480+
"covered_branches": 5,
481+
"missing_branches": 3,
456482
},
457-
"missing_lines": [6, 8, 10, 11],
483+
"missing_lines": [6, 8, 10, 11, 17, 21],
458484
"excluded_lines": [],
459485
}
460486
},
461487
"totals": {
462-
"covered_lines": 6,
463-
"num_statements": 10,
464-
"percent_covered": 60.0,
465-
"missing_lines": 4,
488+
"covered_lines": 15,
489+
"num_statements": 21,
490+
"percent_covered": 0.625,
491+
"missing_lines": 6,
466492
"excluded_lines": 0,
467-
"num_branches": 3,
468-
"num_partial_branches": 1,
469-
"covered_branches": 1,
470-
"missing_branches": 1,
493+
"num_branches": 11,
494+
"num_partial_branches": 3,
495+
"covered_branches": 5,
496+
"missing_branches": 3,
471497
},
472498
}
473499

tests/unit/test_template.py

Lines changed: 7 additions & 7 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%", "62.5%", "60%", "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 62.5%" src="https://img.shields.io/badge/Coverage%20evolution-92%25%20%3E%2062%25-red.svg"> <img title="60% of the statement lines added by this PR are covered" src="https://img.shields.io/badge/PR%20Coverage-60%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 21 statements to codebase/code.py. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/21-%28%2B21%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 6 statements missing coverage to codebase/code.py. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/6-%28%2B6%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 62.5% (15/21). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/62%25-%2815/21%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, 5 new statements are added to codebase/code.py, 3 of which are covered (60%)." src="https://img.shields.io/badge/60%25-%283/5%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 21 statements to the whole project. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/21-%28%2B21%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 6 statements missing coverage to the whole project. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/6-%28%2B6%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 62.5% (15/21). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/62%25-%2815/21%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, 5 new statements are added to the whole project, 3 of which are covered (60%)." src="https://img.shields.io/badge/60%25-%283/5%29-orange.svg"></a></td><td>&nbsp;</td>
9393
</tr>
9494
</tfoot>
9595
</table>
@@ -264,17 +264,17 @@ def test_template__no_previous(coverage_obj_no_branch, diff_coverage_obj):
264264
expected = """## Coverage report
265265
266266
267-
<img title="Coverage for the whole project is 50%. Previous coverage rate is not available, cannot report on evolution." src="https://img.shields.io/badge/Coverage-50%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-red.svg"><details><summary>Click to see where and how coverage changed</summary><table><thead>
267+
<img title="Coverage for the whole project is 50%. Previous coverage rate is not available, cannot report on evolution." src="https://img.shields.io/badge/Coverage-50%25-red.svg"> <img title="60% of the statement lines added by this PR are covered" src="https://img.shields.io/badge/PR%20Coverage-60%25-red.svg"><details><summary>Click to see where and how coverage changed</summary><table><thead>
268268
<tr><th>File</th><th>Statements</th><th>Missing</th><th>Coverage</th><th>Coverage<br>(new stmts)</th><th>Lines missing</th></tr>
269269
</thead>
270270
<tbody><tr>
271271
<td colspan="6">&nbsp;&nbsp;<b>codebase</b></td><tr>
272272
<td>&nbsp;&nbsp;<a href="https://github.com/org/repo/pull/3/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3">code.py</a></td>
273-
<td align="center"><a href="https://github.com/org/repo/pull/3/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="This PR adds 8 statements to codebase/code.py. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/8-%28%2B8%29-007ec6.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/3/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/3/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="The coverage rate of codebase/code.py is 50% (4/8). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/50%25-%284/8%29-red.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/3/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-red.svg"></a></td><td><a href="https://github.com/org/repo/pull/3/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3R6-R8">6-8</a></td></tbody>
273+
<td align="center"><a href="https://github.com/org/repo/pull/3/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="This PR adds 8 statements to codebase/code.py. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/8-%28%2B8%29-007ec6.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/3/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/3/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="The coverage rate of codebase/code.py is 50% (4/8). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/50%25-%284/8%29-red.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/3/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3"><img title="In this PR, 5 new statements are added to codebase/code.py, 3 of which are covered (60%)." src="https://img.shields.io/badge/60%25-%283/5%29-red.svg"></a></td><td><a href="https://github.com/org/repo/pull/3/files#diff-c05d5557f0c1ff3761df2f49e3b541cfc161f4f0d63e2a66d568f090065bc3d3R6-R8">6-8</a></td></tbody>
274274
<tfoot>
275275
<tr>
276276
<td><b>Project Total</b></td>
277-
<td align="center"><a href="https://github.com/org/repo/pull/3/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="This PR adds 8 statements to the whole project. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/8-%28%2B8%29-007ec6.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/3/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/3/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="The coverage rate of the whole project is 50% (4/8). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/50%25-%284/8%29-red.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/3/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-red.svg"></a></td><td>&nbsp;</td>
277+
<td align="center"><a href="https://github.com/org/repo/pull/3/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="This PR adds 8 statements to the whole project. The file did not seem to exist on the base branch." src="https://img.shields.io/badge/8-%28%2B8%29-007ec6.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/3/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/3/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="The coverage rate of the whole project is 50% (4/8). The file did not seem to exist on the base branch." src="https://img.shields.io/badge/50%25-%284/8%29-red.svg"></a></td><td align="center"><a href="https://github.com/org/repo/pull/3/files#diff-4b0bf2efa3367c0072ac2bf1e234e703dc46b47aaa4fe9d3b01737b1a15752b1"><img title="In this PR, 5 new statements are added to the whole project, 3 of which are covered (60%)." src="https://img.shields.io/badge/60%25-%283/5%29-red.svg"></a></td><td>&nbsp;</td>
278278
</tr>
279279
</tfoot>
280280
</table>

0 commit comments

Comments
 (0)