openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dfdcf571ced31f7859cd1871be39e2fb3af6bafa

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/audio/test_transcriptions.py

116lines · modecode

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