"""Tests for the git subprocess wrapper's URL parsing helpers.""" import pytest from byteb4rb1e.utils.vcs.git import parse_base_url, parse_repo_name class TestParseBaseUrl: def test_bitbucket(self) -> None: result = parse_base_url("git@bitbucket.org:byteb4rb1e/foo.git") assert str(result) == "byteb4rb1e" def test_forgejo_host(self) -> None: result = parse_base_url( "git@git.code.tiararodney.com:h5p-mirror/foo.git" ) assert str(result) == "h5p-mirror" def test_github_host(self) -> None: result = parse_base_url("git@github.com:h5p/h5p-multi-choice.git") assert str(result) == "h5p" def test_rejects_https_url(self) -> None: with pytest.raises(ValueError): parse_base_url("https://bitbucket.org/byteb4rb1e/foo.git") def test_rejects_url_without_colon(self) -> None: with pytest.raises(ValueError): parse_base_url("bitbucket.org/byteb4rb1e/foo.git") class TestParseRepoName: def test_bitbucket(self) -> None: assert parse_repo_name( "git@bitbucket.org:byteb4rb1e/foo.git" ) == "foo" def test_forgejo_host(self) -> None: assert parse_repo_name( "git@git.code.tiararodney.com:h5p-mirror/foo.git" ) == "foo" def test_without_git_suffix(self) -> None: assert parse_repo_name( "git@git.code.tiararodney.com:h5p-mirror/foo" ) == "foo" def test_rejects_https_url(self) -> None: with pytest.raises(ValueError): parse_repo_name("https://git.code.tiararodney.com/x/foo.git") def test_rejects_url_without_colon(self) -> None: with pytest.raises(ValueError): parse_repo_name("git.code.tiararodney.com/x/foo.git")