openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.63.2

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 · 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
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16
17
18class TestSteps:
98d779fbStainless Bot2 years ago19parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago20
21@parametrize
22def test_method_retrieve(self, client: OpenAI) -> None:
23step = client.beta.threads.runs.steps.retrieve(
24"string",
25thread_id="string",
26run_id="string",
27)
28assert_matches_type(RunStep, step, path=["response"])
29
5d3111a8Stainless Bot1 years ago30@parametrize
31def test_method_retrieve_with_all_params(self, client: OpenAI) -> None:
32step = client.beta.threads.runs.steps.retrieve(
33step_id="step_id",
34thread_id="thread_id",
35run_id="run_id",
36include=["step_details.tool_calls[*].file_search.results[*].content"],
37)
38assert_matches_type(RunStep, step, path=["response"])
39
baa9f07fRobert Craigie2 years ago40@parametrize
41def test_raw_response_retrieve(self, client: OpenAI) -> None:
42response = client.beta.threads.runs.steps.with_raw_response.retrieve(
43"string",
44thread_id="string",
45run_id="string",
46)
86379b44Stainless Bot2 years ago47
48assert response.is_closed is True
baa9f07fRobert Craigie2 years ago49assert response.http_request.headers.get("X-Stainless-Lang") == "python"
50step = response.parse()
51assert_matches_type(RunStep, step, path=["response"])
52
86379b44Stainless Bot2 years ago53@parametrize
54def test_streaming_response_retrieve(self, client: OpenAI) -> None:
55with client.beta.threads.runs.steps.with_streaming_response.retrieve(
56"string",
57thread_id="string",
58run_id="string",
59) as response:
60assert not response.is_closed
61assert response.http_request.headers.get("X-Stainless-Lang") == "python"
62
63step = response.parse()
64assert_matches_type(RunStep, step, path=["response"])
65
66assert cast(Any, response.is_closed) is True
67
023a4e66Stainless Bot2 years ago68@parametrize
69def test_path_params_retrieve(self, client: OpenAI) -> None:
70with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
71client.beta.threads.runs.steps.with_raw_response.retrieve(
72"string",
73thread_id="",
74run_id="string",
75)
76
77with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
78client.beta.threads.runs.steps.with_raw_response.retrieve(
79"string",
80thread_id="string",
81run_id="",
82)
83
84with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
85client.beta.threads.runs.steps.with_raw_response.retrieve(
86"",
87thread_id="string",
88run_id="string",
89)
90
baa9f07fRobert Craigie2 years ago91@parametrize
92def test_method_list(self, client: OpenAI) -> None:
93step = client.beta.threads.runs.steps.list(
94"string",
95thread_id="string",
96)
97assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
98
99@parametrize
100def test_method_list_with_all_params(self, client: OpenAI) -> None:
101step = client.beta.threads.runs.steps.list(
5d3111a8Stainless Bot1 years ago102run_id="run_id",
103thread_id="thread_id",
104after="after",
105before="before",
106include=["step_details.tool_calls[*].file_search.results[*].content"],
baa9f07fRobert Craigie2 years ago107limit=0,
108order="asc",
109)
110assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
111
112@parametrize
113def test_raw_response_list(self, client: OpenAI) -> None:
114response = client.beta.threads.runs.steps.with_raw_response.list(
115"string",
116thread_id="string",
117)
86379b44Stainless Bot2 years ago118
119assert response.is_closed is True
baa9f07fRobert Craigie2 years ago120assert response.http_request.headers.get("X-Stainless-Lang") == "python"
121step = response.parse()
122assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
123
86379b44Stainless Bot2 years ago124@parametrize
125def test_streaming_response_list(self, client: OpenAI) -> None:
126with client.beta.threads.runs.steps.with_streaming_response.list(
127"string",
128thread_id="string",
129) as response:
130assert not response.is_closed
131assert response.http_request.headers.get("X-Stainless-Lang") == "python"
132
133step = response.parse()
134assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
135
136assert cast(Any, response.is_closed) is True
137
023a4e66Stainless Bot2 years ago138@parametrize
139def test_path_params_list(self, client: OpenAI) -> None:
140with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
141client.beta.threads.runs.steps.with_raw_response.list(
142"string",
143thread_id="",
144)
145
146with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
147client.beta.threads.runs.steps.with_raw_response.list(
148"",
149thread_id="string",
150)
151
baa9f07fRobert Craigie2 years ago152
153class TestAsyncSteps:
98d779fbStainless Bot2 years ago154parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago155
156@parametrize
98d779fbStainless Bot2 years ago157async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
158step = await async_client.beta.threads.runs.steps.retrieve(
baa9f07fRobert Craigie2 years ago159"string",
160thread_id="string",
161run_id="string",
162)
163assert_matches_type(RunStep, step, path=["response"])
164
5d3111a8Stainless Bot1 years ago165@parametrize
166async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
167step = await async_client.beta.threads.runs.steps.retrieve(
168step_id="step_id",
169thread_id="thread_id",
170run_id="run_id",
171include=["step_details.tool_calls[*].file_search.results[*].content"],
172)
173assert_matches_type(RunStep, step, path=["response"])
174
baa9f07fRobert Craigie2 years ago175@parametrize
98d779fbStainless Bot2 years ago176async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
177response = await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
baa9f07fRobert Craigie2 years ago178"string",
179thread_id="string",
180run_id="string",
181)
86379b44Stainless Bot2 years ago182
183assert response.is_closed is True
baa9f07fRobert Craigie2 years ago184assert response.http_request.headers.get("X-Stainless-Lang") == "python"
185step = response.parse()
186assert_matches_type(RunStep, step, path=["response"])
187
86379b44Stainless Bot2 years ago188@parametrize
98d779fbStainless Bot2 years ago189async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
190async with async_client.beta.threads.runs.steps.with_streaming_response.retrieve(
86379b44Stainless Bot2 years ago191"string",
192thread_id="string",
193run_id="string",
194) as response:
195assert not response.is_closed
196assert response.http_request.headers.get("X-Stainless-Lang") == "python"
197
198step = await response.parse()
199assert_matches_type(RunStep, step, path=["response"])
200
201assert cast(Any, response.is_closed) is True
202
023a4e66Stainless Bot2 years ago203@parametrize
98d779fbStainless Bot2 years ago204async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago205with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago206await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago207"string",
208thread_id="",
209run_id="string",
210)
211
212with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
98d779fbStainless Bot2 years ago213await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago214"string",
215thread_id="string",
216run_id="",
217)
218
219with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
98d779fbStainless Bot2 years ago220await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago221"",
222thread_id="string",
223run_id="string",
224)
225
baa9f07fRobert Craigie2 years ago226@parametrize
98d779fbStainless Bot2 years ago227async def test_method_list(self, async_client: AsyncOpenAI) -> None:
228step = await async_client.beta.threads.runs.steps.list(
baa9f07fRobert Craigie2 years ago229"string",
230thread_id="string",
231)
232assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
233
234@parametrize
98d779fbStainless Bot2 years ago235async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
236step = await async_client.beta.threads.runs.steps.list(
5d3111a8Stainless Bot1 years ago237run_id="run_id",
238thread_id="thread_id",
239after="after",
240before="before",
241include=["step_details.tool_calls[*].file_search.results[*].content"],
baa9f07fRobert Craigie2 years ago242limit=0,
243order="asc",
244)
245assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
246
247@parametrize
98d779fbStainless Bot2 years ago248async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
249response = await async_client.beta.threads.runs.steps.with_raw_response.list(
baa9f07fRobert Craigie2 years ago250"string",
251thread_id="string",
252)
86379b44Stainless Bot2 years ago253
254assert response.is_closed is True
baa9f07fRobert Craigie2 years ago255assert response.http_request.headers.get("X-Stainless-Lang") == "python"
256step = response.parse()
257assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
86379b44Stainless Bot2 years ago258
259@parametrize
98d779fbStainless Bot2 years ago260async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
261async with async_client.beta.threads.runs.steps.with_streaming_response.list(
86379b44Stainless Bot2 years ago262"string",
263thread_id="string",
264) as response:
265assert not response.is_closed
266assert response.http_request.headers.get("X-Stainless-Lang") == "python"
267
268step = await response.parse()
269assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
270
271assert cast(Any, response.is_closed) is True
023a4e66Stainless Bot2 years ago272
273@parametrize
98d779fbStainless Bot2 years ago274async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago275with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago276await async_client.beta.threads.runs.steps.with_raw_response.list(
023a4e66Stainless Bot2 years ago277"string",
278thread_id="",
279)
280
281with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
98d779fbStainless Bot2 years ago282await async_client.beta.threads.runs.steps.with_raw_response.list(
023a4e66Stainless Bot2 years ago283"",
284thread_id="string",
285)