Skip to content

Commit e4a0850

Browse files
committed
Fix local server test typing for lint
1 parent dd3124d commit e4a0850

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

tests/test_local_server.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
import json
45
from pathlib import Path
56

@@ -85,10 +86,27 @@ def _fake_popen(
8586
captured_env.update(env)
8687
return _DummyProcess()
8788

88-
monkeypatch.setattr(sea_server, "_pick_free_port", lambda _host: port)
89-
monkeypatch.setattr(sea_server, "_terminate_process", lambda proc: setattr(proc, "_returncode", 0))
90-
monkeypatch.setattr(sea_server, "_wait_ready_sync", lambda **_kwargs: None)
91-
monkeypatch.setattr(sea_server, "resolve_binary_path", lambda **_kwargs: binary_path)
89+
def _fake_pick_free_port(_host: str) -> int:
90+
return port
91+
92+
def _fake_terminate_process(proc: _DummyProcess) -> None:
93+
proc._returncode = 0
94+
95+
def _fake_wait_ready_sync(*, base_url: str, timeout_s: float) -> None:
96+
del base_url, timeout_s
97+
98+
def _fake_resolve_binary_path(
99+
*,
100+
_local_stagehand_binary_path: str | os.PathLike[str] | None = None,
101+
version: str | None = None,
102+
) -> Path:
103+
del _local_stagehand_binary_path, version
104+
return binary_path
105+
106+
monkeypatch.setattr(sea_server, "_pick_free_port", _fake_pick_free_port)
107+
monkeypatch.setattr(sea_server, "_terminate_process", _fake_terminate_process)
108+
monkeypatch.setattr(sea_server, "_wait_ready_sync", _fake_wait_ready_sync)
109+
monkeypatch.setattr(sea_server, "resolve_binary_path", _fake_resolve_binary_path)
92110
monkeypatch.setattr(sea_server.subprocess, "Popen", _fake_popen)
93111

94112

@@ -271,14 +289,17 @@ def test_local_mode_masks_inherited_model_api_key_envs_and_prefers_explicit_para
271289
captured_env: dict[str, str] = {}
272290
_install_fake_sea_runtime(monkeypatch, tmp_path, captured_env, port=43129)
273291

274-
client_kwargs: dict[str, object] = {
275-
"server": "local",
276-
"_local_stagehand_binary_path": "/does/not/matter/in/test",
277-
}
278-
if explicit_model_api_key is not None:
279-
client_kwargs["model_api_key"] = explicit_model_api_key
280-
281-
client = Stagehand(**client_kwargs)
292+
if explicit_model_api_key is None:
293+
client = Stagehand(
294+
server="local",
295+
_local_stagehand_binary_path="/does/not/matter/in/test",
296+
)
297+
else:
298+
client = Stagehand(
299+
server="local",
300+
model_api_key=explicit_model_api_key,
301+
_local_stagehand_binary_path="/does/not/matter/in/test",
302+
)
282303
assert client._sea_server is not None
283304

284305
client._sea_server.ensure_running_sync()

0 commit comments

Comments
 (0)