@@ -30,6 +30,7 @@ def test_get_comment_markdown(coverage_obj, diff_coverage_obj):
3030 github_host = "https://github.com" ,
3131 repo_name = "org/repo" ,
3232 pr_number = 1 ,
33+ branch_name = None ,
3334 base_template = """
3435 {{ previous_coverage_rate | pct }}
3536 {{ coverage.info.percent_covered | pct }}
@@ -70,6 +71,7 @@ def test_template(coverage_obj, diff_coverage_obj):
7071 github_host = "https://github.com" ,
7172 repo_name = "org/repo" ,
7273 pr_number = 5 ,
74+ branch_name = None ,
7375 base_template = template .read_template_file ("comment.md.j2" ),
7476 marker = "<!-- foo -->" ,
7577 subproject_id = "foo" ,
@@ -200,6 +202,7 @@ def test_template_full(make_coverage, make_coverage_and_diff):
200202 github_host = "https://github.com" ,
201203 repo_name = "org/repo" ,
202204 pr_number = 12 ,
205+ branch_name = None ,
203206 base_template = template .read_template_file ("comment.md.j2" ),
204207 )
205208 expected = """## Coverage report
@@ -263,6 +266,7 @@ def test_template__no_previous(coverage_obj_no_branch, diff_coverage_obj):
263266 github_host = "https://github.com" ,
264267 repo_name = "org/repo" ,
265268 pr_number = 3 ,
269+ branch_name = None ,
266270 base_template = template .read_template_file ("comment.md.j2" ),
267271 )
268272 expected = """## Coverage report
@@ -316,6 +320,7 @@ def test_template__max_files(coverage_obj_more_files, diff_coverage_obj_more_fil
316320 github_host = "https://github.com" ,
317321 repo_name = "org/repo" ,
318322 pr_number = 5 ,
323+ branch_name = None ,
319324 max_files = 1 ,
320325 base_template = template .read_template_file ("comment.md.j2" ),
321326 marker = "<!-- foo -->" ,
@@ -348,6 +353,7 @@ def test_template__no_max_files(coverage_obj_more_files, diff_coverage_obj_more_
348353 github_host = "https://github.com" ,
349354 repo_name = "org/repo" ,
350355 pr_number = 5 ,
356+ branch_name = None ,
351357 max_files = None ,
352358 base_template = template .read_template_file ("comment.md.j2" ),
353359 marker = "<!-- foo -->" ,
@@ -383,6 +389,7 @@ def test_template__no_files(coverage_obj, diff_coverage_obj_more_files):
383389 github_host = "https://github.com" ,
384390 repo_name = "org/repo" ,
385391 pr_number = 5 ,
392+ branch_name = None ,
386393 max_files = 25 ,
387394 base_template = template .read_template_file ("comment.md.j2" ),
388395 marker = "<!-- foo -->" ,
@@ -422,6 +429,7 @@ def test_template__no_marker(coverage_obj, diff_coverage_obj):
422429 github_host = "https://github.com" ,
423430 repo_name = "org/repo" ,
424431 pr_number = 1 ,
432+ branch_name = None ,
425433 base_template = template .read_template_file ("comment.md.j2" ),
426434 marker = "<!-- foo -->" ,
427435 custom_template = """foo bar""" ,
@@ -443,6 +451,7 @@ def test_template__broken_template(coverage_obj, diff_coverage_obj):
443451 github_host = "https://github.com" ,
444452 repo_name = "org/repo" ,
445453 pr_number = 1 ,
454+ branch_name = None ,
446455 base_template = template .read_template_file ("comment.md.j2" ),
447456 marker = "<!-- foo -->" ,
448457 custom_template = """{% extends "foo" %}""" ,
@@ -482,36 +491,69 @@ def test_pluralize(number, singular, plural, expected):
482491
483492
484493@pytest .mark .parametrize (
485- "filepath, lines, expected" ,
494+ "filepath, lines, pr_number, branch_name, expected" ,
486495 [
487496 (
488497 pathlib .Path ("tests/conftest.py" ),
489498 None ,
499+ 33 ,
500+ None ,
490501 "https://github.com/py-cov-action/python-coverage-comment-action/pull/33/files#diff-e52e4ddd58b7ef887ab03c04116e676f6280b824ab7469d5d3080e5cba4f2128" ,
491502 ),
492503 (
493504 pathlib .Path ("main.py" ),
494505 (12 , 15 ),
506+ 33 ,
507+ None ,
495508 "https://github.com/py-cov-action/python-coverage-comment-action/pull/33/files#diff-b10564ab7d2c520cdd0243874879fb0a782862c3c902ab535faabe57d5a505e1R12-R15" ,
496509 ),
497510 (
498511 pathlib .Path ("codebase/other.py" ),
499512 (22 , 22 ),
513+ 33 ,
514+ None ,
500515 "https://github.com/py-cov-action/python-coverage-comment-action/pull/33/files#diff-30cad827f61772ec66bb9ef8887058e6d8443a2afedb331d800feaa60228a26eR22-R22" ,
501516 ),
517+ (
518+ pathlib .Path ("tests/conftest.py" ),
519+ None ,
520+ None ,
521+ "mybranch" ,
522+ "https://github.com/py-cov-action/python-coverage-comment-action/blob/mybranch/tests/conftest.py" ,
523+ ),
524+ (
525+ pathlib .Path ("main.py" ),
526+ (12 , 15 ),
527+ None ,
528+ "mybranch" ,
529+ "https://github.com/py-cov-action/python-coverage-comment-action/blob/mybranch/main.py#L12-L15" ,
530+ ),
502531 ],
503532)
504- def test_get_file_url (filepath , lines , expected ):
533+ def test_get_file_url (filepath , lines , pr_number , branch_name , expected ):
505534 result = template .get_file_url (
506535 filename = filepath ,
507536 lines = lines ,
508537 github_host = "https://github.com" ,
509538 repo_name = "py-cov-action/python-coverage-comment-action" ,
510- pr_number = 33 ,
539+ pr_number = pr_number ,
540+ branch_name = branch_name ,
511541 )
512542 assert result == expected
513543
514544
545+ def test_get_file_url__neither_pr_number_nor_branch_name ():
546+ with pytest .raises (Exception ):
547+ template .get_file_url (
548+ filename = pathlib .Path ("main.py" ),
549+ lines = None ,
550+ github_host = "https://github.com" ,
551+ repo_name = "py-cov-action/python-coverage-comment-action" ,
552+ pr_number = None ,
553+ branch_name = None ,
554+ )
555+
556+
515557def test_uptodate ():
516558 assert template .uptodate () is True
517559
0 commit comments