openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.85.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

315lines · modecode

1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.beta.threads.runs import RunStep
14
15# pyright: reportDeprecated=false
16
17base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20class TestSteps:
21 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
22
23 @parametrize
24 def test_method_retrieve(self, client: OpenAI) -> None:
25 with pytest.warns(DeprecationWarning):
26 step = client.beta.threads.runs.steps.retrieve(
27 step_id="step_id",
28 thread_id="thread_id",
29 run_id="run_id",
30 )
31
32 assert_matches_type(RunStep, step, path=["response"])
33
34 @parametrize
35 def test_method_retrieve_with_all_params(self, client: OpenAI) -> None:
36 with pytest.warns(DeprecationWarning):
37 step = client.beta.threads.runs.steps.retrieve(
38 step_id="step_id",
39 thread_id="thread_id",
40 run_id="run_id",
41 include=["step_details.tool_calls[*].file_search.results[*].content"],
42 )
43
44 assert_matches_type(RunStep, step, path=["response"])
45
46 @parametrize
47 def test_raw_response_retrieve(self, client: OpenAI) -> None:
48 with pytest.warns(DeprecationWarning):
49 response = client.beta.threads.runs.steps.with_raw_response.retrieve(
50 step_id="step_id",
51 thread_id="thread_id",
52 run_id="run_id",
53 )
54
55 assert response.is_closed is True
56 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
57 step = response.parse()
58 assert_matches_type(RunStep, step, path=["response"])
59
60 @parametrize
61 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
62 with pytest.warns(DeprecationWarning):
63 with client.beta.threads.runs.steps.with_streaming_response.retrieve(
64 step_id="step_id",
65 thread_id="thread_id",
66 run_id="run_id",
67 ) as response:
68 assert not response.is_closed
69 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
70
71 step = response.parse()
72 assert_matches_type(RunStep, step, path=["response"])
73
74 assert cast(Any, response.is_closed) is True
75
76 @parametrize
77 def test_path_params_retrieve(self, client: OpenAI) -> None:
78 with pytest.warns(DeprecationWarning):
79 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
80 client.beta.threads.runs.steps.with_raw_response.retrieve(
81 step_id="step_id",
82 thread_id="",
83 run_id="run_id",
84 )
85
86 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
87 client.beta.threads.runs.steps.with_raw_response.retrieve(
88 step_id="step_id",
89 thread_id="thread_id",
90 run_id="",
91 )
92
93 with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
94 client.beta.threads.runs.steps.with_raw_response.retrieve(
95 step_id="",
96 thread_id="thread_id",
97 run_id="run_id",
98 )
99
100 @parametrize
101 def test_method_list(self, client: OpenAI) -> None:
102 with pytest.warns(DeprecationWarning):
103 step = client.beta.threads.runs.steps.list(
104 run_id="run_id",
105 thread_id="thread_id",
106 )
107
108 assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
109
110 @parametrize
111 def test_method_list_with_all_params(self, client: OpenAI) -> None:
112 with pytest.warns(DeprecationWarning):
113 step = client.beta.threads.runs.steps.list(
114 run_id="run_id",
115 thread_id="thread_id",
116 after="after",
117 before="before",
118 include=["step_details.tool_calls[*].file_search.results[*].content"],
119 limit=0,
120 order="asc",
121 )
122
123 assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
124
125 @parametrize
126 def test_raw_response_list(self, client: OpenAI) -> None:
127 with pytest.warns(DeprecationWarning):
128 response = client.beta.threads.runs.steps.with_raw_response.list(
129 run_id="run_id",
130 thread_id="thread_id",
131 )
132
133 assert response.is_closed is True
134 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
135 step = response.parse()
136 assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
137
138 @parametrize
139 def test_streaming_response_list(self, client: OpenAI) -> None:
140 with pytest.warns(DeprecationWarning):
141 with client.beta.threads.runs.steps.with_streaming_response.list(
142 run_id="run_id",
143 thread_id="thread_id",
144 ) as response:
145 assert not response.is_closed
146 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
147
148 step = response.parse()
149 assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
150
151 assert cast(Any, response.is_closed) is True
152
153 @parametrize
154 def test_path_params_list(self, client: OpenAI) -> None:
155 with pytest.warns(DeprecationWarning):
156 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
157 client.beta.threads.runs.steps.with_raw_response.list(
158 run_id="run_id",
159 thread_id="",
160 )
161
162 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
163 client.beta.threads.runs.steps.with_raw_response.list(
164 run_id="",
165 thread_id="thread_id",
166 )
167
168
169class TestAsyncSteps:
170 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
171
172 @parametrize
173 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
174 with pytest.warns(DeprecationWarning):
175 step = await async_client.beta.threads.runs.steps.retrieve(
176 step_id="step_id",
177 thread_id="thread_id",
178 run_id="run_id",
179 )
180
181 assert_matches_type(RunStep, step, path=["response"])
182
183 @parametrize
184 async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
185 with pytest.warns(DeprecationWarning):
186 step = await async_client.beta.threads.runs.steps.retrieve(
187 step_id="step_id",
188 thread_id="thread_id",
189 run_id="run_id",
190 include=["step_details.tool_calls[*].file_search.results[*].content"],
191 )
192
193 assert_matches_type(RunStep, step, path=["response"])
194
195 @parametrize
196 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
197 with pytest.warns(DeprecationWarning):
198 response = await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
199 step_id="step_id",
200 thread_id="thread_id",
201 run_id="run_id",
202 )
203
204 assert response.is_closed is True
205 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
206 step = response.parse()
207 assert_matches_type(RunStep, step, path=["response"])
208
209 @parametrize
210 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
211 with pytest.warns(DeprecationWarning):
212 async with async_client.beta.threads.runs.steps.with_streaming_response.retrieve(
213 step_id="step_id",
214 thread_id="thread_id",
215 run_id="run_id",
216 ) as response:
217 assert not response.is_closed
218 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
219
220 step = await response.parse()
221 assert_matches_type(RunStep, step, path=["response"])
222
223 assert cast(Any, response.is_closed) is True
224
225 @parametrize
226 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
227 with pytest.warns(DeprecationWarning):
228 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
229 await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
230 step_id="step_id",
231 thread_id="",
232 run_id="run_id",
233 )
234
235 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
236 await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
237 step_id="step_id",
238 thread_id="thread_id",
239 run_id="",
240 )
241
242 with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
243 await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
244 step_id="",
245 thread_id="thread_id",
246 run_id="run_id",
247 )
248
249 @parametrize
250 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
251 with pytest.warns(DeprecationWarning):
252 step = await async_client.beta.threads.runs.steps.list(
253 run_id="run_id",
254 thread_id="thread_id",
255 )
256
257 assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
258
259 @parametrize
260 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
261 with pytest.warns(DeprecationWarning):
262 step = await async_client.beta.threads.runs.steps.list(
263 run_id="run_id",
264 thread_id="thread_id",
265 after="after",
266 before="before",
267 include=["step_details.tool_calls[*].file_search.results[*].content"],
268 limit=0,
269 order="asc",
270 )
271
272 assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
273
274 @parametrize
275 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
276 with pytest.warns(DeprecationWarning):
277 response = await async_client.beta.threads.runs.steps.with_raw_response.list(
278 run_id="run_id",
279 thread_id="thread_id",
280 )
281
282 assert response.is_closed is True
283 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
284 step = response.parse()
285 assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
286
287 @parametrize
288 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
289 with pytest.warns(DeprecationWarning):
290 async with async_client.beta.threads.runs.steps.with_streaming_response.list(
291 run_id="run_id",
292 thread_id="thread_id",
293 ) as response:
294 assert not response.is_closed
295 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
296
297 step = await response.parse()
298 assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
299
300 assert cast(Any, response.is_closed) is True
301
302 @parametrize
303 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
304 with pytest.warns(DeprecationWarning):
305 with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
306 await async_client.beta.threads.runs.steps.with_raw_response.list(
307 run_id="run_id",
308 thread_id="",
309 )
310
311 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
312 await async_client.beta.threads.runs.steps.with_raw_response.list(
313 run_id="",
314 thread_id="thread_id",
315 )
316