Skip to content

Commit 61d0c52

Browse files
Theodor N. EngøyTheodor N. Engøy
authored andcommitted
tests: type annotate fake shutil.which for pyright
1 parent 4d28f14 commit 61d0c52

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/cli/test_utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ def test_get_npx_windows(monkeypatch: pytest.MonkeyPatch):
7878
import shutil
7979

8080
monkeypatch.setattr(sys, "platform", "win32")
81-
monkeypatch.setattr(shutil, "which", lambda name: "C:\\bin\\npx.exe" if name == "npx.exe" else None)
81+
82+
def fake_which(name: str) -> str | None:
83+
return "C:\\bin\\npx.exe" if name == "npx.exe" else None
84+
85+
monkeypatch.setattr(shutil, "which", fake_which)
8286
assert _get_npx_command() == ["C:\\bin\\npx.exe"]
8387

8488

@@ -88,7 +92,11 @@ def test_get_npx_windows_cmd_wrapper(monkeypatch: pytest.MonkeyPatch):
8892

8993
monkeypatch.setattr(sys, "platform", "win32")
9094
monkeypatch.setenv("COMSPEC", "cmd.exe")
91-
monkeypatch.setattr(shutil, "which", lambda name: "C:\\bin\\npx.cmd" if name == "npx.cmd" else None)
95+
96+
def fake_which(name: str) -> str | None:
97+
return "C:\\bin\\npx.cmd" if name == "npx.cmd" else None
98+
99+
monkeypatch.setattr(shutil, "which", fake_which)
92100

93101
assert _get_npx_command() == ["cmd.exe", "/c", "C:\\bin\\npx.cmd"]
94102

@@ -98,5 +106,8 @@ def test_get_npx_returns_none_when_npx_missing(monkeypatch: pytest.MonkeyPatch):
98106
monkeypatch.setattr(sys, "platform", "win32", raising=False)
99107
import shutil
100108

101-
monkeypatch.setattr(shutil, "which", lambda name: None)
109+
def fake_which(name: str) -> str | None:
110+
return None
111+
112+
monkeypatch.setattr(shutil, "which", fake_which)
102113
assert _get_npx_command() is None

0 commit comments

Comments
 (0)