Skip to content

Commit 56f6525

Browse files
test: add missing prompt validation for sync and async resource methods
1 parent 750354e commit 56f6525

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/test_required_args.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
from openai import OpenAI, AsyncOpenAI
56
from openai._utils import required_args
67

78

@@ -109,3 +110,28 @@ def foo(*, a: str | None = None, b: str | None = None, c: str | None = None) ->
109110
assert foo(a=None, b="bar") == "bar"
110111
assert foo(c=None) is None
111112
assert foo(c="foo") == "foo"
113+
114+
115+
def test_sync_resource_completions_create_missing_prompt(client: OpenAI) -> None:
116+
with pytest.raises(TypeError, match=r"Expected either .*'model'.*'prompt'.*"):
117+
client.completions.create(model="gpt-3.5-turbo-instruct") # type: ignore[call-arg]
118+
119+
120+
def test_sync_resource_images_edit_missing_prompt(client: OpenAI) -> None:
121+
with pytest.raises(TypeError, match=r"Expected either .*'image'.*'prompt'.*"):
122+
client.images.edit(image=b"Example data") # type: ignore[call-arg]
123+
124+
125+
def test_sync_resource_audio_transcriptions_create_missing_model(client: OpenAI) -> None:
126+
with pytest.raises(TypeError, match=r"Expected either .*'file'.*'model'.*"):
127+
client.audio.transcriptions.create(file=b"Example data") # type: ignore[call-arg]
128+
129+
130+
async def test_async_resource_chat_completions_create_missing_messages(async_client: AsyncOpenAI) -> None:
131+
with pytest.raises(TypeError, match=r"Expected either .*'messages'.*'model'.*"):
132+
async_client.chat.completions.create(model="gpt-5.4") # type: ignore[call-arg]
133+
134+
135+
async def test_async_resource_images_generate_missing_prompt(async_client: AsyncOpenAI) -> None:
136+
with pytest.raises(TypeError, match=r"Expected either .*'prompt'.*"):
137+
async_client.images.generate() # type: ignore[call-arg]

0 commit comments

Comments
 (0)