@@ -200,15 +200,15 @@ def test_run_wrong_input_format(self):
200200 list_integers_input = [1 , 2 , 3 ]
201201
202202 with pytest .raises (TypeError , match = "OpenAIDocumentEmbedder expects a list of Documents as input" ):
203- embedder .run (documents = string_input )
203+ embedder .run (documents = string_input ) # type: ignore[arg-type]
204204
205205 with pytest .raises (TypeError , match = "OpenAIDocumentEmbedder expects a list of Documents as input" ):
206- embedder .run (documents = list_integers_input )
206+ embedder .run (documents = list_integers_input ) # type: ignore[arg-type]
207207
208208 def test_run_on_empty_list (self ):
209209 embedder = OpenAIDocumentEmbedder (api_key = Secret .from_token ("fake-api-key" ))
210210
211- empty_list_input = []
211+ empty_list_input : list [ Document ] = []
212212 result = embedder .run (documents = empty_list_input )
213213
214214 assert result ["documents" ] is not None
@@ -217,6 +217,7 @@ def test_run_on_empty_list(self):
217217 def test_embed_batch_handles_exceptions_gracefully (self , caplog ):
218218 embedder = OpenAIDocumentEmbedder (api_key = Secret .from_token ("fake_api_key" ))
219219 embedder .warm_up ()
220+ assert embedder .client is not None
220221 fake_texts_to_embed = {"1" : "text1" , "2" : "text2" }
221222 with patch .object (
222223 embedder .client .embeddings ,
@@ -231,6 +232,7 @@ def test_embed_batch_handles_exceptions_gracefully(self, caplog):
231232 def test_run_handles_exceptions_gracefully (self , caplog ):
232233 embedder = OpenAIDocumentEmbedder (api_key = Secret .from_token ("fake_api_key" ), batch_size = 1 )
233234 embedder .warm_up ()
235+ assert embedder .client is not None
234236 docs = [
235237 Document (content = "I love cheese" , meta = {"topic" : "Cuisine" }),
236238 Document (content = "A transformer is a deep learning architecture" , meta = {"topic" : "ML" }),
@@ -260,6 +262,7 @@ def test_run_handles_exceptions_gracefully(self, caplog):
260262 def test_embed_batch_raises_exception_on_failure (self ):
261263 embedder = OpenAIDocumentEmbedder (api_key = Secret .from_token ("fake_api_key" ), raise_on_failure = True )
262264 embedder .warm_up ()
265+ assert embedder .client is not None
263266 fake_texts_to_embed = {"1" : "text1" , "2" : "text2" }
264267 with patch .object (
265268 embedder .client .embeddings ,
@@ -354,12 +357,14 @@ def test_warm_up_uses_default_timeout_and_max_retries(self, monkeypatch):
354357 monkeypatch .setenv ("OPENAI_API_KEY" , "fake-api-key" )
355358 embedder = OpenAIDocumentEmbedder ()
356359 embedder .warm_up ()
360+ assert embedder .client is not None
357361 assert embedder .client .max_retries == 5
358362 assert embedder .client .timeout == 30.0
359363
360364 def test_warm_up_uses_timeout_and_max_retries_from_parameters (self ):
361365 embedder = OpenAIDocumentEmbedder (api_key = Secret .from_token ("fake-api-key" ), timeout = 40.0 , max_retries = 1 )
362366 embedder .warm_up ()
367+ assert embedder .client is not None
363368 assert embedder .client .max_retries == 1
364369 assert embedder .client .timeout == 40.0
365370
@@ -368,6 +373,7 @@ def test_warm_up_uses_timeout_and_max_retries_from_env_vars(self, monkeypatch):
368373 monkeypatch .setenv ("OPENAI_MAX_RETRIES" , "10" )
369374 embedder = OpenAIDocumentEmbedder (api_key = Secret .from_token ("fake-api-key" ))
370375 embedder .warm_up ()
376+ assert embedder .client is not None
371377 assert embedder .client .max_retries == 10
372378 assert embedder .client .timeout == 100.0
373379
@@ -379,6 +385,7 @@ def test_key_resolved_at_warm_up_not_init(self, monkeypatch):
379385
380386 def test_sync_lifecycle (self , mock_openai_clients ):
381387 sync_cls , _ = mock_openai_clients
388+ sync_client = sync_cls .return_value
382389 embedder = OpenAIDocumentEmbedder ()
383390 assert embedder .client is None
384391 assert embedder .async_client is None
@@ -388,19 +395,20 @@ def test_sync_lifecycle(self, mock_openai_clients):
388395 assert embedder .async_client is None
389396
390397 embedder .close ()
391- sync_cls . return_value .close .assert_called_once ()
398+ sync_client .close .assert_called_once ()
392399 assert embedder .client is None
393400
394401 async def test_async_lifecycle (self , mock_openai_clients ):
395402 _ , async_cls = mock_openai_clients
403+ async_client = async_cls .return_value
396404 embedder = OpenAIDocumentEmbedder ()
397405
398406 await embedder .warm_up_async ()
399407 assert embedder .async_client is async_cls .return_value
400408 assert embedder .client is None
401409
402410 await embedder .close_async ()
403- async_cls . return_value .close .assert_awaited_once ()
411+ async_client .close .assert_awaited_once ()
404412 assert embedder .async_client is None
405413
406414 async def test_close_is_safe_without_warm_up (self , mock_openai_clients ):
0 commit comments