test(google_genai): hoist test imports to module level per Greptile review

Per Greptile review on PR #25955: move the four `from ...` imports inside
test_setup_generate_content_call_propagates_user_to_logging_obj (and the
`__import__("datetime")` trick) to module-level imports at the top of the
file, matching CLAUDE.md style guidance.

Also drop the duplicate `import json/os/sys`/`import pytest` block and the
unused `import litellm` / `import json` at the top of the file -- these
were only present because the duplicate-imports shadow was masking the
F401 warning, and removing them keeps `ruff check` clean on this file.
The other pre-existing lint issues in test_agenerate_content_stream
(unused `result`, `== True`) are out of scope for this PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Darien Kindlund 2026-04-17 10:56:11 -04:00
parent b221afb702
commit 6c1fdd4e5f

View file

@ -2,9 +2,11 @@
"""
Test to verify the Google GenAI generate_content adapter functionality
"""
import json
import datetime
import os
import sys
from unittest.mock import MagicMock, patch
import pytest
@ -12,13 +14,9 @@ sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
import json
import os
import sys
import pytest
import litellm
from litellm.google_genai.main import GenerateContentHelper
from litellm.litellm_core_utils.litellm_logging import Logging
from litellm.llms.gemini.google_genai.transformation import GoogleGenAIConfig
@pytest.mark.asyncio
@ -55,11 +53,6 @@ def test_setup_generate_content_call_propagates_user_to_logging_obj():
`model_call_details["user"]` reflect what the client sent (via header or
body) instead of defaulting to None / "".
"""
from unittest.mock import MagicMock, patch
from litellm.google_genai.main import GenerateContentHelper
from litellm.litellm_core_utils.litellm_logging import Logging
# Use a real Logging instance (required by Pydantic model validation),
# but stub out update_from_kwargs so we can assert what it was called with.
real_logging_obj = Logging(
@ -67,7 +60,7 @@ def test_setup_generate_content_call_propagates_user_to_logging_obj():
messages=[{"role": "user", "content": "hi"}],
stream=False,
call_type="agenerate_content",
start_time=__import__("datetime").datetime.now(),
start_time=datetime.datetime.now(),
litellm_call_id="call-id-123",
function_id="",
)
@ -77,20 +70,19 @@ def test_setup_generate_content_call_propagates_user_to_logging_obj():
# Mock the provider config so we hit the update_from_kwargs path (not the
# adapter early-return path). Use spec= on a real subclass so Pydantic's
# is_instance_of check passes.
from litellm.llms.gemini.google_genai.transformation import (
GoogleGenAIConfig,
)
mock_provider_config = MagicMock(spec=GoogleGenAIConfig())
mock_provider_config.map_generate_content_optional_params.return_value = {}
mock_provider_config.transform_generate_content_request.return_value = {}
with patch(
"litellm.get_llm_provider",
return_value=("gemini-2.5-pro", "gemini", None, None),
), patch(
"litellm.utils.ProviderConfigManager.get_provider_google_genai_generate_content_config",
return_value=mock_provider_config,
with (
patch(
"litellm.get_llm_provider",
return_value=("gemini-2.5-pro", "gemini", None, None),
),
patch(
"litellm.utils.ProviderConfigManager.get_provider_google_genai_generate_content_config",
return_value=mock_provider_config,
),
):
GenerateContentHelper.setup_generate_content_call(
model="gemini-2.5-pro",