openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.59.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 · modeblame

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