|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import signal |
| 4 | +import tempfile |
4 | 5 | import unittest |
5 | 6 | from pathlib import PosixPath |
6 | 7 | from types import SimpleNamespace |
@@ -128,31 +129,25 @@ def test_terminate_pid_windows_include_group_uses_taskkill_tree(self) -> None: |
128 | 129 | def test_resolve_subprocess_executable_searches_common_windows_user_bin_dirs(self) -> None: |
129 | 130 | from cccc.util import process as process_utils |
130 | 131 |
|
131 | | - target = PosixPath("/tmp/tester/.local/bin/kimi.exe") |
132 | | - |
133 | | - def _exists(path_obj) -> bool: |
134 | | - return str(path_obj) == str(target) |
135 | | - |
136 | | - with patch.object(process_utils.os, "name", "nt"), patch.object( |
137 | | - process_utils.shutil, |
138 | | - "which", |
139 | | - return_value=None, |
140 | | - ), patch.object( |
141 | | - process_utils, |
142 | | - "_iter_windows_user_bin_dirs", |
143 | | - return_value=[PosixPath("/tmp/tester/.local/bin")], |
144 | | - ), patch.object( |
145 | | - process_utils, |
146 | | - "_windows_command_name_candidates", |
147 | | - return_value=["kimi.exe"], |
148 | | - ), patch.object( |
149 | | - process_utils.Path, |
150 | | - "exists", |
151 | | - autospec=True, |
152 | | - side_effect=_exists, |
153 | | - create=True, |
154 | | - ): |
155 | | - resolved = process_utils.resolve_subprocess_executable("kimi") |
| 132 | + with tempfile.TemporaryDirectory() as td: |
| 133 | + base = PosixPath(td) |
| 134 | + target = base / "kimi.exe" |
| 135 | + target.write_text("", encoding="utf-8") |
| 136 | + |
| 137 | + with patch.object(process_utils.os, "name", "nt"), patch.object( |
| 138 | + process_utils.shutil, |
| 139 | + "which", |
| 140 | + return_value=None, |
| 141 | + ), patch.object( |
| 142 | + process_utils, |
| 143 | + "_iter_windows_user_bin_dirs", |
| 144 | + return_value=[base], |
| 145 | + ), patch.object( |
| 146 | + process_utils, |
| 147 | + "_windows_command_name_candidates", |
| 148 | + return_value=["kimi.exe"], |
| 149 | + ): |
| 150 | + resolved = process_utils.resolve_subprocess_executable("kimi") |
156 | 151 |
|
157 | 152 | self.assertEqual(resolved, str(target)) |
158 | 153 |
|
|
0 commit comments