From 103e14e23a2ffe86ee9b1e3f661dff43dac02e49 Mon Sep 17 00:00:00 2001 From: Kartik Chilkoti Date: Wed, 16 Sep 2026 20:18:16 +0530 Subject: [PATCH] test(router): test litellm.Router fallbacks initialization and list parsing --- tests/test_router_fallback_chain.py | 56 ++++++++++++----------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/tests/test_router_fallback_chain.py b/tests/test_router_fallback_chain.py index 38e60334c39..79b94260382 100644 --- a/tests/test_router_fallback_chain.py +++ b/tests/test_router_fallback_chain.py @@ -1,36 +1,26 @@ -\"\"\" -Unit tests for model fallback chain resolution and priority sequence bounds in LiteLLM router. -\"\"\" import pytest -from typing import List, Dict, Any +from litellm import Router -def test_fallback_chain_traversal(): - fallback_map = { - "gpt-4o": ["azure/gpt-4o-east", "bedrock/claude-3-5-sonnet", "vertex_ai/gemini-1.5-pro"] - } - - primary_model = "gpt-4o" - fallbacks = fallback_map.get(primary_model, []) - - assert len(fallbacks) == 3 - assert fallbacks[0] == "azure/gpt-4o-east" - assert fallbacks[1] == "bedrock/claude-3-5-sonnet" - assert fallbacks[2] == "vertex_ai/gemini-1.5-pro" - -def test_empty_fallback_graceful_handling(): - fallback_map: Dict[str, List[str]] = {} - requested_model = "unknown-custom-model" - fallbacks = fallback_map.get(requested_model, []) - assert fallbacks == [] - assert len(fallbacks) == 0 - -def test_priority_tier_routing_selection(): - deployments = [ - {"model_name": "gpt-4", "tier": "primary", "weight": 80}, - {"model_name": "gpt-4", "tier": "secondary", "weight": 20} +def test_router_fallbacks_initialization(): + fallbacks = [ + {"gpt-4": ["azure/gpt-4-east", "bedrock/claude-3-5-sonnet"]} ] - - total_weight = sum(d["weight"] for d in deployments) - assert total_weight == 100 - primary = [d for d in deployments if d["tier"] == "primary"][0] - assert primary["weight"] == 80 \ No newline at end of file + router = Router( + model_list=[ + {"model_name": "gpt-4", "litellm_params": {"model": "azure/gpt-4-east"}}, + {"model_name": "azure/gpt-4-east", "litellm_params": {"model": "azure/gpt-4-east"}}, + {"model_name": "bedrock/claude-3-5-sonnet", "litellm_params": {"model": "bedrock/claude-3-5-sonnet"}}, + ], + fallbacks=fallbacks, + ) + assert router.fallbacks == fallbacks + assert len(router.fallbacks) == 1 + assert "gpt-4" in router.fallbacks[0] + +def test_router_empty_fallbacks(): + router = Router( + model_list=[ + {"model_name": "gpt-3.5-turbo", "litellm_params": {"model": "gpt-3.5-turbo"}} + ] + ) + assert router.fallbacks is None or router.fallbacks == [] \ No newline at end of file