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