Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: vcs.git.backend tests #9507

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

indrajithi
Copy link
Contributor

@indrajithi indrajithi commented Jun 20, 2024

Pull Request Check List

Relates-to: #3155

  • Added tests for poetry.vcs.git.backend (increased coverage from 30% to 51%)

@indrajithi indrajithi changed the title Feature/vcs backend tests Test/vcs backend tests Jun 20, 2024
@indrajithi indrajithi changed the title Test/vcs backend tests Test: vcs.git.backend tests Jun 20, 2024
@indrajithi indrajithi marked this pull request as ready for review June 20, 2024 08:18
Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See suggestions.

PS: Please do not use "Resolves" for a permanent issue (because it will be closed automatically if your PR is merged). I changed it to "Relates-to".

tests/vcs/git/test_backend.py Outdated Show resolved Hide resolved
tests/vcs/git/test_backend.py Outdated Show resolved Hide resolved
tests/vcs/git/test_backend.py Outdated Show resolved Hide resolved
Comment on lines 139 to 173
def test_git_ref_spec_resolve_branch(fetch_pack_result: FetchPackResult) -> None:
mock_fetch_pack_result = fetch_pack_result

refspec = GitRefSpec(branch="main")
refspec.resolve(mock_fetch_pack_result)

assert refspec.ref == b"refs/heads/main"
assert refspec.branch == "main"
assert refspec.revision is None
assert refspec.tag is None


def test_git_ref_spec_resolve_tag(fetch_pack_result: FetchPackResult) -> None:
mock_fetch_pack_result = fetch_pack_result

refspec = GitRefSpec(revision="v1.0.0")
refspec.resolve(mock_fetch_pack_result)

assert refspec.ref == annotated_tag(b"refs/tags/v1.0.0")
assert refspec.branch is None
assert refspec.revision is None
assert refspec.tag == "v1.0.0"


def test_git_ref_spec_resolve_sha(fetch_pack_result: FetchPackResult) -> None:
mock_fetch_pack_result = fetch_pack_result

refspec = GitRefSpec(revision="abc")

refspec.resolve(mock_fetch_pack_result)

assert refspec.ref == b"refs/heads/main"
assert refspec.branch is None
assert refspec.tag is None
assert refspec.revision == "abc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge these three ref_spec_resolve tests into one parameterized test?

There are still some uncovered branches in _normalise, e.g. specifying a branch as revision, which can be covered easily. If we add more test variants, a parameterized tests will make even more sense.

@Secrus Secrus added this to the Poetry 2.0 milestone Oct 6, 2024
@Secrus Secrus removed this from the Poetry 2.0 milestone Nov 5, 2024
Comment on lines +157 to +166
Parameterized test for GitRefSpec resolve with different parameters.

Args:
fetch_pack_result (FetchPackResult): The mocked FetchPackResult object.
refspec_params (dict): Parameters for creating GitRefSpec.
expected_ref (bytes): The expected resolved ref.
expected_branch (str): The expected resolved branch.
expected_revision (str): The expected resolved revision.
expected_tag (str): The expected resolved tag.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Parameterized test for GitRefSpec resolve with different parameters.
Args:
fetch_pack_result (FetchPackResult): The mocked FetchPackResult object.
refspec_params (dict): Parameters for creating GitRefSpec.
expected_ref (bytes): The expected resolved ref.
expected_branch (str): The expected resolved branch.
expected_revision (str): The expected resolved revision.
expected_tag (str): The expected resolved tag.
"""

Comment on lines +134 to +147
@pytest.mark.parametrize(
"refspec_params, expected_ref, expected_branch, expected_revision, expected_tag",
[
({"branch": "main"}, b"refs/heads/main", "main", None, None),
(
{"revision": "v1.0.0"},
annotated_tag(b"refs/tags/v1.0.0"),
None,
None,
"v1.0.0",
),
({"revision": "abc"}, b"refs/heads/main", None, "abc", None),
],
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicks, but can you update this to pass in GitRefSpec instances as parameters instead? And make sure we cover, branch, revision, tag, ref parameters.

Additionally, if we can move to using real(ish) short and full shas instead would help with reasoning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And resolution should verify that shart shas when it exists in the fetch pack gets resolved to full shas. So, abc must resolve to abc123 from the fixture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants