The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(unit): migrate wave 1 phase 3 anthropic, apiserpent, azure and azure_ai legacy tests
yunengfcabb626acdc
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.pyindex 3bdab1d231a..d002452d14c 100644--- a/tests/unit/conftest.py+++ b/tests/unit/conftest.py@@ -2,6 +2,8 @@ from collections.abc import Iteratorfrom typing import Finalimport pytest++import litellmfrom pytest_socket import enable_socket, socket_allow_hostsLOOPBACK_HOSTS: Final = ["127.0.0.1", "::1"]@@ -21,3 +23,12 @@ def block_external_sockets() -> Iterator[None]:@pytest.hookimpl(trylast=True)def pytest_runtest_setup() -> None:_allow_loopback_only()+++def local_model_cost_map(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:+ monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True")+ monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url=""))+ litellm.get_model_info.cache_clear()+ yield+ litellm.get_model_info.cache_clear()diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/test_reasoning_effort_fields.py b/tests/unit/llms/anthropic/experimental_pass_through/test_reasoning_effort_fields.pysimilarity index 100%rename from tests/test_litellm/llms/anthropic/experimental_pass_through/test_reasoning_effort_fields.pyrename to tests/unit/llms/anthropic/experimental_pass_through/test_reasoning_effort_fields.pydiff --git a/tests/test_litellm/llms/anthropic/files/test_anthropic_files_transformation.py b/tests/unit/llms/anthropic/files/test_anthropic_files_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/anthropic/files/test_anthropic_files_transformation.pyrename to tests/unit/llms/anthropic/files/test_anthropic_files_transformation.pydiff --git a/tests/test_litellm/llms/anthropic/messages/test_advisor_orchestration.py b/tests/unit/llms/anthropic/messages/test_advisor_orchestration.pysimilarity index 100%rename from tests/test_litellm/llms/anthropic/messages/test_advisor_orchestration.pyrename to tests/unit/llms/anthropic/messages/test_advisor_orchestration.pydiff --git a/tests/test_litellm/llms/apiserpent/test_apiserpent_search.py b/tests/unit/llms/apiserpent/test_apiserpent_search.pysimilarity index 100%rename from tests/test_litellm/llms/apiserpent/test_apiserpent_search.pyrename to tests/unit/llms/apiserpent/test_apiserpent_search.pydiff --git a/tests/test_litellm/llms/azure/image_edit/test_azure_image_edit_transformation.py b/tests/unit/llms/azure/image_edit/test_azure_image_edit_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure/image_edit/test_azure_image_edit_transformation.pyrename to tests/unit/llms/azure/image_edit/test_azure_image_edit_transformation.pydiff --git a/tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py b/tests/unit/llms/azure/image_generation/test_azure_image_generation_init.pysimilarity index 91%rename from tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.pyrename to tests/unit/llms/azure/image_generation/test_azure_image_generation_init.pyindex cfde1760389..eabd5c8427d 100644--- a/tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py+++ b/tests/unit/llms/azure/image_generation/test_azure_image_generation_init.py@@ -133,88 +133,6 @@ def test_azure_image_generation_flattens_extra_body():assert data["size"] == "1024x1024"-def test_azure_image_generation_creates_token_provider_from_credentials():- """- Test that azure_ad_token_provider is created from tenant_id, client_id, client_secret.-- This test verifies the fix in images/main.py where we now create the- azure_ad_token_provider from credentials in litellm_params if it's not already provided.- """- # Simulate the fix in images/main.py- litellm_params_dict = {- "tenant_id": "test-tenant-id",- "client_id": "test-client-id",- "client_secret": "test-client-secret",- "azure_scope": None,- }-- azure_ad_token_provider = None-- # This is the logic we added in images/main.py- if azure_ad_token_provider is None:- tenant_id = litellm_params_dict.get("tenant_id")- client_id = litellm_params_dict.get("client_id")- client_secret = litellm_params_dict.get("client_secret")- azure_scope = (- litellm_params_dict.get("azure_scope")- or "https://cognitiveservices.azure.com/.default"- )-- # Verify the credentials are extracted correctly- assert tenant_id == "test-tenant-id"- assert client_id == "test-client-id"- assert client_secret == "test-client-secret"- assert azure_scope == "https://cognitiveservices.azure.com/.default"-- # Verify the condition to create token provider is met- assert (- tenant_id and client_id and client_secret- ), "Credentials should be present to create token provider"---def test_azure_image_generation_headers_without_api_key():- """- Test that when api_key is None, the api-key header is not added to headers.-- This prevents the httpx TypeError: "Header value must be str or bytes, not <class 'NoneType'>"- that was occurring when api_key was None and being set in headers.-- This is a unit test for the fix in images/main.py where we now check:- if api_key is not None:- default_headers["api-key"] = api_key- """- from litellm.images.main import image_generation-- # Test the header building logic directly- api_key = None-- default_headers = {- "Content-Type": "application/json",- }-- # This is the fix: only add api-key if it's not None- if api_key is not None:- default_headers["api-key"] = api_key-- # Verify api-key is not in headers when api_key is None- assert "api-key" not in default_headers-- # Verify Content-Type is still there- assert default_headers["Content-Type"] == "application/json"-- # Test with a valid api_key- api_key = "valid-key-123"- default_headers_with_key = {- "Content-Type": "application/json",- }- if api_key is not None:- default_headers_with_key["api-key"] = api_key-- # Verify api-key is added when api_key is valid- assert "api-key" in default_headers_with_key- assert default_headers_with_key["api-key"] == "valid-key-123"--def test_azure_image_generation_drop_params_response_format():"""Test that unsupported params like response_format are dropped when drop_params=True.diff --git a/tests/test_litellm/llms/azure/passthrough/test_azure_passthrough_transformation.py b/tests/unit/llms/azure/passthrough/test_azure_passthrough_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure/passthrough/test_azure_passthrough_transformation.pyrename to tests/unit/llms/azure/passthrough/test_azure_passthrough_transformation.pydiff --git a/tests/test_litellm/llms/azure/realtime/test_azure_realtime_handler.py b/tests/unit/llms/azure/realtime/test_azure_realtime_handler.pysimilarity index 94%rename from tests/test_litellm/llms/azure/realtime/test_azure_realtime_handler.pyrename to tests/unit/llms/azure/realtime/test_azure_realtime_handler.pyindex 7d24e604569..c1ba286f8c0 100644--- a/tests/test_litellm/llms/azure/realtime/test_azure_realtime_handler.py+++ b/tests/unit/llms/azure/realtime/test_azure_realtime_handler.py@@ -426,41 +426,6 @@ async def test_async_realtime_beta_without_api_version_raises():)-async def test_realtime_protocol_env_var_fallback():- """- Test that LITELLM_AZURE_REALTIME_PROTOCOL env var is used as fallback.- Fixes #22127: no way to set realtime_protocol from config.- """- from litellm.realtime_api.main import _arealtime- from litellm.types.router import GenericLiteLLMParams-- with patch.dict(os.environ, {"LITELLM_AZURE_REALTIME_PROTOCOL": "v1"}):- # Create a GenericLiteLLMParams without realtime_protocol- litellm_params = GenericLiteLLMParams()- # The env var should be picked up as fallback- realtime_protocol = (- {}.get("realtime_protocol")- or litellm_params.get("realtime_protocol")- or os.environ.get("LITELLM_AZURE_REALTIME_PROTOCOL")- or "beta"- )- assert realtime_protocol == "v1"---async def test_realtime_protocol_from_litellm_params():- """- Test that realtime_protocol is read from litellm_params (config.yaml extra field).- Fixes #22127: realtime_protocol in litellm_params was not used.- """- from litellm.types.router import GenericLiteLLMParams-- # Simulate config.yaml with realtime_protocol as an extra field- litellm_params = GenericLiteLLMParams(realtime_protocol="GA")- assert litellm_params.get("realtime_protocol") == "GA"--@pytest.mark.asyncioasync def test_arealtime_transcription_intent_defaults_to_ga(monkeypatch):"""diff --git a/tests/test_litellm/llms/azure/response/test_azure_transformation.py b/tests/unit/llms/azure/response/test_azure_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure/response/test_azure_transformation.pyrename to tests/unit/llms/azure/response/test_azure_transformation.pydiff --git a/tests/test_litellm/llms/azure/search/foundry_responses_web_search_fixture.json b/tests/unit/llms/azure/search/foundry_responses_web_search_fixture.jsonsimilarity index 100%rename from tests/test_litellm/llms/azure/search/foundry_responses_web_search_fixture.jsonrename to tests/unit/llms/azure/search/foundry_responses_web_search_fixture.jsondiff --git a/tests/test_litellm/llms/azure/search/test_bing_grounding_search_transformation.py b/tests/unit/llms/azure/search/test_bing_grounding_search_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure/search/test_bing_grounding_search_transformation.pyrename to tests/unit/llms/azure/search/test_bing_grounding_search_transformation.pydiff --git a/tests/test_litellm/llms/azure/text_to_speech/test_azure_tts_transformation.py b/tests/unit/llms/azure/text_to_speech/test_azure_tts_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure/text_to_speech/test_azure_tts_transformation.pyrename to tests/unit/llms/azure/text_to_speech/test_azure_tts_transformation.pydiff --git a/tests/test_litellm/llms/azure/vector_stores/test_azure_vector_stores_transformation.py b/tests/unit/llms/azure/vector_stores/test_azure_vector_stores_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure/vector_stores/test_azure_vector_stores_transformation.pyrename to tests/unit/llms/azure/vector_stores/test_azure_vector_stores_transformation.pydiff --git a/tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py b/tests/unit/llms/azure_ai/chat/test_azure_ai_transformation.pysimilarity index 97%rename from tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.pyrename to tests/unit/llms/azure_ai/chat/test_azure_ai_transformation.pyindex f8cc0b5071e..e4a33d5772c 100644--- a/tests/test_litellm/llms/azure_ai/chat/test_azure_ai_transformation.py+++ b/tests/unit/llms/azure_ai/chat/test_azure_ai_transformation.py@@ -352,21 +352,6 @@ def test_azure_model_router_stamps_selected_model_on_hidden_params():)-def test_azure_model_router_stamp_does_not_leak_across_responses():- """- ModelResponse declares _hidden_params as a class-level dict, so the stamp has to be written- as a fresh dict. Mutating in place would bleed the selected model into unrelated responses.- """- from litellm.llms.azure_ai.common_utils import (- AZURE_MODEL_ROUTER_SELECTED_MODEL_KEY,- )- from litellm.types.utils import ModelResponse-- untouched = ModelResponse()-- assert AZURE_MODEL_ROUTER_SELECTED_MODEL_KEY not in (untouched._hidden_params or {})--def test_drop_tool_level_extra_fields_strips_copilot_mcp_server_name():"""Regression test: Azure AI returns 400 when tools contain copilot_mcp_server_name.diff --git a/tests/test_litellm/llms/azure_ai/embed/test_azure_ai_embed_handler.py b/tests/unit/llms/azure_ai/embed/test_azure_ai_embed_handler.pysimilarity index 100%rename from tests/test_litellm/llms/azure_ai/embed/test_azure_ai_embed_handler.pyrename to tests/unit/llms/azure_ai/embed/test_azure_ai_embed_handler.pydiff --git a/tests/test_litellm/llms/azure_ai/image_edit/test_azure_ai_image_edit_transformation.py b/tests/unit/llms/azure_ai/image_edit/test_azure_ai_image_edit_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure_ai/image_edit/test_azure_ai_image_edit_transformation.pyrename to tests/unit/llms/azure_ai/image_edit/test_azure_ai_image_edit_transformation.pydiff --git a/tests/test_litellm/llms/azure_ai/image_edit/test_mai_image_edit_transformation.py b/tests/unit/llms/azure_ai/image_edit/test_mai_image_edit_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure_ai/image_edit/test_mai_image_edit_transformation.pyrename to tests/unit/llms/azure_ai/image_edit/test_mai_image_edit_transformation.pydiff --git a/tests/test_litellm/llms/azure_ai/ocr/test_azure_ai_cohere_parse_transformation.py b/tests/unit/llms/azure_ai/ocr/test_azure_ai_cohere_parse_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure_ai/ocr/test_azure_ai_cohere_parse_transformation.pyrename to tests/unit/llms/azure_ai/ocr/test_azure_ai_cohere_parse_transformation.pydiff --git a/tests/test_litellm/llms/azure_ai/passthrough/test_azure_ai_passthrough_transformation.py b/tests/unit/llms/azure_ai/passthrough/test_azure_ai_passthrough_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure_ai/passthrough/test_azure_ai_passthrough_transformation.pyrename to tests/unit/llms/azure_ai/passthrough/test_azure_ai_passthrough_transformation.pydiff --git a/tests/test_litellm/llms/azure_ai/rerank/test_azure_ai_rerank_transformation.py b/tests/unit/llms/azure_ai/rerank/test_azure_ai_rerank_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure_ai/rerank/test_azure_ai_rerank_transformation.pyrename to tests/unit/llms/azure_ai/rerank/test_azure_ai_rerank_transformation.pydiff --git a/tests/test_litellm/llms/azure_ai/responses/test_azure_ai_responses_transformation.py b/tests/unit/llms/azure_ai/responses/test_azure_ai_responses_transformation.pysimilarity index 100%rename from tests/test_litellm/llms/azure_ai/responses/test_azure_ai_responses_transformation.pyrename to tests/unit/llms/azure_ai/responses/test_azure_ai_responses_transformation.py