Skip to content

Commit 997feb4

Browse files
committed
feat: add more test and fix pytest warnings
1 parent 33aeacc commit 997feb4

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ exclude_also = [
8080
"__name__",
8181
"FileNotFoundError"
8282
]
83+
84+
[tool.pytest.ini_options]
85+
markers = [
86+
"benchmark: mark test as a benchmark test"
87+
]

tests/test_util.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import sys
66

7+
from cpp_linter_hooks import util
78
from cpp_linter_hooks.util import (
89
get_version_from_dependency,
910
_resolve_version,
@@ -278,3 +279,42 @@ def test_resolve_install_with_none_default_version():
278279

279280
# Should fallback to hardcoded version when DEFAULT is None
280281
mock_install.assert_called_once_with("clang-format", None)
282+
283+
284+
@pytest.mark.benchmark
285+
def test_main_success(monkeypatch):
286+
# Patch _resolve_install to simulate success
287+
monkeypatch.setattr(
288+
"cpp_linter_hooks.util._resolve_install",
289+
lambda tool, version: "/usr/bin/clang-format",
290+
)
291+
monkeypatch.setattr(
292+
sys, "argv", ["util.py", "--tool", "clang-format", "--version", "15.0.7"]
293+
)
294+
exit_code = util.main()
295+
assert exit_code == 0
296+
297+
298+
@pytest.mark.benchmark
299+
def test_main_failure(monkeypatch):
300+
# Patch _resolve_install to simulate failure
301+
monkeypatch.setattr(
302+
"cpp_linter_hooks.util._resolve_install", lambda tool, version: None
303+
)
304+
monkeypatch.setattr(
305+
sys, "argv", ["util.py", "--tool", "clang-format", "--version", "99.99.99"]
306+
)
307+
exit_code = util.main()
308+
assert exit_code == 1
309+
310+
311+
@pytest.mark.benchmark
312+
def test_main_default_tool(monkeypatch):
313+
# Patch _resolve_install to simulate success for default tool
314+
monkeypatch.setattr(
315+
"cpp_linter_hooks.util._resolve_install",
316+
lambda tool, version: "/usr/bin/clang-format",
317+
)
318+
monkeypatch.setattr(sys, "argv", ["util.py"])
319+
exit_code = util.main()
320+
assert exit_code == 0

0 commit comments

Comments
 (0)