@@ -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" , [
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 ),
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 , 500 ),
180180 # invalid response format (expected to fail)
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 ),
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 ),
184184])
185- def test_completion_with_response_format (response_format : dict , n_predicted : int , re_content : str | None ):
185+ def test_completion_with_response_format (response_format : dict , n_predicted : int , re_content : str | None , expected_status_code : int ):
186186 global server
187187 server .start ()
188188 res = server .make_request ("POST" , "/chat/completions" , data = {
@@ -193,12 +193,11 @@ 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
196197 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 != 200
202201 assert "error" in res .body
203202
204203
0 commit comments