Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Jan 1, 2024
1 parent 5de9dd2 commit 0bf474d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
5 changes: 2 additions & 3 deletions tests/end_to_end/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def test_public_repo(
"--jq=.comments[0].body",
fail_value="\n",
)
assert ":arrow_up:" in comment
assert "## Coverage report (my-great-project)" in comment
assert (
"This comment was produced by python-coverage-comment-action (id: my-great-project)"
Expand Down Expand Up @@ -184,7 +183,7 @@ def test_public_repo(
fail_value="\n",
)

assert ":arrow_up:" in ext_comment
assert "-brightgreen.svg" in ext_comment


@pytest.mark.repo_suffix("private")
Expand Down Expand Up @@ -275,7 +274,7 @@ def test_private_repo(
"--jq=.comments[0].body",
fail_value="\n",
)
assert ":arrow_up:" in comment
assert "-brightgreen.svg" in comment

# Let's merge the PR and see if everything works fine
gh_me("pr", "merge", "1", "--merge")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ def test_annotations(capsys):
annotation_type="warning",
annotations=[
(pathlib.Path("codebase/code.py"), 1, 3),
(pathlib.Path("codebase/main.py"), 5, 5),
(pathlib.Path("codebase/other.py"), 5, 5),
],
)

expected = """::group::Annotations of lines with missing coverage
::warning file=codebase/code.py,line=1,endLine=3,title=Missing coverage::Missing coverage on lines 1-3
::warning file=codebase/main.py,line=5,endLine=5,title=Missing coverage::Missing coverage on line 5
::warning file=codebase/other.py,line=5,endLine=5,title=Missing coverage::Missing coverage on line 5
::endgroup::"""
output = capsys.readouterr()
assert output.err.strip() == expected
23 changes: 16 additions & 7 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,16 @@ def checker(payload):
comment_file = pathlib.Path("python-coverage-comment-action.txt").read_text()
assert comment == comment_file
assert comment == summary_file.read_text()
assert "Coverage data for the default branch was not found." in comment
assert "The coverage rate is `77.77%`" in comment
assert "`75%` of new lines are covered." in comment
assert (
"### foo.py\n`75%` of new lines are covered (`77.77%` of the complete file)"
"Coverage for the whole project is 77.77%. Previous coverage rate is not available"
in comment
)
assert (
"In this PR, 4 new statements are added to the whole project, 3 of which are covered (75%)."
in comment
)
assert (
"https://github.com/py-cov-action/foobar/pull/2/files#diff-b08fd7a517303ab07cfa211f74d03c1a4c2e64b3b0656d84ff32ecb449b785d2"
in comment
)
assert (
Expand Down Expand Up @@ -270,7 +275,10 @@ def checker(payload):
comment_file = pathlib.Path("python-coverage-comment-action.txt").read_text()
assert comment == comment_file
assert comment == summary_file.read_text()
assert "Coverage evolution disabled because this PR targets" in comment
assert (
"Previous coverage rate is not available, cannot report on evolution."
in comment
)


def test_action__pull_request__post_comment(
Expand Down Expand Up @@ -324,7 +332,8 @@ def checker(payload):
assert result == 0

assert not pathlib.Path("python-coverage-comment-action.txt").exists()
assert "The coverage rate went from `30%` to `77.77%` :arrow_up:" in comment
assert "Coverage for the whole project went from 30% to 77.77%" in comment
assert comment.count("<img") == 10
assert comment == summary_file.read_text()

expected_output = "COMMENT_FILE_WRITTEN=false\n"
Expand Down Expand Up @@ -394,7 +403,7 @@ def checker(payload):
assert result == 0

assert not pathlib.Path("python-coverage-comment-action.txt").exists()
assert "The coverage rate went from `30%` to `77.77%` :arrow_up:" in comment
assert "Coverage for the whole project went from 30% to 77.77%" in comment
assert comment == summary_file.read_text()

expected_output = "COMMENT_FILE_WRITTEN=false\n"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_compute_badge_image(session):
def test_get_static_badge_url():
result = badge.get_static_badge_url(label="a-b", message="c_d e", color="green")

assert result == "https://img.shields.io/badge/a--b-c__d_e-green.svg"
assert result == "https://img.shields.io/badge/a--b-c__d%20e-green.svg"


@pytest.mark.parametrize(
Expand Down
30 changes: 26 additions & 4 deletions tests/unit/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
from coverage_comment import coverage, subprocess


def test_diff_violations(make_coverage_and_diff):
_, diff = make_coverage_and_diff(
"""
# file: a.py
+ 1 missing
2 missing
+ 3 missing
4 covered
+ 5 covered
"""
)
assert diff.files[pathlib.Path("a.py")].violation_lines == [1, 3]


@pytest.mark.parametrize(
"num_covered, num_total, expected_coverage",
[
Expand Down Expand Up @@ -137,7 +151,9 @@ def test_generate_coverage_markdown(mocker):
pathlib.Path("codebase/code.py"): coverage.FileDiffCoverage(
path=pathlib.Path("codebase/code.py"),
percent_covered=decimal.Decimal("0.5"),
missing_lines=[3],
added_statements=[1, 3],
covered_statements=[1],
missing_statements=[3],
added_lines=[1, 3],
)
},
Expand Down Expand Up @@ -174,7 +190,9 @@ def test_generate_coverage_markdown(mocker):
pathlib.Path("codebase/code.py"): coverage.FileDiffCoverage(
path=pathlib.Path("codebase/code.py"),
percent_covered=decimal.Decimal("1"),
missing_lines=[],
added_statements=[],
covered_statements=[],
missing_statements=[],
added_lines=[4, 5, 6],
)
},
Expand Down Expand Up @@ -207,13 +225,17 @@ def test_generate_coverage_markdown(mocker):
pathlib.Path("codebase/code.py"): coverage.FileDiffCoverage(
path=pathlib.Path("codebase/code.py"),
percent_covered=decimal.Decimal("1"),
missing_lines=[],
added_statements=[5, 6],
covered_statements=[5, 6],
missing_statements=[],
added_lines=[4, 5, 6],
),
pathlib.Path("codebase/other.py"): coverage.FileDiffCoverage(
path=pathlib.Path("codebase/other.py"),
percent_covered=decimal.Decimal("0.5"),
missing_lines=[13],
added_statements=[10, 13],
covered_statements=[10],
missing_statements=[13],
added_lines=[10, 13],
),
},
Expand Down

0 comments on commit 0bf474d

Please sign in to comment.