openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/evals/runs/test_output_items.py

265lines · modeblame

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