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/audio/test_translations.py

114lines · modeblame

5cfb125aStainless Bot2 years ago1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
08b8179aDavid Schnurr2 years ago2
3from __future__ import annotations
4
5import os
86379b44Stainless Bot2 years ago6from typing import Any, cast
08b8179aDavid Schnurr2 years ago7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
1f3f4784stainless-app[bot]1 years ago12from openai.types.audio import TranslationCreateResponse
08b8179aDavid Schnurr2 years ago13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15
16
17class TestTranslations:
98d779fbStainless Bot2 years ago18parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
08b8179aDavid Schnurr2 years ago19
20@parametrize
21def test_method_create(self, client: OpenAI) -> None:
22translation = client.audio.translations.create(
aa2634c2stainless-app[bot]3 months ago23file=b"Example data",
08b8179aDavid Schnurr2 years ago24model="whisper-1",
25)
1f3f4784stainless-app[bot]1 years ago26assert_matches_type(TranslationCreateResponse, translation, path=["response"])
08b8179aDavid Schnurr2 years ago27
28@parametrize
29def test_method_create_with_all_params(self, client: OpenAI) -> None:
30translation = client.audio.translations.create(
aa2634c2stainless-app[bot]3 months ago31file=b"Example data",
08b8179aDavid Schnurr2 years ago32model="whisper-1",
d1691a17stainless-app[bot]1 years ago33prompt="prompt",
c118d98astainless-app[bot]1 years ago34response_format="json",
08b8179aDavid Schnurr2 years ago35temperature=0,
36)
1f3f4784stainless-app[bot]1 years ago37assert_matches_type(TranslationCreateResponse, translation, path=["response"])
08b8179aDavid Schnurr2 years ago38
39@parametrize
40def test_raw_response_create(self, client: OpenAI) -> None:
41response = client.audio.translations.with_raw_response.create(
aa2634c2stainless-app[bot]3 months ago42file=b"Example data",
08b8179aDavid Schnurr2 years ago43model="whisper-1",
44)
86379b44Stainless Bot2 years ago45
46assert response.is_closed is True
08b8179aDavid Schnurr2 years ago47assert response.http_request.headers.get("X-Stainless-Lang") == "python"
48translation = response.parse()
1f3f4784stainless-app[bot]1 years ago49assert_matches_type(TranslationCreateResponse, translation, path=["response"])
08b8179aDavid Schnurr2 years ago50
86379b44Stainless Bot2 years ago51@parametrize
52def test_streaming_response_create(self, client: OpenAI) -> None:
53with client.audio.translations.with_streaming_response.create(
aa2634c2stainless-app[bot]3 months ago54file=b"Example data",
86379b44Stainless Bot2 years ago55model="whisper-1",
56) as response:
57assert not response.is_closed
58assert response.http_request.headers.get("X-Stainless-Lang") == "python"
59
60translation = response.parse()
1f3f4784stainless-app[bot]1 years ago61assert_matches_type(TranslationCreateResponse, translation, path=["response"])
86379b44Stainless Bot2 years ago62
63assert cast(Any, response.is_closed) is True
64
08b8179aDavid Schnurr2 years ago65
66class TestAsyncTranslations:
d7700afdstainless-app[bot]1 years ago67parametrize = pytest.mark.parametrize(
68"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
69)
08b8179aDavid Schnurr2 years ago70
71@parametrize
98d779fbStainless Bot2 years ago72async def test_method_create(self, async_client: AsyncOpenAI) -> None:
73translation = await async_client.audio.translations.create(
aa2634c2stainless-app[bot]3 months ago74file=b"Example data",
08b8179aDavid Schnurr2 years ago75model="whisper-1",
76)
1f3f4784stainless-app[bot]1 years ago77assert_matches_type(TranslationCreateResponse, translation, path=["response"])
08b8179aDavid Schnurr2 years ago78
79@parametrize
98d779fbStainless Bot2 years ago80async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
81translation = await async_client.audio.translations.create(
aa2634c2stainless-app[bot]3 months ago82file=b"Example data",
08b8179aDavid Schnurr2 years ago83model="whisper-1",
d1691a17stainless-app[bot]1 years ago84prompt="prompt",
c118d98astainless-app[bot]1 years ago85response_format="json",
08b8179aDavid Schnurr2 years ago86temperature=0,
87)
1f3f4784stainless-app[bot]1 years ago88assert_matches_type(TranslationCreateResponse, translation, path=["response"])
08b8179aDavid Schnurr2 years ago89
90@parametrize
98d779fbStainless Bot2 years ago91async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
92response = await async_client.audio.translations.with_raw_response.create(
aa2634c2stainless-app[bot]3 months ago93file=b"Example data",
08b8179aDavid Schnurr2 years ago94model="whisper-1",
95)
86379b44Stainless Bot2 years ago96
97assert response.is_closed is True
08b8179aDavid Schnurr2 years ago98assert response.http_request.headers.get("X-Stainless-Lang") == "python"
99translation = response.parse()
1f3f4784stainless-app[bot]1 years ago100assert_matches_type(TranslationCreateResponse, translation, path=["response"])
86379b44Stainless Bot2 years ago101
102@parametrize
98d779fbStainless Bot2 years ago103async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
104async with async_client.audio.translations.with_streaming_response.create(
aa2634c2stainless-app[bot]3 months ago105file=b"Example data",
86379b44Stainless Bot2 years ago106model="whisper-1",
107) as response:
108assert not response.is_closed
109assert response.http_request.headers.get("X-Stainless-Lang") == "python"
110
111translation = await response.parse()
1f3f4784stainless-app[bot]1 years ago112assert_matches_type(TranslationCreateResponse, translation, path=["response"])
86379b44Stainless Bot2 years ago113
114assert cast(Any, response.is_closed) is True