Skip to content

Commit 852c212

Browse files
committed
add more tests with mock
1 parent 578a165 commit 852c212

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

adalflow/tests/test_openai_client.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ def setUp(self):
7171
{"type": "text", "text": "Describe this image"},
7272
{
7373
"type": "image_url",
74-
"image_url": {"url": "https://example.com/image.jpg", "detail": "auto"},
74+
"image_url": {
75+
"url": "https://example.com/image.jpg",
76+
"detail": "auto",
77+
},
7578
},
7679
],
7780
}
@@ -266,13 +269,17 @@ def test_call_with_vision(self, MockSyncOpenAI, mock_init_sync_client):
266269
mock_init_sync_client.return_value = mock_sync_client
267270

268271
# Mock the vision model response
269-
mock_sync_client.chat.completions.create = Mock(return_value=self.mock_vision_response)
272+
mock_sync_client.chat.completions.create = Mock(
273+
return_value=self.mock_vision_response
274+
)
270275

271276
# Set the sync client
272277
self.client.sync_client = mock_sync_client
273278

274279
# Call the call method with vision model
275-
result = self.client.call(api_kwargs=self.vision_api_kwargs, model_type=ModelType.LLM)
280+
result = self.client.call(
281+
api_kwargs=self.vision_api_kwargs, model_type=ModelType.LLM
282+
)
276283

277284
# Assertions
278285
mock_sync_client.chat.completions.create.assert_called_once_with(
@@ -283,7 +290,9 @@ def test_call_with_vision(self, MockSyncOpenAI, mock_init_sync_client):
283290
# Test parse_chat_completion for vision model
284291
output = self.client.parse_chat_completion(completion=self.mock_vision_response)
285292
self.assertTrue(isinstance(output, GeneratorOutput))
286-
self.assertEqual(output.raw_response, "The image shows a beautiful sunset over mountains.")
293+
self.assertEqual(
294+
output.raw_response, "The image shows a beautiful sunset over mountains."
295+
)
287296
self.assertEqual(output.usage.completion_tokens, 15)
288297
self.assertEqual(output.usage.prompt_tokens, 25)
289298
self.assertEqual(output.usage.total_tokens, 40)

0 commit comments

Comments
 (0)