Skip to content

Commit 2a96fdf

Browse files
2bndy5shenxianpeng
authored andcommitted
AI review changes
1 parent 1534871 commit 2a96fdf

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cpp_linter_hooks/util.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ def parse_version(v: str):
6060

6161

6262
def _install_tool(tool: str, version: str) -> Optional[Path]:
63-
"""Install a tool using pip, suppressing output."""
63+
"""Install a tool using pip, logging output on failure."""
6464
result = subprocess.run(
6565
[sys.executable, "-m", "pip", "install", f"{tool}=={version}"],
6666
capture_output=True,
67+
text=True,
6768
)
6869
if result.returncode == 0:
6970
return shutil.which(tool)
7071
else:
7172
LOG.error("pip failed to install %s %s", tool, version)
72-
LOG.error(result.stdout.decode(encoding="utf-8"))
73-
LOG.error(result.stderr.decode(encoding="utf-8"))
73+
LOG.error(result.stdout)
74+
LOG.error(result.stderr)
7475
return None
7576

7677

tests/test_util.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def patched_run(*args, **kwargs):
136136
mock_run.assert_called_once_with(
137137
[sys.executable, "-m", "pip", "install", "clang-format==20.1.7"],
138138
capture_output=True,
139+
text=True,
139140
)
140141

141142

@@ -145,7 +146,7 @@ def test_install_tool_failure():
145146

146147
def patched_run(*args, **kwargs):
147148
return subprocess.CompletedProcess(
148-
args, returncode=1, stderr=b"Error", stdout=b"Installation failed"
149+
args, returncode=1, stderr="Error", stdout="Installation failed"
149150
)
150151

151152
with (
@@ -159,7 +160,14 @@ def patched_run(*args, **kwargs):
159160
@pytest.mark.benchmark
160161
def test_install_tool_success_but_not_found():
161162
"""Test _install_tool when install succeeds but tool not found in PATH."""
162-
with patch("subprocess.run"), patch("shutil.which", return_value=None):
163+
164+
def patched_run(*args, **kwargs):
165+
return subprocess.CompletedProcess(args, returncode=0)
166+
167+
with (
168+
patch("subprocess.run", side_effect=patched_run),
169+
patch("shutil.which", return_value=None),
170+
):
163171
result = _install_tool("clang-format", "20.1.7")
164172
assert result is None
165173

0 commit comments

Comments
 (0)