openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.86.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/evals/test_runs.py

589lines · 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.evals import (
14 RunListResponse,
15 RunCancelResponse,
16 RunCreateResponse,
17 RunDeleteResponse,
18 RunRetrieveResponse,
19)
20
21base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
22
23
24class TestRuns:
25 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
26
27 @parametrize
28 def test_method_create(self, client: OpenAI) -> None:
29 run = client.evals.runs.create(
30 eval_id="eval_id",
31 data_source={
32 "source": {
33 "content": [{"item": {"foo": "bar"}}],
34 "type": "file_content",
35 },
36 "type": "jsonl",
37 },
38 )
39 assert_matches_type(RunCreateResponse, run, path=["response"])
40
41 @parametrize
42 def test_method_create_with_all_params(self, client: OpenAI) -> None:
43 run = client.evals.runs.create(
44 eval_id="eval_id",
45 data_source={
46 "source": {
47 "content": [
48 {
49 "item": {"foo": "bar"},
50 "sample": {"foo": "bar"},
51 }
52 ],
53 "type": "file_content",
54 },
55 "type": "jsonl",
56 },
57 metadata={"foo": "string"},
58 name="name",
59 )
60 assert_matches_type(RunCreateResponse, run, path=["response"])
61
62 @parametrize
63 def test_raw_response_create(self, client: OpenAI) -> None:
64 response = client.evals.runs.with_raw_response.create(
65 eval_id="eval_id",
66 data_source={
67 "source": {
68 "content": [{"item": {"foo": "bar"}}],
69 "type": "file_content",
70 },
71 "type": "jsonl",
72 },
73 )
74
75 assert response.is_closed is True
76 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
77 run = response.parse()
78 assert_matches_type(RunCreateResponse, run, path=["response"])
79
80 @parametrize
81 def test_streaming_response_create(self, client: OpenAI) -> None:
82 with client.evals.runs.with_streaming_response.create(
83 eval_id="eval_id",
84 data_source={
85 "source": {
86 "content": [{"item": {"foo": "bar"}}],
87 "type": "file_content",
88 },
89 "type": "jsonl",
90 },
91 ) as response:
92 assert not response.is_closed
93 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
94
95 run = response.parse()
96 assert_matches_type(RunCreateResponse, run, path=["response"])
97
98 assert cast(Any, response.is_closed) is True
99
100 @parametrize
101 def test_path_params_create(self, client: OpenAI) -> None:
102 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
103 client.evals.runs.with_raw_response.create(
104 eval_id="",
105 data_source={
106 "source": {
107 "content": [{"item": {"foo": "bar"}}],
108 "type": "file_content",
109 },
110 "type": "jsonl",
111 },
112 )
113
114 @parametrize
115 def test_method_retrieve(self, client: OpenAI) -> None:
116 run = client.evals.runs.retrieve(
117 run_id="run_id",
118 eval_id="eval_id",
119 )
120 assert_matches_type(RunRetrieveResponse, run, path=["response"])
121
122 @parametrize
123 def test_raw_response_retrieve(self, client: OpenAI) -> None:
124 response = client.evals.runs.with_raw_response.retrieve(
125 run_id="run_id",
126 eval_id="eval_id",
127 )
128
129 assert response.is_closed is True
130 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
131 run = response.parse()
132 assert_matches_type(RunRetrieveResponse, run, path=["response"])
133
134 @parametrize
135 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
136 with client.evals.runs.with_streaming_response.retrieve(
137 run_id="run_id",
138 eval_id="eval_id",
139 ) as response:
140 assert not response.is_closed
141 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
142
143 run = response.parse()
144 assert_matches_type(RunRetrieveResponse, run, path=["response"])
145
146 assert cast(Any, response.is_closed) is True
147
148 @parametrize
149 def test_path_params_retrieve(self, client: OpenAI) -> None:
150 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
151 client.evals.runs.with_raw_response.retrieve(
152 run_id="run_id",
153 eval_id="",
154 )
155
156 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
157 client.evals.runs.with_raw_response.retrieve(
158 run_id="",
159 eval_id="eval_id",
160 )
161
162 @parametrize
163 def test_method_list(self, client: OpenAI) -> None:
164 run = client.evals.runs.list(
165 eval_id="eval_id",
166 )
167 assert_matches_type(SyncCursorPage[RunListResponse], run, path=["response"])
168
169 @parametrize
170 def test_method_list_with_all_params(self, client: OpenAI) -> None:
171 run = client.evals.runs.list(
172 eval_id="eval_id",
173 after="after",
174 limit=0,
175 order="asc",
176 status="queued",
177 )
178 assert_matches_type(SyncCursorPage[RunListResponse], run, path=["response"])
179
180 @parametrize
181 def test_raw_response_list(self, client: OpenAI) -> None:
182 response = client.evals.runs.with_raw_response.list(
183 eval_id="eval_id",
184 )
185
186 assert response.is_closed is True
187 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
188 run = response.parse()
189 assert_matches_type(SyncCursorPage[RunListResponse], run, path=["response"])
190
191 @parametrize
192 def test_streaming_response_list(self, client: OpenAI) -> None:
193 with client.evals.runs.with_streaming_response.list(
194 eval_id="eval_id",
195 ) as response:
196 assert not response.is_closed
197 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
198
199 run = response.parse()
200 assert_matches_type(SyncCursorPage[RunListResponse], run, path=["response"])
201
202 assert cast(Any, response.is_closed) is True
203
204 @parametrize
205 def test_path_params_list(self, client: OpenAI) -> None:
206 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
207 client.evals.runs.with_raw_response.list(
208 eval_id="",
209 )
210
211 @parametrize
212 def test_method_delete(self, client: OpenAI) -> None:
213 run = client.evals.runs.delete(
214 run_id="run_id",
215 eval_id="eval_id",
216 )
217 assert_matches_type(RunDeleteResponse, run, path=["response"])
218
219 @parametrize
220 def test_raw_response_delete(self, client: OpenAI) -> None:
221 response = client.evals.runs.with_raw_response.delete(
222 run_id="run_id",
223 eval_id="eval_id",
224 )
225
226 assert response.is_closed is True
227 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
228 run = response.parse()
229 assert_matches_type(RunDeleteResponse, run, path=["response"])
230
231 @parametrize
232 def test_streaming_response_delete(self, client: OpenAI) -> None:
233 with client.evals.runs.with_streaming_response.delete(
234 run_id="run_id",
235 eval_id="eval_id",
236 ) as response:
237 assert not response.is_closed
238 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
239
240 run = response.parse()
241 assert_matches_type(RunDeleteResponse, run, path=["response"])
242
243 assert cast(Any, response.is_closed) is True
244
245 @parametrize
246 def test_path_params_delete(self, client: OpenAI) -> None:
247 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
248 client.evals.runs.with_raw_response.delete(
249 run_id="run_id",
250 eval_id="",
251 )
252
253 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
254 client.evals.runs.with_raw_response.delete(
255 run_id="",
256 eval_id="eval_id",
257 )
258
259 @parametrize
260 def test_method_cancel(self, client: OpenAI) -> None:
261 run = client.evals.runs.cancel(
262 run_id="run_id",
263 eval_id="eval_id",
264 )
265 assert_matches_type(RunCancelResponse, run, path=["response"])
266
267 @parametrize
268 def test_raw_response_cancel(self, client: OpenAI) -> None:
269 response = client.evals.runs.with_raw_response.cancel(
270 run_id="run_id",
271 eval_id="eval_id",
272 )
273
274 assert response.is_closed is True
275 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
276 run = response.parse()
277 assert_matches_type(RunCancelResponse, run, path=["response"])
278
279 @parametrize
280 def test_streaming_response_cancel(self, client: OpenAI) -> None:
281 with client.evals.runs.with_streaming_response.cancel(
282 run_id="run_id",
283 eval_id="eval_id",
284 ) as response:
285 assert not response.is_closed
286 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
287
288 run = response.parse()
289 assert_matches_type(RunCancelResponse, run, path=["response"])
290
291 assert cast(Any, response.is_closed) is True
292
293 @parametrize
294 def test_path_params_cancel(self, client: OpenAI) -> None:
295 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
296 client.evals.runs.with_raw_response.cancel(
297 run_id="run_id",
298 eval_id="",
299 )
300
301 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
302 client.evals.runs.with_raw_response.cancel(
303 run_id="",
304 eval_id="eval_id",
305 )
306
307
308class TestAsyncRuns:
309 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
310
311 @parametrize
312 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
313 run = await async_client.evals.runs.create(
314 eval_id="eval_id",
315 data_source={
316 "source": {
317 "content": [{"item": {"foo": "bar"}}],
318 "type": "file_content",
319 },
320 "type": "jsonl",
321 },
322 )
323 assert_matches_type(RunCreateResponse, run, path=["response"])
324
325 @parametrize
326 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
327 run = await async_client.evals.runs.create(
328 eval_id="eval_id",
329 data_source={
330 "source": {
331 "content": [
332 {
333 "item": {"foo": "bar"},
334 "sample": {"foo": "bar"},
335 }
336 ],
337 "type": "file_content",
338 },
339 "type": "jsonl",
340 },
341 metadata={"foo": "string"},
342 name="name",
343 )
344 assert_matches_type(RunCreateResponse, run, path=["response"])
345
346 @parametrize
347 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
348 response = await async_client.evals.runs.with_raw_response.create(
349 eval_id="eval_id",
350 data_source={
351 "source": {
352 "content": [{"item": {"foo": "bar"}}],
353 "type": "file_content",
354 },
355 "type": "jsonl",
356 },
357 )
358
359 assert response.is_closed is True
360 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
361 run = response.parse()
362 assert_matches_type(RunCreateResponse, run, path=["response"])
363
364 @parametrize
365 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
366 async with async_client.evals.runs.with_streaming_response.create(
367 eval_id="eval_id",
368 data_source={
369 "source": {
370 "content": [{"item": {"foo": "bar"}}],
371 "type": "file_content",
372 },
373 "type": "jsonl",
374 },
375 ) as response:
376 assert not response.is_closed
377 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
378
379 run = await response.parse()
380 assert_matches_type(RunCreateResponse, run, path=["response"])
381
382 assert cast(Any, response.is_closed) is True
383
384 @parametrize
385 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
386 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
387 await async_client.evals.runs.with_raw_response.create(
388 eval_id="",
389 data_source={
390 "source": {
391 "content": [{"item": {"foo": "bar"}}],
392 "type": "file_content",
393 },
394 "type": "jsonl",
395 },
396 )
397
398 @parametrize
399 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
400 run = await async_client.evals.runs.retrieve(
401 run_id="run_id",
402 eval_id="eval_id",
403 )
404 assert_matches_type(RunRetrieveResponse, run, path=["response"])
405
406 @parametrize
407 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
408 response = await async_client.evals.runs.with_raw_response.retrieve(
409 run_id="run_id",
410 eval_id="eval_id",
411 )
412
413 assert response.is_closed is True
414 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
415 run = response.parse()
416 assert_matches_type(RunRetrieveResponse, run, path=["response"])
417
418 @parametrize
419 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
420 async with async_client.evals.runs.with_streaming_response.retrieve(
421 run_id="run_id",
422 eval_id="eval_id",
423 ) as response:
424 assert not response.is_closed
425 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
426
427 run = await response.parse()
428 assert_matches_type(RunRetrieveResponse, run, path=["response"])
429
430 assert cast(Any, response.is_closed) is True
431
432 @parametrize
433 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
434 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
435 await async_client.evals.runs.with_raw_response.retrieve(
436 run_id="run_id",
437 eval_id="",
438 )
439
440 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
441 await async_client.evals.runs.with_raw_response.retrieve(
442 run_id="",
443 eval_id="eval_id",
444 )
445
446 @parametrize
447 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
448 run = await async_client.evals.runs.list(
449 eval_id="eval_id",
450 )
451 assert_matches_type(AsyncCursorPage[RunListResponse], run, path=["response"])
452
453 @parametrize
454 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
455 run = await async_client.evals.runs.list(
456 eval_id="eval_id",
457 after="after",
458 limit=0,
459 order="asc",
460 status="queued",
461 )
462 assert_matches_type(AsyncCursorPage[RunListResponse], run, path=["response"])
463
464 @parametrize
465 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
466 response = await async_client.evals.runs.with_raw_response.list(
467 eval_id="eval_id",
468 )
469
470 assert response.is_closed is True
471 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
472 run = response.parse()
473 assert_matches_type(AsyncCursorPage[RunListResponse], run, path=["response"])
474
475 @parametrize
476 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
477 async with async_client.evals.runs.with_streaming_response.list(
478 eval_id="eval_id",
479 ) as response:
480 assert not response.is_closed
481 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
482
483 run = await response.parse()
484 assert_matches_type(AsyncCursorPage[RunListResponse], run, path=["response"])
485
486 assert cast(Any, response.is_closed) is True
487
488 @parametrize
489 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
490 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
491 await async_client.evals.runs.with_raw_response.list(
492 eval_id="",
493 )
494
495 @parametrize
496 async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
497 run = await async_client.evals.runs.delete(
498 run_id="run_id",
499 eval_id="eval_id",
500 )
501 assert_matches_type(RunDeleteResponse, run, path=["response"])
502
503 @parametrize
504 async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
505 response = await async_client.evals.runs.with_raw_response.delete(
506 run_id="run_id",
507 eval_id="eval_id",
508 )
509
510 assert response.is_closed is True
511 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
512 run = response.parse()
513 assert_matches_type(RunDeleteResponse, run, path=["response"])
514
515 @parametrize
516 async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
517 async with async_client.evals.runs.with_streaming_response.delete(
518 run_id="run_id",
519 eval_id="eval_id",
520 ) as response:
521 assert not response.is_closed
522 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
523
524 run = await response.parse()
525 assert_matches_type(RunDeleteResponse, run, path=["response"])
526
527 assert cast(Any, response.is_closed) is True
528
529 @parametrize
530 async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
531 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
532 await async_client.evals.runs.with_raw_response.delete(
533 run_id="run_id",
534 eval_id="",
535 )
536
537 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
538 await async_client.evals.runs.with_raw_response.delete(
539 run_id="",
540 eval_id="eval_id",
541 )
542
543 @parametrize
544 async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
545 run = await async_client.evals.runs.cancel(
546 run_id="run_id",
547 eval_id="eval_id",
548 )
549 assert_matches_type(RunCancelResponse, run, path=["response"])
550
551 @parametrize
552 async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
553 response = await async_client.evals.runs.with_raw_response.cancel(
554 run_id="run_id",
555 eval_id="eval_id",
556 )
557
558 assert response.is_closed is True
559 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
560 run = response.parse()
561 assert_matches_type(RunCancelResponse, run, path=["response"])
562
563 @parametrize
564 async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
565 async with async_client.evals.runs.with_streaming_response.cancel(
566 run_id="run_id",
567 eval_id="eval_id",
568 ) as response:
569 assert not response.is_closed
570 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
571
572 run = await response.parse()
573 assert_matches_type(RunCancelResponse, run, path=["response"])
574
575 assert cast(Any, response.is_closed) is True
576
577 @parametrize
578 async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
579 with pytest.raises(ValueError, match=r"Expected a non-empty value for `eval_id` but received ''"):
580 await async_client.evals.runs.with_raw_response.cancel(
581 run_id="run_id",
582 eval_id="",
583 )
584
585 with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
586 await async_client.evals.runs.with_raw_response.cancel(
587 run_id="",
588 eval_id="eval_id",
589 )
590