openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.8.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_translations.py

118lines · modecode

1# File generated from our OpenAPI spec by Stainless.
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._client import OpenAI, AsyncOpenAI
13from openai.types.audio import Translation
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestTranslations:
20 strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
21 loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
22 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 translation = client.audio.translations.create(
27 file=b"raw file contents",
28 model="whisper-1",
29 )
30 assert_matches_type(Translation, translation, path=["response"])
31
32 @parametrize
33 def test_method_create_with_all_params(self, client: OpenAI) -> None:
34 translation = client.audio.translations.create(
35 file=b"raw file contents",
36 model="whisper-1",
37 prompt="string",
38 response_format="string",
39 temperature=0,
40 )
41 assert_matches_type(Translation, translation, path=["response"])
42
43 @parametrize
44 def test_raw_response_create(self, client: OpenAI) -> None:
45 response = client.audio.translations.with_raw_response.create(
46 file=b"raw file contents",
47 model="whisper-1",
48 )
49
50 assert response.is_closed is True
51 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
52 translation = response.parse()
53 assert_matches_type(Translation, translation, path=["response"])
54
55 @parametrize
56 def test_streaming_response_create(self, client: OpenAI) -> None:
57 with client.audio.translations.with_streaming_response.create(
58 file=b"raw file contents",
59 model="whisper-1",
60 ) as response:
61 assert not response.is_closed
62 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
63
64 translation = response.parse()
65 assert_matches_type(Translation, translation, path=["response"])
66
67 assert cast(Any, response.is_closed) is True
68
69
70class TestAsyncTranslations:
71 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
72 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
73 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
74
75 @parametrize
76 async def test_method_create(self, client: AsyncOpenAI) -> None:
77 translation = await client.audio.translations.create(
78 file=b"raw file contents",
79 model="whisper-1",
80 )
81 assert_matches_type(Translation, translation, path=["response"])
82
83 @parametrize
84 async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
85 translation = await client.audio.translations.create(
86 file=b"raw file contents",
87 model="whisper-1",
88 prompt="string",
89 response_format="string",
90 temperature=0,
91 )
92 assert_matches_type(Translation, translation, path=["response"])
93
94 @parametrize
95 async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
96 response = await client.audio.translations.with_raw_response.create(
97 file=b"raw file contents",
98 model="whisper-1",
99 )
100
101 assert response.is_closed is True
102 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
103 translation = response.parse()
104 assert_matches_type(Translation, translation, path=["response"])
105
106 @parametrize
107 async def test_streaming_response_create(self, client: AsyncOpenAI) -> None:
108 async with client.audio.translations.with_streaming_response.create(
109 file=b"raw file contents",
110 model="whisper-1",
111 ) as response:
112 assert not response.is_closed
113 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
114
115 translation = await response.parse()
116 assert_matches_type(Translation, translation, path=["response"])
117
118 assert cast(Any, response.is_closed) is True
119