[CI][RFC] Replace black-jupyter with ruff-format (#37210)
Co-authored-by: Alison Shao <a.shao@wustl.edu>
This commit is contained in:
co-authored by
Alison Shao
parent
2641e427be
commit
28262c20df
@@ -194,9 +194,9 @@ def _direct_warm(worker_url: str, model_id: str, prefix: str) -> None:
|
||||
},
|
||||
timeout=60.0,
|
||||
)
|
||||
assert (
|
||||
r.status_code == 200
|
||||
), f"direct warm to {worker_url} failed: HTTP {r.status_code} {r.text!r}"
|
||||
assert r.status_code == 200, (
|
||||
f"direct warm to {worker_url} failed: HTTP {r.status_code} {r.text!r}"
|
||||
)
|
||||
|
||||
|
||||
def _route_through(router_url: str, model_id: str, prompt: str) -> str:
|
||||
@@ -212,9 +212,9 @@ def _route_through(router_url: str, model_id: str, prompt: str) -> str:
|
||||
after = _success_counts_by_worker(router_url)
|
||||
deltas = {w: after.get(w, 0) - before.get(w, 0) for w in set(after) | set(before)}
|
||||
winners = [w for w, d in deltas.items() if d > 0]
|
||||
assert (
|
||||
len(winners) == 1
|
||||
), f"expected exactly one worker delta on {router_url}, got {deltas}"
|
||||
assert len(winners) == 1, (
|
||||
f"expected exactly one worker delta on {router_url}, got {deltas}"
|
||||
)
|
||||
return winners[0]
|
||||
|
||||
|
||||
@@ -309,15 +309,15 @@ def test_routers_route_by_prefix_content(
|
||||
landed = _route_through(
|
||||
router.base_url, spec["model"], PREFIX_X
|
||||
)
|
||||
assert (
|
||||
landed == worker_x.url
|
||||
), f"router {label}: PREFIX_X must route to {worker_x.url}; landed on {landed}"
|
||||
assert landed == worker_x.url, (
|
||||
f"router {label}: PREFIX_X must route to {worker_x.url}; landed on {landed}"
|
||||
)
|
||||
landed = _route_through(
|
||||
router.base_url, spec["model"], PREFIX_Y
|
||||
)
|
||||
assert (
|
||||
landed == worker_y.url
|
||||
), f"router {label}: PREFIX_Y must route to {worker_y.url}; landed on {landed}"
|
||||
assert landed == worker_y.url, (
|
||||
f"router {label}: PREFIX_Y must route to {worker_y.url}; landed on {landed}"
|
||||
)
|
||||
except Exception:
|
||||
_dump_logs(logs)
|
||||
raise
|
||||
|
||||
@@ -50,9 +50,9 @@ def test_chat_non_streaming_returns_assistant_message(
|
||||
body = resp.json()
|
||||
choice = body["choices"][0]
|
||||
assert choice["message"]["role"] == "assistant"
|
||||
assert choice["message"][
|
||||
"content"
|
||||
], f"empty assistant content: {choice!r}"
|
||||
assert choice["message"]["content"], (
|
||||
f"empty assistant content: {choice!r}"
|
||||
)
|
||||
assert choice.get("finish_reason"), choice
|
||||
finally:
|
||||
gpu_allocator.release(gpu)
|
||||
@@ -91,8 +91,8 @@ def test_chat_streaming_emits_sse_chunks_with_done(
|
||||
if line.startswith("data:"):
|
||||
chunks.append(line.strip())
|
||||
assert len(chunks) >= 2, f"expected >=2 SSE chunks, got: {chunks}"
|
||||
assert any(
|
||||
"[DONE]" in c for c in chunks
|
||||
), f"no [DONE] terminator in stream: {chunks}"
|
||||
assert any("[DONE]" in c for c in chunks), (
|
||||
f"no [DONE] terminator in stream: {chunks}"
|
||||
)
|
||||
finally:
|
||||
gpu_allocator.release(gpu)
|
||||
|
||||
@@ -66,15 +66,17 @@ def test_router_discovers_multiple_workers(router_url):
|
||||
# Scale down to 1 — router should still route after reconverging
|
||||
_scale_fake_worker(1)
|
||||
_poll_until(
|
||||
lambda: httpx.post(
|
||||
f"{router_url}/v1/chat/completions",
|
||||
json={
|
||||
"model": "tiny",
|
||||
"messages": [{"role": "user", "content": "post-scale-down"}],
|
||||
},
|
||||
timeout=10.0,
|
||||
).status_code
|
||||
== 200,
|
||||
lambda: (
|
||||
httpx.post(
|
||||
f"{router_url}/v1/chat/completions",
|
||||
json={
|
||||
"model": "tiny",
|
||||
"messages": [{"role": "user", "content": "post-scale-down"}],
|
||||
},
|
||||
timeout=10.0,
|
||||
).status_code
|
||||
== 200
|
||||
),
|
||||
"router routes after scale-down to 1",
|
||||
timeout=60,
|
||||
interval=3,
|
||||
|
||||
@@ -16,9 +16,9 @@ def test_models(router: str) -> None:
|
||||
assert resp.status_code == 200, resp.text
|
||||
data = resp.json()
|
||||
ids = [m["id"] for m in data.get("data", [])]
|
||||
assert any(
|
||||
MODEL in mid for mid in ids
|
||||
), f"Model {MODEL!r} not found in /v1/models response: {ids}"
|
||||
assert any(MODEL in mid for mid in ids), (
|
||||
f"Model {MODEL!r} not found in /v1/models response: {ids}"
|
||||
)
|
||||
|
||||
|
||||
def test_chat_non_streaming(router: str) -> None:
|
||||
@@ -59,6 +59,6 @@ def test_chat_streaming(router: str) -> None:
|
||||
chunks.append(line)
|
||||
|
||||
assert len(chunks) >= 2, f"Expected >=2 SSE chunks, got {len(chunks)}: {chunks}"
|
||||
assert any(
|
||||
"[DONE]" in c for c in chunks
|
||||
), f"No [DONE] chunk found in SSE stream: {chunks}"
|
||||
assert any("[DONE]" in c for c in chunks), (
|
||||
f"No [DONE] chunk found in SSE stream: {chunks}"
|
||||
)
|
||||
|
||||
@@ -20,9 +20,9 @@ def test_tokenize_round_trip(router: str) -> None:
|
||||
)
|
||||
assert tok_resp.status_code == 200, tok_resp.text
|
||||
tokens = tok_resp.json()["tokens"]
|
||||
assert (
|
||||
isinstance(tokens, list) and len(tokens) > 0
|
||||
), f"Expected non-empty token list, got: {tokens}"
|
||||
assert isinstance(tokens, list) and len(tokens) > 0, (
|
||||
f"Expected non-empty token list, got: {tokens}"
|
||||
)
|
||||
|
||||
# Detokenize
|
||||
detok_resp = httpx.post(
|
||||
@@ -32,6 +32,6 @@ def test_tokenize_round_trip(router: str) -> None:
|
||||
)
|
||||
assert detok_resp.status_code == 200, detok_resp.text
|
||||
recovered = detok_resp.json()["text"]
|
||||
assert (
|
||||
TEXT in recovered or recovered in TEXT
|
||||
), f"Round-trip mismatch: original={TEXT!r}, recovered={recovered!r}"
|
||||
assert TEXT in recovered or recovered in TEXT, (
|
||||
f"Round-trip mismatch: original={TEXT!r}, recovered={recovered!r}"
|
||||
)
|
||||
|
||||
@@ -85,7 +85,7 @@ def load_tokenizer_with_fallback(primary, fallback, slug):
|
||||
raise
|
||||
continue
|
||||
raise RuntimeError(
|
||||
f"No accessible tokenizer for slug={slug} " f"(tried: {primary}, {fallback})"
|
||||
f"No accessible tokenizer for slug={slug} (tried: {primary}, {fallback})"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user