openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.104.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/lib/test_audio.py

83lines · modeblame

adb6da3aRobert Craigie1 years ago1from __future__ import annotations
2
3import sys
4import inspect
5import typing_extensions
6from typing import get_args
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import evaluate_forwardref
12from openai._utils import assert_signatures_in_sync
13from openai._compat import is_literal_type
14from openai._utils._typing import is_union_type
15from openai.types.audio_response_format import AudioResponseFormat
16
17
18@pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"])
19def test_translation_create_overloads_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None:
20checking_client: OpenAI | AsyncOpenAI = client if sync else async_client
21
22fn = checking_client.audio.translations.create
23overload_response_formats: set[str] = set()
24
25for i, overload in enumerate(typing_extensions.get_overloads(fn)):
26assert_signatures_in_sync(
27fn,
28overload,
2b4bc759stainless-app[bot]1 years ago29exclude_params={"response_format", "stream"},
adb6da3aRobert Craigie1 years ago30description=f" for overload {i}",
31)
32
33sig = inspect.signature(overload)
34typ = evaluate_forwardref(
35sig.parameters["response_format"].annotation,
36globalns=sys.modules[fn.__module__].__dict__,
37)
38if is_union_type(typ):
39for arg in get_args(typ):
40if not is_literal_type(arg):
41continue
42
43overload_response_formats.update(get_args(arg))
44elif is_literal_type(typ):
45overload_response_formats.update(get_args(typ))
46
47src_response_formats: set[str] = set(get_args(AudioResponseFormat))
48diff = src_response_formats.difference(overload_response_formats)
49assert len(diff) == 0, f"some response format options don't have overloads"
50
51
52@pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"])
53def test_transcription_create_overloads_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None:
54checking_client: OpenAI | AsyncOpenAI = client if sync else async_client
55
56fn = checking_client.audio.transcriptions.create
57overload_response_formats: set[str] = set()
58
59for i, overload in enumerate(typing_extensions.get_overloads(fn)):
60assert_signatures_in_sync(
61fn,
62overload,
2b4bc759stainless-app[bot]1 years ago63exclude_params={"response_format", "stream"},
adb6da3aRobert Craigie1 years ago64description=f" for overload {i}",
65)
66
67sig = inspect.signature(overload)
68typ = evaluate_forwardref(
69sig.parameters["response_format"].annotation,
70globalns=sys.modules[fn.__module__].__dict__,
71)
72if is_union_type(typ):
73for arg in get_args(typ):
74if not is_literal_type(arg):
75continue
76
77overload_response_formats.update(get_args(arg))
78elif is_literal_type(typ):
79overload_response_formats.update(get_args(typ))
80
81src_response_formats: set[str] = set(get_args(AudioResponseFormat))
82diff = src_response_formats.difference(overload_response_formats)
83assert len(diff) == 0, f"some response format options don't have overloads"