-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: add tests for vcs.git.backend (#9491)
- Loading branch information
1 parent
c90d118
commit d707e4d
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from dulwich.repo import Repo | ||
|
||
from poetry.vcs.git.backend import Git | ||
from poetry.vcs.git.backend import annotated_tag | ||
from poetry.vcs.git.backend import is_revision_sha | ||
from poetry.vcs.git.backend import urlpathjoin | ||
|
||
|
||
VALID_SHA = "c5c7624ef64f34d9f50c3b7e8118f7f652fddbbd" | ||
|
@@ -41,3 +47,31 @@ def test_invalid_revision_sha_max_len() -> None: | |
def test_get_name_from_source_url(url: str) -> None: | ||
name = Git.get_name_from_source_url(url) | ||
assert name == "poetry" | ||
|
||
|
||
@pytest.mark.parametrize(("tag"), ["my-tag", b"my-tag"]) | ||
def test_annotated_tag(tag: str | bytes) -> None: | ||
tag = annotated_tag("my-tag") | ||
assert tag == b"my-tag^{}" | ||
|
||
|
||
def test_get_remote_url() -> None: | ||
repo = MagicMock(spec=Repo) | ||
repo.get_config.return_value.get.return_value = ( | ||
b"https://github.com/python-poetry/poetry.git" | ||
) | ||
|
||
assert Git.get_remote_url(repo) == "https://github.com/python-poetry/poetry.git" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url, expected_result", | ||
[ | ||
("ssh://[email protected]/org/repo", "ssh://[email protected]/other-repo"), | ||
("ssh://[email protected]/org/repo/", "ssh://[email protected]/org/other-repo"), | ||
], | ||
) | ||
def test_urlpathjoin(url: str, expected_result: str) -> None: | ||
path = "../other-repo" | ||
result = urlpathjoin(url, path) | ||
assert result == expected_result |