openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.26.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/runs/test_steps.py

317lines · modeblame

5cfb125aStainless Bot2 years ago1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
baa9f07fRobert Craigie2 years ago2
3from __future__ import annotations
4
5import os
86379b44Stainless Bot2 years ago6from typing import Any, cast
baa9f07fRobert Craigie2 years ago7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncCursorPage, AsyncCursorPage
4a0f0fa0Stainless Bot2 years ago13from openai.types.beta.threads.runs import RunStep
baa9f07fRobert Craigie2 years ago14
cca09707stainless-app[bot]1 years ago15# pyright: reportDeprecated=false
16
baa9f07fRobert Craigie2 years ago17base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20class TestSteps:
98d779fbStainless Bot2 years ago21parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago22
23@parametrize
24def test_method_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago25with pytest.warns(DeprecationWarning):
26step = client.beta.threads.runs.steps.retrieve(
27step_id="step_id",
28thread_id="thread_id",
29run_id="run_id",
30)
31
baa9f07fRobert Craigie2 years ago32assert_matches_type(RunStep, step, path=["response"])
33
5d3111a8Stainless Bot1 years ago34@parametrize
35def test_method_retrieve_with_all_params(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago36with pytest.warns(DeprecationWarning):
37step = client.beta.threads.runs.steps.retrieve(
38step_id="step_id",
39thread_id="thread_id",
40run_id="run_id",
41include=["step_details.tool_calls[*].file_search.results[*].content"],
42)
43
5d3111a8Stainless Bot1 years ago44assert_matches_type(RunStep, step, path=["response"])
45
baa9f07fRobert Craigie2 years ago46@parametrize
47def test_raw_response_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago48with pytest.warns(DeprecationWarning):
49response = client.beta.threads.runs.steps.with_raw_response.retrieve(
50step_id="step_id",
51thread_id="thread_id",
52run_id="run_id",
53)
86379b44Stainless Bot2 years ago54
55assert response.is_closed is True
baa9f07fRobert Craigie2 years ago56assert response.http_request.headers.get("X-Stainless-Lang") == "python"
57step = response.parse()
58assert_matches_type(RunStep, step, path=["response"])
59
86379b44Stainless Bot2 years ago60@parametrize
61def test_streaming_response_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago62with pytest.warns(DeprecationWarning):
63with client.beta.threads.runs.steps.with_streaming_response.retrieve(
64step_id="step_id",
65thread_id="thread_id",
66run_id="run_id",
67) as response:
68assert not response.is_closed
69assert response.http_request.headers.get("X-Stainless-Lang") == "python"
70
71step = response.parse()
72assert_matches_type(RunStep, step, path=["response"])
86379b44Stainless Bot2 years ago73
74assert cast(Any, response.is_closed) is True
75
023a4e66Stainless Bot2 years ago76@parametrize
77def test_path_params_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago78with pytest.warns(DeprecationWarning):
79with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
80client.beta.threads.runs.steps.with_raw_response.retrieve(
81step_id="step_id",
82thread_id="",
83run_id="run_id",
84)
85
86with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
87client.beta.threads.runs.steps.with_raw_response.retrieve(
88step_id="step_id",
89thread_id="thread_id",
90run_id="",
91)
92
93with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
94client.beta.threads.runs.steps.with_raw_response.retrieve(
95step_id="",
96thread_id="thread_id",
97run_id="run_id",
98)
023a4e66Stainless Bot2 years ago99
baa9f07fRobert Craigie2 years ago100@parametrize
101def test_method_list(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago102with pytest.warns(DeprecationWarning):
103step = client.beta.threads.runs.steps.list(
104run_id="run_id",
105thread_id="thread_id",
106)
107
baa9f07fRobert Craigie2 years ago108assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
109
110@parametrize
111def test_method_list_with_all_params(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago112with pytest.warns(DeprecationWarning):
113step = client.beta.threads.runs.steps.list(
114run_id="run_id",
115thread_id="thread_id",
116after="after",
117before="before",
118include=["step_details.tool_calls[*].file_search.results[*].content"],
119limit=0,
120order="asc",
121)
122
baa9f07fRobert Craigie2 years ago123assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
124
125@parametrize
126def test_raw_response_list(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago127with pytest.warns(DeprecationWarning):
128response = client.beta.threads.runs.steps.with_raw_response.list(
129run_id="run_id",
130thread_id="thread_id",
131)
86379b44Stainless Bot2 years ago132
133assert response.is_closed is True
baa9f07fRobert Craigie2 years ago134assert response.http_request.headers.get("X-Stainless-Lang") == "python"
135step = response.parse()
136assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
137
86379b44Stainless Bot2 years ago138@parametrize
139def test_streaming_response_list(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago140with pytest.warns(DeprecationWarning):
141with client.beta.threads.runs.steps.with_streaming_response.list(
142run_id="run_id",
143thread_id="thread_id",
144) as response:
145assert not response.is_closed
146assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago147
cca09707stainless-app[bot]1 years ago148step = response.parse()
149assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
86379b44Stainless Bot2 years ago150
151assert cast(Any, response.is_closed) is True
152
023a4e66Stainless Bot2 years ago153@parametrize
154def test_path_params_list(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago155with pytest.warns(DeprecationWarning):
156with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
157client.beta.threads.runs.steps.with_raw_response.list(
158run_id="run_id",
159thread_id="",
160)
023a4e66Stainless Bot2 years ago161
cca09707stainless-app[bot]1 years ago162with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
163client.beta.threads.runs.steps.with_raw_response.list(
164run_id="",
165thread_id="thread_id",
166)
023a4e66Stainless Bot2 years ago167
baa9f07fRobert Craigie2 years ago168
169class TestAsyncSteps:
c62e9907stainless-app[bot]1 years ago170parametrize = pytest.mark.parametrize(
171"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
172)
baa9f07fRobert Craigie2 years ago173
174@parametrize
98d779fbStainless Bot2 years ago175async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago176with pytest.warns(DeprecationWarning):
177step = await async_client.beta.threads.runs.steps.retrieve(
178step_id="step_id",
179thread_id="thread_id",
180run_id="run_id",
181)
182
baa9f07fRobert Craigie2 years ago183assert_matches_type(RunStep, step, path=["response"])
184
5d3111a8Stainless Bot1 years ago185@parametrize
186async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago187with pytest.warns(DeprecationWarning):
188step = await async_client.beta.threads.runs.steps.retrieve(
189step_id="step_id",
190thread_id="thread_id",
191run_id="run_id",
192include=["step_details.tool_calls[*].file_search.results[*].content"],
193)
194
5d3111a8Stainless Bot1 years ago195assert_matches_type(RunStep, step, path=["response"])
196
baa9f07fRobert Craigie2 years ago197@parametrize
98d779fbStainless Bot2 years ago198async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago199with pytest.warns(DeprecationWarning):
200response = await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
201step_id="step_id",
202thread_id="thread_id",
203run_id="run_id",
204)
86379b44Stainless Bot2 years ago205
206assert response.is_closed is True
baa9f07fRobert Craigie2 years ago207assert response.http_request.headers.get("X-Stainless-Lang") == "python"
208step = response.parse()
209assert_matches_type(RunStep, step, path=["response"])
210
86379b44Stainless Bot2 years ago211@parametrize
98d779fbStainless Bot2 years ago212async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago213with pytest.warns(DeprecationWarning):
214async with async_client.beta.threads.runs.steps.with_streaming_response.retrieve(
215step_id="step_id",
216thread_id="thread_id",
217run_id="run_id",
218) as response:
219assert not response.is_closed
220assert response.http_request.headers.get("X-Stainless-Lang") == "python"
221
222step = await response.parse()
223assert_matches_type(RunStep, step, path=["response"])
86379b44Stainless Bot2 years ago224
225assert cast(Any, response.is_closed) is True
226
023a4e66Stainless Bot2 years ago227@parametrize
98d779fbStainless Bot2 years ago228async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago229with pytest.warns(DeprecationWarning):
230with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
231await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
232step_id="step_id",
233thread_id="",
234run_id="run_id",
235)
236
237with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
238await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
239step_id="step_id",
240thread_id="thread_id",
241run_id="",
242)
243
244with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
245await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
246step_id="",
247thread_id="thread_id",
248run_id="run_id",
249)
023a4e66Stainless Bot2 years ago250
baa9f07fRobert Craigie2 years ago251@parametrize
98d779fbStainless Bot2 years ago252async def test_method_list(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago253with pytest.warns(DeprecationWarning):
254step = await async_client.beta.threads.runs.steps.list(
255run_id="run_id",
256thread_id="thread_id",
257)
258
baa9f07fRobert Craigie2 years ago259assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
260
261@parametrize
98d779fbStainless Bot2 years ago262async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago263with pytest.warns(DeprecationWarning):
264step = await async_client.beta.threads.runs.steps.list(
265run_id="run_id",
266thread_id="thread_id",
267after="after",
268before="before",
269include=["step_details.tool_calls[*].file_search.results[*].content"],
270limit=0,
271order="asc",
272)
273
baa9f07fRobert Craigie2 years ago274assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
275
276@parametrize
98d779fbStainless Bot2 years ago277async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago278with pytest.warns(DeprecationWarning):
279response = await async_client.beta.threads.runs.steps.with_raw_response.list(
280run_id="run_id",
281thread_id="thread_id",
282)
86379b44Stainless Bot2 years ago283
284assert response.is_closed is True
baa9f07fRobert Craigie2 years ago285assert response.http_request.headers.get("X-Stainless-Lang") == "python"
286step = response.parse()
287assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
86379b44Stainless Bot2 years ago288
289@parametrize
98d779fbStainless Bot2 years ago290async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago291with pytest.warns(DeprecationWarning):
292async with async_client.beta.threads.runs.steps.with_streaming_response.list(
293run_id="run_id",
294thread_id="thread_id",
295) as response:
296assert not response.is_closed
297assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago298
cca09707stainless-app[bot]1 years ago299step = await response.parse()
300assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
86379b44Stainless Bot2 years ago301
302assert cast(Any, response.is_closed) is True
023a4e66Stainless Bot2 years ago303
304@parametrize
98d779fbStainless Bot2 years ago305async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago306with pytest.warns(DeprecationWarning):
307with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
308await async_client.beta.threads.runs.steps.with_raw_response.list(
309run_id="run_id",
310thread_id="",
311)
312
313with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
314await async_client.beta.threads.runs.steps.with_raw_response.list(
315run_id="",
316thread_id="thread_id",
317)