openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.61.1

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

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