MCPcopy
hub / github.com/openai/openai-python / test_parse_nothing

Function test_parse_nothing

tests/lib/chat/test_completions.py:32–93  ·  view source on GitHub ↗
(client: OpenAI, respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch)

Source from the content-addressed store, hash-verified

30
31@pytest.mark.respx(base_url=base_url)
32def test_parse_nothing(client: OpenAI, respx_mock: MockRouter, monkeypatch: pytest.MonkeyPatch) -> None:
33 completion = make_snapshot_request(
34 lambda c: c.chat.completions.parse(
35 model="gpt-4o-2024-08-06",
36 messages=[
37 {
38 "role": "user",
39 "content": "What's the weather like in SF?",
40 },
41 ],
42 ),
43 content_snapshot=snapshot(
44 '{"id": "chatcmpl-ABfvaueLEMLNYbT8YzpJxsmiQ6HSY", "object": "chat.completion", "created": 1727346142, "model": "gpt-4o-2024-08-06", "choices": [{"index": 0, "message": {"role": "assistant", "content": "I\'m unable to provide real-time weather updates. To get the current weather in San Francisco, I recommend checking a reliable weather website or app like the Weather Channel or a local news station.", "refusal": null}, "logprobs": null, "finish_reason": "stop"}], "usage": {"prompt_tokens": 14, "completion_tokens": 37, "total_tokens": 51, "completion_tokens_details": {"reasoning_tokens": 0}}, "system_fingerprint": "fp_b40fb1c6fb"}'
45 ),
46 path="/chat/completions",
47 mock_client=client,
48 respx_mock=respx_mock,
49 )
50
51 assert print_obj(completion, monkeypatch) == snapshot(
52 """\
53ParsedChatCompletion(
54 choices=[
55 ParsedChoice(
56 finish_reason='stop',
57 index=0,
58 logprobs=None,
59 message=ParsedChatCompletionMessage(
60 annotations=None,
61 audio=None,
62 content="I'm unable to provide real-time weather updates. To get the current weather in San Francisco, I
63recommend checking a reliable weather website or app like the Weather Channel or a local news station.",
64 function_call=None,
65 parsed=None,
66 refusal=None,
67 role='assistant',
68 tool_calls=None
69 )
70 )
71 ],
72 created=1727346142,
73 id='chatcmpl-ABfvaueLEMLNYbT8YzpJxsmiQ6HSY',
74 model='gpt-4o-2024-08-06',
75 moderation=None,
76 object='chat.completion',
77 service_tier=None,
78 system_fingerprint='fp_b40fb1c6fb',
79 usage=CompletionUsage(
80 completion_tokens=37,
81 completion_tokens_details=CompletionTokensDetails(
82 accepted_prediction_tokens=None,
83 audio_tokens=None,
84 reasoning_tokens=0,
85 rejected_prediction_tokens=None
86 ),
87 prompt_tokens=14,
88 prompt_tokens_details=None,
89 total_tokens=51

Callers

nothing calls this directly

Calls 3

make_snapshot_requestFunction · 0.85
print_objFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected