Skip to content

Commit 009ac7e

Browse files
committed
fix(process): tolerate mocked windows path resolution
1 parent b96d16a commit 009ac7e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/cccc/util/process.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ def find_subprocess_executable(command: str) -> Optional[str]:
3131
except Exception:
3232
return str(resolved)
3333

34-
path = Path(raw)
35-
if path.exists():
34+
try:
35+
path = Path(raw)
36+
except Exception:
37+
path = None
38+
if path is not None and path.exists():
3639
try:
3740
return str(path.resolve())
3841
except Exception:

tests/test_process_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ def test_resolve_subprocess_executable_searches_common_windows_user_bin_dirs(sel
133133
base = PosixPath(td)
134134
target = base / "kimi.exe"
135135
target.write_text("", encoding="utf-8")
136+
original_path = process_utils.Path
137+
138+
def _path_factory(value):
139+
if value == "kimi":
140+
raise NotImplementedError("cannot instantiate 'WindowsPath' on your system")
141+
return original_path(value)
136142

137143
with patch.object(process_utils.os, "name", "nt"), patch.object(
138144
process_utils.shutil,
@@ -146,6 +152,10 @@ def test_resolve_subprocess_executable_searches_common_windows_user_bin_dirs(sel
146152
process_utils,
147153
"_windows_command_name_candidates",
148154
return_value=["kimi.exe"],
155+
), patch.object(
156+
process_utils,
157+
"Path",
158+
side_effect=_path_factory,
149159
):
150160
resolved = process_utils.resolve_subprocess_executable("kimi")
151161

0 commit comments

Comments
 (0)