From fcd539af33e4c71d0b03d1946d7d5c529a8c340f Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Tue, 30 Sep 2025 18:15:25 +0800 Subject: [PATCH] fix the issue from the tests for pr review --- .../google_genai/test_google_genai_adapter.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/test_litellm/google_genai/test_google_genai_adapter.py b/tests/test_litellm/google_genai/test_google_genai_adapter.py index 669e54638a..626692cf47 100644 --- a/tests/test_litellm/google_genai/test_google_genai_adapter.py +++ b/tests/test_litellm/google_genai/test_google_genai_adapter.py @@ -1059,7 +1059,6 @@ async def test_google_generate_content_with_openai(): """ import unittest.mock - from litellm.google_genai.adapters.transformation import GoogleGenAIAdapter from litellm.types.llms.openai import ChatCompletionAssistantMessage from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import Choices, ModelResponse, Usage @@ -1092,9 +1091,9 @@ async def test_google_generate_content_with_openai(): ) # Use AsyncMock for proper async function mocking - with unittest.mock.patch.object(GoogleGenAIAdapter, 'translate_completion_to_generate_content', new_callable=unittest.mock.AsyncMock) as mock_translate: - # Set the return value directly on the AsyncMock - mock_translate.return_value = {"candidates": []} + with unittest.mock.patch("litellm.completion", new_callable=unittest.mock.MagicMock) as mock_completion: + # Set the return value directly on the MagicMock + mock_completion.return_value = mock_response response = await agenerate_content( model="openai/gpt-4o-mini", @@ -1110,11 +1109,23 @@ async def test_google_generate_content_with_openai(): ] ) + # Print the request args sent to litellm.completion + call_args, call_kwargs = mock_completion.call_args + print("Arguments sent to litellm.completion:") + print(f"Args: {call_args}") + print(f"Kwargs: {call_kwargs}") + # Verify the mock was called - mock_translate.assert_called_once() + mock_completion.assert_called_once() # Print the response for verification print(f"Response: {response}") + ######################################################### + # validate only expected fields were sent to litellm.completion + passed_fields = set(call_kwargs.keys()) + # remove any GenericLiteLLMParams fields + passed_fields = passed_fields - set(GenericLiteLLMParams.model_fields.keys()) + assert passed_fields == set(["model", "messages"]), f"Expected only model and messages to be passed through, got {passed_fields}" @pytest.mark.asyncio async def test_agenerate_content_x_goog_api_key_header(): """