openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next

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

119lines · 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:
c62e9907stainless-app[bot]1 years ago70parametrize = pytest.mark.parametrize(
71"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
72)
f5247e30Stainless Bot2 years ago73
74@parametrize
75async def test_method_list(self, async_client: AsyncOpenAI) -> None:
76checkpoint = await async_client.fine_tuning.jobs.checkpoints.list(
77"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
78)
79assert_matches_type(AsyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
80
81@parametrize
82async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
83checkpoint = await async_client.fine_tuning.jobs.checkpoints.list(
84"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
85after="string",
86limit=0,
87)
88assert_matches_type(AsyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
89
90@parametrize
91async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
92response = await async_client.fine_tuning.jobs.checkpoints.with_raw_response.list(
93"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
94)
95
96assert response.is_closed is True
97assert response.http_request.headers.get("X-Stainless-Lang") == "python"
98checkpoint = response.parse()
99assert_matches_type(AsyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
100
101@parametrize
102async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
103async with async_client.fine_tuning.jobs.checkpoints.with_streaming_response.list(
104"ft-AF1WoRqd3aJAHsqc9NY7iL8F",
105) as response:
106assert not response.is_closed
107assert response.http_request.headers.get("X-Stainless-Lang") == "python"
108
109checkpoint = await response.parse()
110assert_matches_type(AsyncCursorPage[FineTuningJobCheckpoint], checkpoint, path=["response"])
111
112assert cast(Any, response.is_closed) is True
113
114@parametrize
115async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
116with pytest.raises(ValueError, match=r"Expected a non-empty value for `fine_tuning_job_id` but received ''"):
117await async_client.fine_tuning.jobs.checkpoints.with_raw_response.list(
118"",
119)