Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/code_coverage_tests/router_code_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def get_functions_from_router(file_path):


ignored_function_names = [
"_acancel_batch",
"__init__",
]

Expand Down
53 changes: 53 additions & 0 deletions tests/router_unit_tests/test_router_acancel_batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
Test router.acancel_batch() functionality

This ensures the router's batch cancellation method has test coverage.
"""
import sys
import os

sys.path.insert(0, os.path.abspath("../.."))

import pytest
from unittest.mock import patch, AsyncMock, MagicMock
from litellm import Router
import litellm


@pytest.fixture
def router():
"""Create a router with a mock deployment"""
return Router(
model_list=[
{
"model_name": "gpt-4",
"litellm_params": {
"model": "gpt-4",
"api_key": "fake-key",
},
}
]
)


@pytest.mark.asyncio
async def test_router_acancel_batch(router):
"""Test that router.acancel_batch() calls litellm.acancel_batch with correct params"""
mock_response = MagicMock()
mock_response.id = "batch_123"
mock_response.status = "cancelled"

with patch.object(litellm, "acancel_batch", new_callable=AsyncMock) as mock_cancel:
mock_cancel.return_value = mock_response

# This tests that the router method exists and can be called
# The actual API call is mocked
response = await router.acancel_batch(
model="gpt-4",
batch_id="batch_123",
)

# Verify the mock was called
assert mock_cancel.called
assert response.id == "batch_123"
assert response.status == "cancelled"
Loading