11import typing
2- from unittest import mock
32
43import faker
54import httpx
@@ -35,8 +34,7 @@ async def test_ok(self, faker: faker.Faker) -> None:
3534 )
3635
3736 result : typing .Final = await any_llm_client .get_client (
38- OpenAIConfigFactory .build (),
39- httpx_client = httpx .AsyncClient (transport = httpx .MockTransport (lambda _ : response )),
37+ OpenAIConfigFactory .build (), transport = httpx .MockTransport (lambda _ : response )
4038 ).request_llm_message (** LLMFuncRequestFactory .build ())
4139
4240 assert result == expected_result
@@ -47,8 +45,7 @@ async def test_fails_without_alternatives(self) -> None:
4745 json = ChatCompletionsNotStreamingResponse .model_construct (choices = []).model_dump (mode = "json" ),
4846 )
4947 client : typing .Final = any_llm_client .get_client (
50- OpenAIConfigFactory .build (),
51- httpx_client = httpx .AsyncClient (transport = httpx .MockTransport (lambda _ : response )),
48+ OpenAIConfigFactory .build (), transport = httpx .MockTransport (lambda _ : response )
5249 )
5350
5451 with pytest .raises (pydantic .ValidationError ):
@@ -89,10 +86,7 @@ async def test_ok(self, faker: faker.Faker) -> None:
8986 response : typing .Final = httpx .Response (
9087 200 , headers = {"Content-Type" : "text/event-stream" }, content = response_content
9188 )
92- client : typing .Final = any_llm_client .get_client (
93- config ,
94- httpx_client = httpx .AsyncClient (transport = httpx .MockTransport (lambda _ : response )),
95- )
89+ client : typing .Final = any_llm_client .get_client (config , transport = httpx .MockTransport (lambda _ : response ))
9690
9791 result : typing .Final = await consume_llm_partial_responses (client .stream_llm_partial_messages (** func_request ))
9892
@@ -106,8 +100,7 @@ async def test_fails_without_alternatives(self) -> None:
106100 200 , headers = {"Content-Type" : "text/event-stream" }, content = response_content
107101 )
108102 client : typing .Final = any_llm_client .get_client (
109- OpenAIConfigFactory .build (),
110- httpx_client = httpx .AsyncClient (transport = httpx .MockTransport (lambda _ : response )),
103+ OpenAIConfigFactory .build (), transport = httpx .MockTransport (lambda _ : response )
111104 )
112105
113106 with pytest .raises (pydantic .ValidationError ):
@@ -119,8 +112,7 @@ class TestOpenAILLMErrors:
119112 @pytest .mark .parametrize ("status_code" , [400 , 500 ])
120113 async def test_fails_with_unknown_error (self , stream : bool , status_code : int ) -> None :
121114 client : typing .Final = any_llm_client .get_client (
122- OpenAIConfigFactory .build (),
123- httpx_client = httpx .AsyncClient (transport = httpx .MockTransport (lambda _ : httpx .Response (status_code ))),
115+ OpenAIConfigFactory .build (), transport = httpx .MockTransport (lambda _ : httpx .Response (status_code ))
124116 )
125117
126118 coroutine : typing .Final = (
@@ -144,8 +136,7 @@ async def test_fails_with_unknown_error(self, stream: bool, status_code: int) ->
144136 async def test_fails_with_out_of_tokens_error (self , stream : bool , content : bytes | None ) -> None :
145137 response : typing .Final = httpx .Response (400 , content = content )
146138 client : typing .Final = any_llm_client .get_client (
147- OpenAIConfigFactory .build (),
148- httpx_client = httpx .AsyncClient (transport = httpx .MockTransport (lambda _ : response )),
139+ OpenAIConfigFactory .build (), transport = httpx .MockTransport (lambda _ : response )
149140 )
150141
151142 coroutine : typing .Final = (
@@ -244,14 +235,13 @@ def test_with_alternation(
244235 self , messages : list [any_llm_client .Message ], expected_result : list [ChatCompletionsMessage ]
245236 ) -> None :
246237 client : typing .Final = any_llm_client .OpenAIClient (
247- config = OpenAIConfigFactory .build (force_user_assistant_message_alternation = True ), httpx_client = mock . Mock ( )
238+ OpenAIConfigFactory .build (force_user_assistant_message_alternation = True )
248239 )
249240 assert client ._prepare_messages (messages ) == expected_result # noqa: SLF001
250241
251242 def test_without_alternation (self ) -> None :
252243 client : typing .Final = any_llm_client .OpenAIClient (
253- config = OpenAIConfigFactory .build (force_user_assistant_message_alternation = False ),
254- httpx_client = mock .Mock (),
244+ OpenAIConfigFactory .build (force_user_assistant_message_alternation = False )
255245 )
256246 assert client ._prepare_messages ( # noqa: SLF001
257247 [
0 commit comments