openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.20.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/fine_tuning/jobs/test_checkpoints.py

117lines · 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.fine_tuning.jobs import FineTuningJobCheckpoint
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16
17
18class TestCheckpoints:
19 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
20
21 @parametrize
22 def test_method_list(self, client: OpenAI) -> None:
23 checkpoint = client.fine_tuning.jobs.checkpoints.list(
24 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
25 )
26 assert_matches_type(SyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
27
28 @parametrize
29 def test_method_list_with_all_params(self, client: OpenAI) -> None:
30 checkpoint = client.fine_tuning.jobs.checkpoints.list(
31 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
32 after="string",
33 limit=0,
34 )
35 assert_matches_type(SyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
36
37 @parametrize
38 def test_raw_response_list(self, client: OpenAI) -> None:
39 response = client.fine_tuning.jobs.checkpoints.with_raw_response.list(
40 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
41 )
42
43 assert response.is_closed is True
44 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
45 checkpoint = response.parse()
46 assert_matches_type(SyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
47
48 @parametrize
49 def test_streaming_response_list(self, client: OpenAI) -> None:
50 with client.fine_tuning.jobs.checkpoints.with_streaming_response.list(
51 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
52 ) as response:
53 assert not response.is_closed
54 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
55
56 checkpoint = response.parse()
57 assert_matches_type(SyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
58
59 assert cast(Any, response.is_closed) is True
60
61 @parametrize
62 def test_path_params_list(self, client: OpenAI) -> None:
63 with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
64 client.fine_tuning.jobs.checkpoints.with_raw_response.list(
65 "",
66 )
67
68
69class TestAsyncCheckpoints:
70 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
71
72 @parametrize
73 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
74 checkpoint = await async_client.fine_tuning.jobs.checkpoints.list(
75 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
76 )
77 assert_matches_type(AsyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
78
79 @parametrize
80 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
81 checkpoint = await async_client.fine_tuning.jobs.checkpoints.list(
82 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
83 after="string",
84 limit=0,
85 )
86 assert_matches_type(AsyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
87
88 @parametrize
89 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
90 response = await async_client.fine_tuning.jobs.checkpoints.with_raw_response.list(
91 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
92 )
93
94 assert response.is_closed is True
95 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
96 checkpoint = response.parse()
97 assert_matches_type(AsyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
98
99 @parametrize
100 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
101 async with async_client.fine_tuning.jobs.checkpoints.with_streaming_response.list(
102 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
103 ) as response:
104 assert not response.is_closed
105 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
106
107 checkpoint = await response.parse()
108 assert_matches_type(AsyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
109
110 assert cast(Any, response.is_closed) is True
111
112 @parametrize
113 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
114 with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
115 await async_client.fine_tuning.jobs.checkpoints.with_raw_response.list(
116 "",
117 )
118