From b3bcd715e074aa11507ee81fe06f7716ecfa0bae Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 8 Sep 2026 15:01:17 -0700 Subject: [PATCH] test(proxy): type the realtime WebRTC fixtures with Protocols instead of a bare Callable --- .../test_realtime_webrtc_endpoints.py | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/test_litellm/proxy/realtime_endpoints/test_realtime_webrtc_endpoints.py b/tests/test_litellm/proxy/realtime_endpoints/test_realtime_webrtc_endpoints.py index 7436cf84fec..82f2ef097aa 100644 --- a/tests/test_litellm/proxy/realtime_endpoints/test_realtime_webrtc_endpoints.py +++ b/tests/test_litellm/proxy/realtime_endpoints/test_realtime_webrtc_endpoints.py @@ -6,7 +6,8 @@ Tests for LiteLLM proxy realtime WebRTC HTTP endpoints: import json import time -from collections.abc import Awaitable, Callable +from collections.abc import Awaitable +from typing import Protocol from unittest.mock import AsyncMock, MagicMock, patch import httpx @@ -161,17 +162,27 @@ def mock_route_request_realtime_calls(): return _mock_route +class AddLitellmDataToRequest(Protocol): + def __call__(self, data: dict[str, object], **kwargs: object) -> Awaitable[dict[str, object]]: ... + + +class PreCallHook(Protocol): + def __call__( + self, user_api_key_dict: UserAPIKeyAuth, data: dict[str, object], call_type: str + ) -> Awaitable[dict[str, object]]: ... + + @pytest.fixture -def mock_add_litellm_data(): - async def _mock(data, **kwargs): +def mock_add_litellm_data() -> AddLitellmDataToRequest: + async def _mock(data: dict[str, object], **kwargs: object) -> dict[str, object]: return data return _mock @pytest.fixture -def mock_pre_call_hook(): - async def _mock(user_api_key_dict, data, call_type): +def mock_pre_call_hook() -> PreCallHook: + async def _mock(user_api_key_dict: UserAPIKeyAuth, data: dict[str, object], call_type: str) -> dict[str, object]: return data return _mock @@ -1205,8 +1216,8 @@ async def test_transcription_sessions_wraps_route_exception( def test_realtime_calls_upstream_rejection_answers_an_openai_typed_error( proxy_app: FastAPI, - mock_add_litellm_data: Callable[..., Awaitable[object]], - mock_pre_call_hook: Callable[..., Awaitable[object]], + mock_add_litellm_data: AddLitellmDataToRequest, + mock_pre_call_hook: PreCallHook, monkeypatch: pytest.MonkeyPatch, ): """A bare HTTPException carries no type or param, so the tail used to ship the @@ -1245,8 +1256,8 @@ def test_realtime_calls_upstream_rejection_answers_an_openai_typed_error( def test_transcription_sessions_rejection_answers_an_openai_typed_error( proxy_app: FastAPI, - mock_add_litellm_data: Callable[..., Awaitable[object]], - mock_pre_call_hook: Callable[..., Awaitable[object]], + mock_add_litellm_data: AddLitellmDataToRequest, + mock_pre_call_hook: PreCallHook, monkeypatch: pytest.MonkeyPatch, ): """A model the router cannot serve surfaces as a bare HTTPException, which this tail