-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
base: main
Are you sure you want to change the base?
Test: vcs.git.backend tests #9507
Conversation
There was a problem hiding this 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
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" |
There was a problem hiding this comment.
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.
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. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | |
""" |
@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), | ||
], | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Pull Request Check List
Relates-to: #3155
poetry.vcs.git.backend
(increased coverage from 30% to 51%)