[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
a9ad8b7703
commit
52d671f3a2
4 changed files with 28 additions and 16 deletions
|
|
@ -937,7 +937,11 @@ def _per_port_records() -> "list[tuple[int, float | None, str | None] | None]":
|
|||
return []
|
||||
|
||||
|
||||
def _resolve_port(host: str, port: int, avoid_own_studio: bool = True) -> int:
|
||||
def _resolve_port(
|
||||
host: str,
|
||||
port: int,
|
||||
avoid_own_studio: bool = True,
|
||||
) -> int:
|
||||
"""The requested port, or the next free one.
|
||||
|
||||
With ``avoid_own_studio`` this aborts rather than falling back past one of our
|
||||
|
|
|
|||
|
|
@ -476,11 +476,14 @@ def test_bind_addresses_keeps_every_family_a_hostname_resolves_to(monkeypatch):
|
|||
# Independent oracle: the sibling test derives its expectation from this
|
||||
# function's own output, so dropping a family would pass it.
|
||||
import socket
|
||||
|
||||
monkeypatch.setattr(socket, "getaddrinfo", lambda *a, **k: [
|
||||
(socket.AF_INET, socket.SOCK_STREAM, 6, "", ("127.0.0.1", 8889)),
|
||||
(socket.AF_INET6, socket.SOCK_STREAM, 6, "", ("::1", 8889, 0, 0)),
|
||||
])
|
||||
monkeypatch.setattr(
|
||||
socket,
|
||||
"getaddrinfo",
|
||||
lambda *a, **k: [
|
||||
(socket.AF_INET, socket.SOCK_STREAM, 6, "", ("127.0.0.1", 8889)),
|
||||
(socket.AF_INET6, socket.SOCK_STREAM, 6, "", ("::1", 8889, 0, 0)),
|
||||
],
|
||||
)
|
||||
|
||||
assert run._bind_addresses("localhost", 8889) == {"127.0.0.1", "::1"}
|
||||
|
||||
|
|
@ -491,8 +494,9 @@ def test_the_legacy_file_is_written_even_when_the_per_port_record_fails(tmp_path
|
|||
# overwrite of an existing path, so it can still succeed and must be tried.
|
||||
blocked = tmp_path / "not-a-directory"
|
||||
blocked.write_text("", encoding = "utf-8")
|
||||
monkeypatch.setattr(run, "_pid_file_for_port",
|
||||
lambda port: blocked / f"studio-{port}-{os.getpid()}.pid")
|
||||
monkeypatch.setattr(
|
||||
run, "_pid_file_for_port", lambda port: blocked / f"studio-{port}-{os.getpid()}.pid"
|
||||
)
|
||||
|
||||
run._write_pid_file(8901, "127.0.0.1")
|
||||
|
||||
|
|
|
|||
|
|
@ -54,12 +54,16 @@ def test_stop_finds_a_pid_file_named_the_way_the_backend_writes_it(tmp_path, mon
|
|||
def test_the_legacy_file_stays_a_bare_pid_an_older_cli_can_parse(tmp_path, monkeypatch):
|
||||
# An older `unsloth studio stop` reads studio.pid and requires str.isdigit(),
|
||||
# so the compatibility file must never gain the extra metadata lines.
|
||||
ns = {"os": os, "Path": Path, "_studio_root": lambda: tmp_path,
|
||||
"_PID_FILE": tmp_path / "studio.pid",
|
||||
"_pid_file_for_port": lambda port: _backend_pid_path(tmp_path, port),
|
||||
"_process_create_time": lambda pid: None,
|
||||
"_bind_addresses": lambda host, port: {host},
|
||||
"_OWN_PID_FILE": None}
|
||||
ns = {
|
||||
"os": os,
|
||||
"Path": Path,
|
||||
"_studio_root": lambda: tmp_path,
|
||||
"_PID_FILE": tmp_path / "studio.pid",
|
||||
"_pid_file_for_port": lambda port: _backend_pid_path(tmp_path, port),
|
||||
"_process_create_time": lambda pid: None,
|
||||
"_bind_addresses": lambda host, port: {host},
|
||||
"_OWN_PID_FILE": None,
|
||||
}
|
||||
exec(_func_source(_RUN_SRC, "_write_pid_file"), ns)
|
||||
ns["_write_pid_file"](8901, "127.0.0.1")
|
||||
|
||||
|
|
|
|||
|
|
@ -453,8 +453,8 @@ def test_stop_keeps_a_record_it_cannot_read(monkeypatch, tmp_path):
|
|||
def test_stop_reaches_every_server_when_one_record_cannot_be_removed(monkeypatch, tmp_path):
|
||||
# One undeletable stale record must not end the loop before the live servers.
|
||||
studio_mod, _live, killed = _install(monkeypatch, tmp_path, alive = {8600})
|
||||
_write_pid(tmp_path, "studio-8901-8550.pid", 8550) # dead -> stop prunes it
|
||||
_write_pid(tmp_path, "studio-8902-8600.pid", 8600) # live -> stop signals it
|
||||
_write_pid(tmp_path, "studio-8901-8550.pid", 8550) # dead -> stop prunes it
|
||||
_write_pid(tmp_path, "studio-8902-8600.pid", 8600) # live -> stop signals it
|
||||
real_unlink = Path.unlink
|
||||
|
||||
def deny(self, *args, **kwargs):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue