Skip to content

Commit 25ccc0b

Browse files
committed
fix: update tests
1 parent 0dc7ff7 commit 25ccc0b

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

cpp_linter_hooks/util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
2626
for dep in requires:
2727
if dep.startswith(f"{tool}=="):
2828
return dep.split("==")[1]
29+
30+
# Check project.dependencies
31+
dependencies = data.get("project", {}).get("dependencies", [])
32+
for dep in dependencies:
33+
if dep.startswith(f"{tool}=="):
34+
return dep.split("==")[1]
35+
36+
# Check project.optional-dependencies (all groups)
37+
optional_deps = data.get("project", {}).get("optional-dependencies", {})
38+
for group in optional_deps.values():
39+
for dep in group:
40+
if dep.startswith(f"{tool}=="):
41+
return dep.split("==")[1]
42+
2943
return None
3044

3145

tests/test_util.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
def test_get_version_from_dependency_success():
2626
"""Test get_version_from_dependency with valid pyproject.toml."""
2727
mock_toml_content = {
28-
"project": {
29-
"build-system": {
30-
"requires": [
31-
"clang-format==20.1.7",
32-
"clang-tidy==20.1.0",
33-
"other-package==1.0.0",
34-
]
35-
}
36-
}
28+
"build-system": {
29+
"requires": [
30+
"clang-format==20.1.7",
31+
"clang-tidy==20.1.0",
32+
"other-package==1.0.0",
33+
]
34+
},
35+
"project": {},
3736
}
3837

3938
with (
@@ -176,7 +175,7 @@ def test_resolve_install_tool_already_installed_correct_version():
176175
patch("shutil.which", return_value=mock_path),
177176
):
178177
result = _resolve_install("clang-format", "20.1.7")
179-
assert result == Path(mock_path)
178+
assert Path(result) == Path(mock_path)
180179

181180

182181
@pytest.mark.benchmark

0 commit comments

Comments
 (0)