Skip to content

Commit 3dc3ae5

Browse files
committed
Simplify test back to original pattern
1 parent 93aba65 commit 3dc3ae5

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tools/server/tests/unit/test_chat_completion.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,18 @@ def test_apply_chat_template():
171171
assert res.body["prompt"] == "<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>You are a test.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hi there<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
172172

173173

174-
@pytest.mark.parametrize("response_format,n_predicted,re_content,expected_status_code", [
175-
({"type": "json_object", "schema": {"const": "42"}}, 6, "\"42\"", 200),
176-
({"type": "json_object", "schema": {"items": [{"type": "integer"}]}}, 10, "[ -3000 ]", 200),
177-
({"type": "json_schema", "json_schema": {"schema": {"const": "foooooo"}}}, 10, "\"foooooo\"", 200),
178-
({"type": "json_object"}, 10, "(\\{|John)+", 200),
179-
({"type": "sound"}, 0, None, 400),
174+
@pytest.mark.parametrize("response_format,n_predicted,re_content", [
175+
({"type": "json_object", "schema": {"const": "42"}}, 6, "\"42\""),
176+
({"type": "json_object", "schema": {"items": [{"type": "integer"}]}}, 10, "[ -3000 ]"),
177+
({"type": "json_schema", "json_schema": {"schema": {"const": "foooooo"}}}, 10, "\"foooooo\""),
178+
({"type": "json_object"}, 10, "(\\{|John)+"),
179+
({"type": "sound"}, 0, None),
180180
# invalid response format (expected to fail)
181-
({"type": "json_object", "schema": 123}, 0, None, 400),
182-
({"type": "json_object", "schema": {"type": 123}}, 0, None, 400),
183-
({"type": "json_object", "schema": {"type": "hiccup"}}, 0, None, 400),
181+
({"type": "json_object", "schema": 123}, 0, None),
182+
({"type": "json_object", "schema": {"type": 123}}, 0, None),
183+
({"type": "json_object", "schema": {"type": "hiccup"}}, 0, None),
184184
])
185-
def test_completion_with_response_format(response_format: dict, n_predicted: int, re_content: str | None, expected_status_code: int):
185+
def test_completion_with_response_format(response_format: dict, n_predicted: int, re_content: str | None):
186186
global server
187187
server.start()
188188
res = server.make_request("POST", "/chat/completions", data={
@@ -193,11 +193,12 @@ def test_completion_with_response_format(response_format: dict, n_predicted: int
193193
],
194194
"response_format": response_format,
195195
})
196-
assert res.status_code == expected_status_code
197196
if re_content is not None:
197+
assert res.status_code == 200
198198
choice = res.body["choices"][0]
199199
assert match_regex(re_content, choice["message"]["content"])
200200
else:
201+
assert res.status_code == 400
201202
assert "error" in res.body
202203

203204

0 commit comments

Comments
 (0)