Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add more test and fix pytest warnings
  • Loading branch information
shenxianpeng committed Oct 28, 2025
commit 997feb4146c5bb24b966e1bd797e6b7f3a23f28c
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ exclude_also = [
"__name__",
"FileNotFoundError"
]

[tool.pytest.ini_options]
markers = [
"benchmark: mark test as a benchmark test"
]
40 changes: 40 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import sys

from cpp_linter_hooks import util
from cpp_linter_hooks.util import (
get_version_from_dependency,
_resolve_version,
Expand Down Expand Up @@ -278,3 +279,42 @@ def test_resolve_install_with_none_default_version():

# Should fallback to hardcoded version when DEFAULT is None
mock_install.assert_called_once_with("clang-format", None)


@pytest.mark.benchmark
def test_main_success(monkeypatch):
# Patch _resolve_install to simulate success
monkeypatch.setattr(
"cpp_linter_hooks.util._resolve_install",
lambda tool, version: "/usr/bin/clang-format",
)
monkeypatch.setattr(
sys, "argv", ["util.py", "--tool", "clang-format", "--version", "15.0.7"]
)
exit_code = util.main()
assert exit_code == 0


@pytest.mark.benchmark
def test_main_failure(monkeypatch):
# Patch _resolve_install to simulate failure
monkeypatch.setattr(
"cpp_linter_hooks.util._resolve_install", lambda tool, version: None
)
monkeypatch.setattr(
sys, "argv", ["util.py", "--tool", "clang-format", "--version", "99.99.99"]
)
exit_code = util.main()
assert exit_code == 1


@pytest.mark.benchmark
def test_main_default_tool(monkeypatch):
# Patch _resolve_install to simulate success for default tool
monkeypatch.setattr(
"cpp_linter_hooks.util._resolve_install",
lambda tool, version: "/usr/bin/clang-format",
)
monkeypatch.setattr(sys, "argv", ["util.py"])
exit_code = util.main()
assert exit_code == 0
Loading