openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
custom-code-from-generated-20260521

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/evals/test_runs.py

591lines · modeblame

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