Skip to content

Commit a855ce0

Browse files
J03D03claude
andcommitted
Modernize tests/utils style and dedupe test_git_url.py
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent fcfe25b commit a855ce0

7 files changed

Lines changed: 92 additions & 220 deletions

File tree

‎tests/utils/test_datasets_utils.py‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,8 @@ def test_resolves_tag_to_commit_sha(self) -> None:
7979
def test_nonexistent_ref_returns_none(self) -> None:
8080
"""Non-existent refs should return None without raising."""
8181
result = _resolve_ref_local("this-tag-does-not-exist-12345", "https://github.com/curl/curl")
82-
# Either None (repo exists, ref not found) or None (repo not cloned)
8382
assert result is None
8483

85-
@pytest.mark.integration
86-
def test_invalid_repo_directory_returns_none(self, tmp_path: pytest.TempPathFactory) -> None:
87-
"""Return None when the repo path exists but is not a valid git repo."""
88-
# _resolve_ref_local checks url_to_pathname, so we can't easily point it
89-
# at tmp_path. Instead, verify it handles InvalidGitRepositoryError gracefully
90-
# by testing with a URL whose local path doesn't contain a valid repo.
91-
assert _resolve_ref_local("main", "https://github.com/nonexistent/repo-xyz-999") is None
92-
9384

9485
class TestResolveSymbolicRef:
9586
"""Tests for _resolve_symbolic_ref function."""
@@ -105,14 +96,9 @@ def test_resolves_curl_tag_to_commit_sha(self) -> None:
10596
This tests both the API call logic AND the SHA normalization (lowercase).
10697
"""
10798
sha = _resolve_symbolic_ref("curl-7_50_0", "https://github.com/curl/curl")
108-
109-
# Known stable commit for curl-7_50_0 tag
110-
expected_sha = "79e63a53bb9598af863b0afe49ad662795faeef4"
111-
112-
if sha:
113-
assert sha == expected_sha, f"Expected {expected_sha}, got {sha}"
114-
else:
99+
if sha is None:
115100
pytest.skip("Could not resolve (no local repo and API unavailable)")
101+
assert sha == "79e63a53bb9598af863b0afe49ad662795faeef4"
116102

117103
@pytest.mark.integration
118104
def test_nonexistent_ref_returns_none(self) -> None:

‎tests/utils/test_extensions.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55

66
class TestExtensionsFor:
7-
def test_single_language(self):
7+
def test_single_language(self) -> None:
88
exts = extensions_for("python")
99
assert ".py" in exts
1010
assert ".pyw" in exts
1111

12-
def test_multiple_languages(self):
12+
def test_multiple_languages(self) -> None:
1313
exts = extensions_for("c", "cpp")
1414
assert ".c" in exts
1515
assert ".cpp" in exts
1616
assert ".h" in exts
1717

18-
def test_unknown_language_returns_empty(self):
18+
def test_unknown_language_returns_empty(self) -> None:
1919
assert extensions_for("fortran") == set()
2020

21-
def test_all_extensions_map_to_known_language(self):
21+
def test_all_extensions_map_to_known_language(self) -> None:
2222
for ext, lang in EXTENSION_TO_LANGUAGE.items():
2323
assert ext in extensions_for(lang)

‎tests/utils/test_git_repository_strategy.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Tests for CloneStrategy helpers in utils.git.repository."""
22

3-
from __future__ import annotations
4-
53
import shutil
64
from pathlib import Path
75

@@ -43,28 +41,28 @@ def _full_clone(bare: Path, dest: Path) -> Repo:
4341

4442
@pytest.mark.integration
4543
class TestIsPartialClone:
46-
def test_blobless_clone_detected(self, tmp_path):
44+
def test_blobless_clone_detected(self, tmp_path: Path) -> None:
4745
bare = _init_bare_source(tmp_path)
4846
repo = _blobless_clone(bare, tmp_path / "clone")
4947
assert _is_partial_clone(repo) is True
5048

51-
def test_full_clone_not_partial(self, tmp_path):
49+
def test_full_clone_not_partial(self, tmp_path: Path) -> None:
5250
bare = _init_bare_source(tmp_path)
5351
repo = _full_clone(bare, tmp_path / "clone")
5452
assert _is_partial_clone(repo) is False
5553

5654

5755
@pytest.mark.integration
5856
class TestUpgradeToFull:
59-
def test_unsets_filter_config(self, tmp_path):
57+
def test_unsets_filter_config(self, tmp_path: Path) -> None:
6058
bare = _init_bare_source(tmp_path)
6159
repo = _blobless_clone(bare, tmp_path / "clone")
6260
assert _is_partial_clone(repo)
6361

6462
assert _upgrade_to_full(repo, timeout=60) is True
6563
assert not _is_partial_clone(repo)
6664

67-
def test_returns_false_when_remote_gone(self, tmp_path):
65+
def test_returns_false_when_remote_gone(self, tmp_path: Path) -> None:
6866
"""If fetch fails, caller needs False so it can recover."""
6967
bare = _init_bare_source(tmp_path)
7068
repo = _blobless_clone(bare, tmp_path / "clone")

0 commit comments

Comments
 (0)