Skip to content

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]

test: migrate wave 1 phase 2 legacy unit tests to tests/unit

yuneng522c3e3ed6a5
diff --git a/tests/test_litellm/llms/amazon_nova/chat/test_amazon_nova_chat_completion.py b/tests/test_litellm/llms/amazon_nova/chat/test_amazon_nova_chat_completion.py
deleted file mode 100644
index ecdd1b36333..00000000000
--- a/tests/test_litellm/llms/amazon_nova/chat/test_amazon_nova_chat_completion.py
+++ /dev/null
@@ -1,195 +0,0 @@
-import os
-import pytest
-
-# Ensure the project root is on the import path
-
-from litellm import completion
-from litellm.types.utils import ModelResponse, Usage, Choices, Message
-
-
-def _has_api_key() -> bool:
- """Check if Amazon Nova API key is available"""
- return (
- "AMAZON_NOVA_API_KEY" in os.environ
- and os.environ["AMAZON_NOVA_API_KEY"] is not None
- )
-
-
-def _create_mock_nova_response():
- """Helper function to create mock Amazon Nova response for testing"""
- return ModelResponse(
- id="chatcmpl-test-nova-micro",
- choices=[
- Choices(
- finish_reason="stop",
- index=0,
- message=Message(
- content="I am Amazon Nova Micro. 777 times 9 equals 6993.",
- role="assistant",
- ),
- )
- ],
- created=1234567890,
- model="amazon-nova/nova-micro-v1",
- object="chat.completion",
- usage=Usage(prompt_tokens=25, completion_tokens=15, total_tokens=40),
- )
-
-
-def test_amazon_nova_chat_completion_nova_micro():
- if _has_api_key():
- response: ModelResponse = completion(
- model="amazon-nova/nova-micro-v1",
- messages=[
- {"role": "system", "content": "You are a helpful assistant"},
- {
- "role": "user",
- "content": "What model are you? Can you calculate 777 times 9?",
- },
- ],
- api_key=os.environ["AMAZON_NOVA_API_KEY"],
- )
- else:
- # Use mock response when API key is not available
- response = _create_mock_nova_response()
- # Additional mock-specific assertions for code review reference
- assert (
- response.choices[0].message.content
- == "I am Amazon Nova Micro. 777 times 9 equals 6993."
- )
- assert response.model == "amazon-nova/nova-micro-v1"
- assert response.usage.prompt_tokens == 25
- assert response.usage.completion_tokens == 15
- assert response.object == "chat.completion"
- assert response.choices[0].finish_reason == "stop"
- assert response.choices[0].message.role == "assistant"
-
- # Common assertions for both real and mock responses
- assert response is not None
- assert hasattr(response, "choices")
- assert len(response.choices) > 0
- assert response.choices[0].message.content is not None
- assert response.usage.total_tokens > 0
-
-
[email protected](not _has_api_key(), reason="Amazon Nova API key not available")
-def test_amazon_nova_chat_completion_nova_lite():
- response: ModelResponse = completion(
- model="amazon-nova/nova-lite-v1",
- messages=[
- {"role": "system", "content": "You are a helpful assistant"},
- {
- "role": "user",
- "content": "What model are you? Please tell me a poem on rain",
- },
- ],
- api_key=os.environ["AMAZON_NOVA_API_KEY"],
- )
-
- assert response is not None
- assert hasattr(response, "choices")
- assert len(response.choices) > 0
- assert response.choices[0].message.content is not None
- assert response.usage.total_tokens > 0
-
-
[email protected](not _has_api_key(), reason="Amazon Nova API key not available")
-def test_amazon_nova_chat_completion_nova_pro():
- response: ModelResponse = completion(
- model="amazon-nova/nova-pro-v1",
- messages=[
- {"role": "system", "content": "You are a helpful assistant"},
- {
- "role": "user",
- "content": "What model are you? What is MCP server and how does that help in building GenAI applications?",
- },
- ],
- timeout=30,
- api_key=os.environ["AMAZON_NOVA_API_KEY"],
- )
-
- assert response is not None
- assert hasattr(response, "choices")
- assert len(response.choices) > 0
- assert response.choices[0].message.content is not None
- assert response.usage.total_tokens > 0
-
-
[email protected](not _has_api_key(), reason="Amazon Nova API key not available")
-def test_amazon_nova_chat_completion_nova_premier():
- response: ModelResponse = completion(
- model="amazon-nova/nova-premier-v1",
- messages=[
- {"role": "system", "content": "You are a helpful assistant"},
- {
- "role": "user",
- "content": "What model are you? Can you help me understand what Trigonometry is?",
- },
- ],
- timeout=60,
- api_key=os.environ["AMAZON_NOVA_API_KEY"],
- )
-
- assert response is not None
- print(response.choices[0].message.content)
- assert hasattr(response, "choices")
- assert len(response.choices) > 0
- assert response.choices[0].message.content is not None
- assert response.usage.total_tokens > 0
-
-
[email protected](not _has_api_key(), reason="Amazon Nova API key not available")
-def test_amazon_nova_chat_completion_with_tool_usage():
- response: ModelResponse = completion(
- model="amazon-nova/nova-micro-v1",
- messages=[
- {"role": "system", "content": "You are a helpful assistant"},
- {"role": "user", "content": "What is the temperature in SFO?"},
- ],
- tools=[
- {
- "type": "function",
- "function": {
- "name": "getCurrentWeather",
- "description": "Get the current weather in a given city",
- "parameters": {
- "type": "object",
- "properties": {
- "location": {
- "type": "string",
- "description": "City and country e.g. Bogotá, Colombia",
- }
- },
- "required": ["location"],
- },
- },
- }
- ],
- api_key=os.environ["AMAZON_NOVA_API_KEY"],
- )
-
- assert response is not None
- assert hasattr(response, "choices")
- assert len(response.choices) > 0
- assert response.choices[0].message is not None
-
-
[email protected](not _has_api_key(), reason="Amazon Nova API key not available")
-def test_amazon_nova_chat_completion_with_stream_response():
- response = completion(
- model="amazon-nova/nova-micro-v1",
- stream=True,
- messages=[
- {"role": "system", "content": "You are a helpful assistant"},
- {
- "role": "user",
- "content": "What are MMO games? Can you give me some sample references?",
- },
- ],
- api_key=os.environ["AMAZON_NOVA_API_KEY"],
- )
-
- assert response is not None
- chunks = list(response)
- assert chunks is not None
- assert len(chunks) > 0
diff --git a/tests/test_litellm/integrations/levo/test_levo.py b/tests/unit/integrations/levo/test_levo.py
similarity index 88%
rename from tests/test_litellm/integrations/levo/test_levo.py
rename to tests/unit/integrations/levo/test_levo.py
index 903be644671..647bcb3154e 100644
--- a/tests/test_litellm/integrations/levo/test_levo.py
+++ b/tests/unit/integrations/levo/test_levo.py
@@ -151,48 +151,6 @@ class TestLevoConfig(unittest.TestCase):
class TestLevoIntegration(unittest.TestCase):
"""Integration tests for LevoLogger."""
- @patch.dict(
- "os.environ",
- {
- "LEVOAI_API_KEY": "test-api-key",
- "LEVOAI_ORG_ID": "test-org-id",
- "LEVOAI_WORKSPACE_ID": "test-workspace-id",
- "LEVOAI_COLLECTOR_URL": "https://collector.levo.ai",
- },
- )
- @pytest.mark.skipif(
- not OPENTELEMETRY_AVAILABLE, reason="OpenTelemetry packages not installed"
- )
- @patch(
- "litellm.integrations.opentelemetry.OpenTelemetry._init_otel_logger_on_litellm_proxy"
- )
- @pytest.mark.asyncio
- async def test_levo_logger_health_check_healthy(self, mock_init_proxy):
- """Test health check returns healthy status when config is valid."""
- # Mock the proxy initialization to avoid importing proxy code
- mock_init_proxy.return_value = None
-
- config = LevoLogger.get_levo_config()
- otel_config = OpenTelemetryConfig(
- exporter=config.protocol,
- endpoint=config.endpoint,
- headers=config.otlp_auth_headers,
- )
-
- # Create tracer provider with in-memory exporter
- tracer_provider = TracerProvider()
- tracer_provider.add_span_processor(SimpleSpanProcessor(InMemorySpanExporter()))
-
- levo_logger = LevoLogger(
- config=otel_config, callback_name="levo", tracer_provider=tracer_provider
- )
-
- # Run health check
- result = await levo_logger.async_health_check()
-
- self.assertEqual(result["status"], "healthy")
- self.assertIn("message", result)
-
@patch.dict("os.environ", {}, clear=True)
def test_levo_logger_health_check_unhealthy(self):
"""Test health check returns unhealthy status when required vars are missing."""
diff --git a/tests/test_litellm/integrations/litellm_agent/test_litellm_agent_model_resolver.py b/tests/unit/integrations/litellm_agent/test_litellm_agent_model_resolver.py
similarity index 100%
rename from tests/test_litellm/integrations/litellm_agent/test_litellm_agent_model_resolver.py
rename to tests/unit/integrations/litellm_agent/test_litellm_agent_model_resolver.py
diff --git a/tests/test_litellm/integrations/mavvrik_focus/test_mavvrik_focus_logger.py b/tests/unit/integrations/mavvrik_focus/test_mavvrik_focus_logger.py
similarity index 100%
rename from tests/test_litellm/integrations/mavvrik_focus/test_mavvrik_focus_logger.py
rename to tests/unit/integrations/mavvrik_focus/test_mavvrik_focus_logger.py
diff --git a/tests/test_litellm/integrations/opik/test_opik_extractors.py b/tests/unit/integrations/opik/test_opik_extractors.py
similarity index 100%
rename from tests/test_litellm/integrations/opik/test_opik_extractors.py
rename to tests/unit/integrations/opik/test_opik_extractors.py
diff --git a/tests/test_litellm/integrations/pointfive/test_logger.py b/tests/unit/integrations/pointfive/test_logger.py
similarity index 100%
rename from tests/test_litellm/integrations/pointfive/test_logger.py
rename to tests/unit/integrations/pointfive/test_logger.py
diff --git a/tests/test_litellm/integrations/pointfive/test_payload.py b/tests/unit/integrations/pointfive/test_payload.py
similarity index 100%
rename from tests/test_litellm/integrations/pointfive/test_payload.py
rename to tests/unit/integrations/pointfive/test_payload.py
diff --git a/tests/test_litellm/integrations/pointfive/test_upload_client.py b/tests/unit/integrations/pointfive/test_upload_client.py
similarity index 100%
rename from tests/test_litellm/integrations/pointfive/test_upload_client.py
rename to tests/unit/integrations/pointfive/test_upload_client.py
diff --git a/tests/test_litellm/integrations/vector_store_integrations/test_vector_store_pre_call_hook.py b/tests/unit/integrations/vector_store_integrations/test_vector_store_pre_call_hook.py
similarity index 100%
rename from tests/test_litellm/integrations/vector_store_integrations/test_vector_store_pre_call_hook.py
rename to tests/unit/integrations/vector_store_integrations/test_vector_store_pre_call_hook.py
diff --git a/tests/test_litellm/litellm_core_utils/audio_utils/test_subtitle_utils.py b/tests/unit/litellm_core_utils/audio_utils/test_subtitle_utils.py
similarity index 100%
rename from tests/test_litellm/litellm_core_utils/audio_utils/test_subtitle_utils.py
rename to tests/unit/litellm_core_utils/audio_utils/test_subtitle_utils.py
diff --git a/tests/test_litellm/litellm_core_utils/llm_response_utils/test_convert_dict_to_response.py b/tests/unit/litellm_core_utils/llm_response_utils/test_convert_dict_to_response.py
similarity index 100%
rename from tests/test_litellm/litellm_core_utils/llm_response_utils/test_convert_dict_to_response.py
rename to tests/unit/litellm_core_utils/llm_response_utils/test_convert_dict_to_response.py
diff --git a/tests/test_litellm/litellm_core_utils/llm_response_utils/test_convert_to_streaming_response.py b/tests/unit/litellm_core_utils/llm_response_utils/test_convert_to_streaming_response.py
similarity index 100%
rename from tests/test_litellm/litellm_core_utils/llm_response_utils/test_convert_to_streaming_response.py
rename to tests/unit/litellm_core_utils/llm_response_utils/test_convert_to_streaming_response.py
diff --git a/tests/test_litellm/litellm_core_utils/llm_response_utils/test_get_formatted_prompt.py b/tests/unit/litellm_core_utils/llm_response_utils/test_get_formatted_prompt.py
similarity index 100%
rename from tests/test_litellm/litellm_core_utils/llm_response_utils/test_get_formatted_prompt.py
rename to tests/unit/litellm_core_utils/llm_response_utils/test_get_formatted_prompt.py
diff --git a/tests/test_litellm/litellm_core_utils/llm_response_utils/test_response_metadata.py b/tests/unit/litellm_core_utils/llm_response_utils/test_response_metadata.py
similarity index 100%
rename from tests/test_litellm/litellm_core_utils/llm_response_utils/test_response_metadata.py
rename to tests/unit/litellm_core_utils/llm_response_utils/test_response_metadata.py
diff --git a/tests/test_litellm/llms/a2a/chat/guardrail_translation/test_a2a_guardrail_handler.py b/tests/unit/llms/a2a/chat/guardrail_translation/test_a2a_guardrail_handler.py
similarity index 100%
rename from tests/test_litellm/llms/a2a/chat/guardrail_translation/test_a2a_guardrail_handler.py
rename to tests/unit/llms/a2a/chat/guardrail_translation/test_a2a_guardrail_handler.py
diff --git a/tests/test_litellm/llms/a2a/chat/test_a2a_chat_streaming_iterator.py b/tests/unit/llms/a2a/chat/test_a2a_chat_streaming_iterator.py
similarity index 100%
rename from tests/test_litellm/llms/a2a/chat/test_a2a_chat_streaming_iterator.py
rename to tests/unit/llms/a2a/chat/test_a2a_chat_streaming_iterator.py
diff --git a/tests/test_litellm/llms/a2a/chat/test_a2a_chat_transformation.py b/tests/unit/llms/a2a/chat/test_a2a_chat_transformation.py
similarity index 100%
rename from tests/test_litellm/llms/a2a/chat/test_a2a_chat_transformation.py
rename to tests/unit/llms/a2a/chat/test_a2a_chat_transformation.py
diff --git a/tests/test_litellm/llms/a2a/test_common_utils.py b/tests/unit/llms/a2a/test_common_utils.py
similarity index 100%
rename from tests/test_litellm/llms/a2a/test_common_utils.py
rename to tests/unit/llms/a2a/test_common_utils.py
diff --git a/tests/test_litellm/llms/anthropic/batches/test_handler.py b/tests/unit/llms/anthropic/batches/test_handler.py
similarity index 100%
rename from tests/test_litellm/llms/anthropic/batches/test_handler.py
rename to tests/unit/llms/anthropic/batches/test_handler.py
diff --git a/tests/test_litellm/llms/anthropic/batches/test_transformation.py b/tests/unit/llms/anthropic/batches/test_transformation.py
similarity index 100%
rename from tests/test_litellm/llms/anthropic/batches/test_transformation.py
rename to tests/unit/llms/anthropic/batches/test_transformation.py