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