12
12
import openai ._legacy_response as _legacy_response
13
13
from openai import OpenAI , AsyncOpenAI
14
14
from tests .utils import assert_matches_type
15
- from openai ._client import OpenAI , AsyncOpenAI
16
15
17
16
# pyright: reportDeprecated=false
18
17
19
18
base_url = os .environ .get ("TEST_API_BASE_URL" , "http://127.0.0.1:4010" )
20
- api_key = "My API Key"
21
19
22
20
23
21
class TestSpeech :
24
- strict_client = OpenAI (base_url = base_url , api_key = api_key , _strict_response_validation = True )
25
- loose_client = OpenAI (base_url = base_url , api_key = api_key , _strict_response_validation = False )
26
- parametrize = pytest .mark .parametrize ("client" , [strict_client , loose_client ], ids = ["strict" , "loose" ])
22
+ parametrize = pytest .mark .parametrize ("client" , [False , True ], indirect = True , ids = ["loose" , "strict" ])
27
23
28
24
@parametrize
29
25
@pytest .mark .respx (base_url = base_url )
@@ -86,15 +82,13 @@ def test_streaming_response_create(self, client: OpenAI, respx_mock: MockRouter)
86
82
87
83
88
84
class TestAsyncSpeech :
89
- strict_client = AsyncOpenAI (base_url = base_url , api_key = api_key , _strict_response_validation = True )
90
- loose_client = AsyncOpenAI (base_url = base_url , api_key = api_key , _strict_response_validation = False )
91
- parametrize = pytest .mark .parametrize ("client" , [strict_client , loose_client ], ids = ["strict" , "loose" ])
85
+ parametrize = pytest .mark .parametrize ("async_client" , [False , True ], indirect = True , ids = ["loose" , "strict" ])
92
86
93
87
@parametrize
94
88
@pytest .mark .respx (base_url = base_url )
95
- async def test_method_create (self , client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
89
+ async def test_method_create (self , async_client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
96
90
respx_mock .post ("/audio/speech" ).mock (return_value = httpx .Response (200 , json = {"foo" : "bar" }))
97
- speech = await client .audio .speech .create (
91
+ speech = await async_client .audio .speech .create (
98
92
input = "string" ,
99
93
model = "string" ,
100
94
voice = "alloy" ,
@@ -104,9 +98,9 @@ async def test_method_create(self, client: AsyncOpenAI, respx_mock: MockRouter)
104
98
105
99
@parametrize
106
100
@pytest .mark .respx (base_url = base_url )
107
- async def test_method_create_with_all_params (self , client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
101
+ async def test_method_create_with_all_params (self , async_client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
108
102
respx_mock .post ("/audio/speech" ).mock (return_value = httpx .Response (200 , json = {"foo" : "bar" }))
109
- speech = await client .audio .speech .create (
103
+ speech = await async_client .audio .speech .create (
110
104
input = "string" ,
111
105
model = "string" ,
112
106
voice = "alloy" ,
@@ -118,10 +112,10 @@ async def test_method_create_with_all_params(self, client: AsyncOpenAI, respx_mo
118
112
119
113
@parametrize
120
114
@pytest .mark .respx (base_url = base_url )
121
- async def test_raw_response_create (self , client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
115
+ async def test_raw_response_create (self , async_client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
122
116
respx_mock .post ("/audio/speech" ).mock (return_value = httpx .Response (200 , json = {"foo" : "bar" }))
123
117
124
- response = await client .audio .speech .with_raw_response .create (
118
+ response = await async_client .audio .speech .with_raw_response .create (
125
119
input = "string" ,
126
120
model = "string" ,
127
121
voice = "alloy" ,
@@ -134,9 +128,9 @@ async def test_raw_response_create(self, client: AsyncOpenAI, respx_mock: MockRo
134
128
135
129
@parametrize
136
130
@pytest .mark .respx (base_url = base_url )
137
- async def test_streaming_response_create (self , client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
131
+ async def test_streaming_response_create (self , async_client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
138
132
respx_mock .post ("/audio/speech" ).mock (return_value = httpx .Response (200 , json = {"foo" : "bar" }))
139
- async with client .audio .speech .with_streaming_response .create (
133
+ async with async_client .audio .speech .with_streaming_response .create (
140
134
input = "string" ,
141
135
model = "string" ,
142
136
voice = "alloy" ,
0 commit comments