Skip to content

Commit 207249b

Browse files
shenxianpeng2bndy5
authored andcommitted
fix: update test
adjust tests for `subprocess.run()`
1 parent 7b269b4 commit 207249b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/test_util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,16 @@ def test_install_tool_success():
124124
mock_path = "/usr/bin/clang-format"
125125

126126
with (
127-
patch("subprocess.check_call") as mock_check_call,
127+
patch("subprocess.run") as mock_run,
128128
patch("shutil.which", return_value=mock_path),
129129
):
130130
result = _install_tool("clang-format", "20.1.7")
131131
assert result == mock_path
132132

133-
mock_check_call.assert_called_once_with(
133+
mock_run.assert_called_once_with(
134134
[sys.executable, "-m", "pip", "install", "clang-format==20.1.7"],
135-
stdout=subprocess.DEVNULL,
136-
stderr=subprocess.DEVNULL,
135+
capture_output=True,
136+
check=True,
137137
)
138138

139139

@@ -142,7 +142,7 @@ def test_install_tool_failure():
142142
"""Test _install_tool when pip install fails."""
143143
with (
144144
patch(
145-
"subprocess.check_call",
145+
"subprocess.run",
146146
side_effect=subprocess.CalledProcessError(1, ["pip"]),
147147
),
148148
patch("cpp_linter_hooks.util.LOG"),
@@ -154,7 +154,7 @@ def test_install_tool_failure():
154154
@pytest.mark.benchmark
155155
def test_install_tool_success_but_not_found():
156156
"""Test _install_tool when install succeeds but tool not found in PATH."""
157-
with patch("subprocess.check_call"), patch("shutil.which", return_value=None):
157+
with patch("subprocess.run"), patch("shutil.which", return_value=None):
158158
result = _install_tool("clang-format", "20.1.7")
159159
assert result is None
160160

0 commit comments

Comments
 (0)