From c090987b9c7e213e64c128b3e23bde4f7e7d8439 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Mar 2026 04:23:54 +0000 Subject: [PATCH] fix: add test for _combine_fallback_usage to satisfy router code coverage The router_code_coverage.py check requires all functions in router.py to be called in test files. Add a basic test for _combine_fallback_usage. Co-authored-by: Ishaan Jaff --- tests/test_litellm/test_router.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py index 99ff7953586..8c37214e19e 100644 --- a/tests/test_litellm/test_router.py +++ b/tests/test_litellm/test_router.py @@ -2733,3 +2733,24 @@ def test_credential_name_not_injected_when_absent(): router._update_kwargs_with_deployment(deployment=deployment, kwargs=kwargs) assert kwargs["metadata"]["tags"] == ["A.101"] + + +def test_combine_fallback_usage(): + """Test that _combine_fallback_usage merges partial and fallback usage.""" + from litellm.router import Router + from litellm.types.utils import Usage + + # Create a stream chunk with usage + chunk = litellm.ModelResponseStream( + id="test", + model="gpt-4o", + choices=[], + usage=Usage(prompt_tokens=10, completion_tokens=5, total_tokens=15), + ) + + # Call _combine_fallback_usage with no extra usage + Router._combine_fallback_usage(chunk, None) + assert chunk.usage is not None + assert chunk.usage.prompt_tokens == 10 + assert chunk.usage.completion_tokens == 5 + assert chunk.usage.total_tokens == 15