Skip to content

Commit cfbb866

Browse files
committed
fmt
1 parent 8ab0c0f commit cfbb866

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

tests/mock_server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,10 +1265,11 @@ async def dynamic_path_generation(
12651265

12661266
try:
12671267
payload = await request.json()
1268-
payload["model"] = model_path
1269-
body = GenerationRequest(**payload)
12701268
except Exception as e:
1271-
raise HTTPException(status_code=400, detail=f"Invalid Request: {e}")
1269+
raise HTTPException(status_code=400, detail=f"Invalid JSON: {e}")
1270+
1271+
payload["model"] = model_path
1272+
body = GenerationRequest(**payload)
12721273

12731274
accept_header = request.headers.get("accept", "")
12741275
dashscope_sse = request.headers.get("x-dashscope-sse", "").lower()

tests/test_doc.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@
4949

5050
# --- HELPERS ---
5151

52+
5253
@dataclass
5354
class SSEFrame:
5455
"""Formal representation of a Server-Sent Event frame for validation."""
56+
5557
id: str
5658
output: Dict[str, Any]
5759
usage: Dict[str, Any]
5860
request_id: str
5961

62+
6063
def parse_sse_stream(response: requests.Response) -> Generator[SSEFrame, None, None]:
6164
"""Parses the raw SSE stream."""
6265
for line in response.iter_lines():
@@ -67,14 +70,17 @@ def parse_sse_stream(response: requests.Response) -> Generator[SSEFrame, None, N
6770
try:
6871
data = json.loads(json_str)
6972
yield SSEFrame(
70-
id=data.get("output", {}).get("choices", [{}])[0].get("id", "unknown"),
73+
id=data.get("output", {})
74+
.get("choices", [{}])[0]
75+
.get("id", "unknown"),
7176
output=data.get("output", {}),
7277
usage=data.get("usage", {}),
7378
request_id=data.get("request_id", ""),
7479
)
7580
except json.JSONDecodeError:
7681
continue
7782

83+
7884
def make_request(payload: Dict[str, Any]):
7985
"""
8086
Helper to send POST request using the Dynamic Path URL.
@@ -85,7 +91,9 @@ def make_request(payload: Dict[str, Any]):
8591
model_path = payload.get("model")
8692

8793
if not model_path:
88-
raise ValueError("Payload must contain 'model' field for dynamic URL construction")
94+
raise ValueError(
95+
"Payload must contain 'model' field for dynamic URL construction"
96+
)
8997

9098
# 构建动态 URL
9199
# 例如: http://localhost:8000/siliconflow/models/pre-siliconflow/deepseek-v3
@@ -97,6 +105,7 @@ def make_request(payload: Dict[str, Any]):
97105

98106
# --- TEST SUITE ---
99107

108+
100109
class TestParameterValidation:
101110
"""
102111
对应表格中参数校验相关的错误用例 (4xx Error Codes)
@@ -115,11 +124,15 @@ def test_invalid_parameter_type_top_p(self):
115124
response = make_request(payload)
116125

117126
# 验证状态码不应为 500
118-
assert response.status_code != 500, "Should not return 500 for invalid parameter type"
127+
assert (
128+
response.status_code != 500
129+
), "Should not return 500 for invalid parameter type"
119130
assert response.status_code == 400
120131

121132
data = response.json()
122-
assert "InvalidParameter" in data.get("code", "") or "InvalidParameter" in data.get("message", "")
133+
assert "InvalidParameter" in data.get(
134+
"code", ""
135+
) or "InvalidParameter" in data.get("message", "")
123136

124137
@pytest.mark.parametrize("top_p_value", [0, 0.0])
125138
def test_invalid_parameter_range_top_p(self, top_p_value):
@@ -184,7 +197,9 @@ def test_r1_usage_structure(self):
184197
# 验证 output_tokens_details 存在
185198
assert output_details, "output_tokens_details missing"
186199
# 验证不包含 text_tokens (根据表格描述这是预期行为)
187-
assert "text_tokens" not in output_details, "R1 usage should not contain text_tokens"
200+
assert (
201+
"text_tokens" not in output_details
202+
), "R1 usage should not contain text_tokens"
188203
# 验证包含 reasoning_tokens
189204
assert "reasoning_tokens" in output_details
190205

@@ -230,7 +245,9 @@ def test_prefix_completion_thinking_conflict(self):
230245

231246
assert response.status_code == 400
232247
data = response.json()
233-
assert "Partial mode is not supported when enable_thinking is true" in data.get("message", "")
248+
assert "Partial mode is not supported when enable_thinking is true" in data.get(
249+
"message", ""
250+
)
234251

235252
def test_history_with_tool_calls(self):
236253
"""
@@ -271,7 +288,9 @@ def test_history_with_tool_calls(self):
271288
response = make_request(payload)
272289

273290
# 核心验证:不能崩 (500)
274-
assert response.status_code != 500, "Server returned 500 for history with tool calls"
291+
assert (
292+
response.status_code != 500
293+
), "Server returned 500 for history with tool calls"
275294
assert response.status_code == 200
276295

277296
def test_r1_tool_call_format_wrapping(self):

0 commit comments

Comments
 (0)