|
7 | 7 | from inline_snapshot import snapshot |
8 | 8 |
|
9 | 9 | from openai import OpenAI, AsyncOpenAI |
| 10 | +from openai._types import omit |
10 | 11 | from openai._utils import assert_signatures_in_sync |
| 12 | +from openai._models import construct_type_unchecked |
| 13 | +from openai.types.responses import Response |
| 14 | +from openai.lib._parsing._responses import parse_response |
11 | 15 |
|
12 | 16 | from ...conftest import base_url |
13 | 17 | from ..snapshots import make_snapshot_request |
@@ -41,6 +45,38 @@ def test_output_text(client: OpenAI, respx_mock: MockRouter) -> None: |
41 | 45 | ) |
42 | 46 |
|
43 | 47 |
|
| 48 | +def test_parse_response_handles_null_output() -> None: |
| 49 | + response = construct_type_unchecked( |
| 50 | + type_=Response, |
| 51 | + value={ |
| 52 | + "id": "resp_null_output", |
| 53 | + "object": "response", |
| 54 | + "created_at": 1754925861, |
| 55 | + "status": "completed", |
| 56 | + "error": None, |
| 57 | + "incomplete_details": None, |
| 58 | + "instructions": None, |
| 59 | + "max_output_tokens": None, |
| 60 | + "model": "gpt-4o-mini-2024-07-18", |
| 61 | + "output": None, |
| 62 | + "parallel_tool_calls": True, |
| 63 | + "previous_response_id": None, |
| 64 | + "reasoning": {"effort": None, "summary": None}, |
| 65 | + "store": True, |
| 66 | + "temperature": 1.0, |
| 67 | + "text": {"format": {"type": "text"}}, |
| 68 | + "tool_choice": "auto", |
| 69 | + "tools": [], |
| 70 | + "top_p": 1.0, |
| 71 | + "truncation": "disabled", |
| 72 | + }, |
| 73 | + ) |
| 74 | + |
| 75 | + parsed = parse_response(text_format=omit, input_tools=omit, response=response) |
| 76 | + |
| 77 | + assert parsed.output == [] |
| 78 | + |
| 79 | + |
44 | 80 | @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) |
45 | 81 | def test_stream_method_definition_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None: |
46 | 82 | checking_client: OpenAI | AsyncOpenAI = client if sync else async_client |
|
0 commit comments