From 0a7f4bc573d15cd92d69e8faff6264a1fde795a0 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 28 Oct 2026 10:45:07 -0700 Subject: [PATCH] test: type the PDF and annotation tests the PR added --- .../test_convert_dict_to_response.py | 4 ++-- ..._anthropic_messages_adapters_transformation.py | 8 +++++--- .../azure_ai/chat/test_azure_ai_transformation.py | 6 +++--- .../gemma/test_vertex_ai_gemma_global_endpoint.py | 15 ++++++++------- .../unit/test_stream_chunk_builder_annotations.py | 14 ++++++++------ 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/tests/unit/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 index a4c344d250c..cea12230fbd 100644 --- a/tests/unit/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 @@ -3006,7 +3006,7 @@ def _message_with_annotations(annotations: list[dict[str, object]]) -> Message: ).choices[0].message -def test_annotations_typed_other_than_url_citation_move_to_provider_specific_fields(): +def test_annotations_typed_other_than_url_citation_move_to_provider_specific_fields() -> None: untyped_annotation: Final = {"start_index": 0, "end_index": 4} message: Final = _message_with_annotations([_URL_CITATION, untyped_annotation, _FILE_ANNOTATION]) @@ -3014,7 +3014,7 @@ def test_annotations_typed_other_than_url_citation_move_to_provider_specific_fie assert message.provider_specific_fields["annotations"] == [_FILE_ANNOTATION] -def test_url_citation_annotations_keep_provider_keys(): +def test_url_citation_annotations_keep_provider_keys() -> None: message: Final = _message_with_annotations([_URL_CITATION]) assert message.annotations == [_URL_CITATION] diff --git a/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py b/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py index 4f457429093..7da72c52b23 100644 --- a/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py +++ b/tests/unit/llms/anthropic/messages/adapters/test_anthropic_messages_adapters_transformation.py @@ -5275,9 +5275,11 @@ def test_eager_input_streaming_tool_reaches_bedrock_converse_as_beta(): ("title", "expected_filename"), [(None, "document.pdf"), ("Quarterly report", "Quarterly report")], ) -def test_user_pdf_document_reaches_openai_compatible_providers_as_file_part(title, expected_filename): - document = _base64_pdf_block() | ({"title": title} if title else {}) - request_messages = _run_chat_completions_pipeline( +def test_user_pdf_document_reaches_openai_compatible_providers_as_file_part( + title: str | None, expected_filename: str +) -> None: + document: Final = _base64_pdf_block() | ({"title": title} if title else {}) + request_messages: Final = _run_chat_completions_pipeline( [ AnthropicMessagesUserMessageParam( role="user", diff --git a/tests/unit/llms/azure_ai/chat/test_azure_ai_transformation.py b/tests/unit/llms/azure_ai/chat/test_azure_ai_transformation.py index 54d8b149066..3f4504fbf5c 100644 --- a/tests/unit/llms/azure_ai/chat/test_azure_ai_transformation.py +++ b/tests/unit/llms/azure_ai/chat/test_azure_ai_transformation.py @@ -1100,7 +1100,7 @@ def test_map_azure_model_group(model_group_header, expected_model): assert config._map_azure_model_group(model_group_header) == expected_model -def test_azure_ai_sends_file_parts_instead_of_flattening_them_to_text(): +def test_azure_ai_sends_file_parts_instead_of_flattening_them_to_text() -> None: file_part: Final = { "type": "file", "file": {"filename": "document.pdf", "file_data": "data:application/pdf;base64,JVBERi0xLjQK"}, @@ -1118,7 +1118,7 @@ def test_azure_ai_sends_file_parts_instead_of_flattening_them_to_text(): assert request["messages"] == [{"role": "user", "content": content}] -def test_azure_ai_passes_dict_message_content_through_for_the_provider_to_judge(): +def test_azure_ai_passes_dict_message_content_through_for_the_provider_to_judge() -> None: content: Final = {"type": "text", "text": "Say hi"} request: Final = AzureAIStudioConfig().transform_request( @@ -1140,7 +1140,7 @@ def test_azure_ai_passes_dict_message_content_through_for_the_provider_to_judge( ], ids=["text_data_url", "file_id_only"], ) -def test_azure_ai_flattens_a_non_pdf_file_part_to_its_text_as_before(file: dict[str, str]): +def test_azure_ai_flattens_a_non_pdf_file_part_to_its_text_as_before(file: dict[str, str]) -> None: request: Final = AzureAIStudioConfig().transform_request( model="Llama-3.3-70B-Instruct", messages=[{"role": "user", "content": [{"type": "text", "text": "summarize"}, {"type": "file", "file": file}]}], diff --git a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/gemma/test_vertex_ai_gemma_global_endpoint.py b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/gemma/test_vertex_ai_gemma_global_endpoint.py index cb0861edbde..98d0d314977 100644 --- a/tests/unit/llms/vertex_ai/vertex_ai_partner_models/gemma/test_vertex_ai_gemma_global_endpoint.py +++ b/tests/unit/llms/vertex_ai/vertex_ai_partner_models/gemma/test_vertex_ai_gemma_global_endpoint.py @@ -13,6 +13,7 @@ These tests verify that: import json import os +from typing import Final from unittest.mock import AsyncMock, MagicMock, patch import pytest @@ -425,9 +426,9 @@ async def test_vertex_ai_gemma_vision_passthrough(): @pytest.mark.asyncio -async def test_vertex_ai_gemma_pdf_file_part_is_sent_as_image_url(): - pdf_data_url = "data:application/pdf;base64,JVBERi0xLjQKJcfsj6IKMSAwIG9iago8PD4+CmVuZG9iagp0cmFpbGVyCjw8Pj4KJSVFT0YK" - messages = [ +async def test_vertex_ai_gemma_pdf_file_part_is_sent_as_image_url() -> None: + pdf_data_url: Final = "data:application/pdf;base64,JVBERi0xLjQKJcfsj6IKMSAwIG9iago8PD4+CmVuZG9iagp0cmFpbGVyCjw8Pj4KJSVFT0YK" + messages: Final = [ { "role": "user", "content": [ @@ -437,12 +438,12 @@ async def test_vertex_ai_gemma_pdf_file_part_is_sent_as_image_url(): } ] - mock_response = MagicMock() + mock_response: Final = MagicMock() mock_response.status_code = 200 mock_response.headers = {} mock_response.json.return_value = _MOCK_RESPONSE_JSON - mock_vertexai = MagicMock() + mock_vertexai: Final = MagicMock() mock_vertexai.preview = MagicMock() with ( @@ -465,8 +466,8 @@ async def test_vertex_ai_gemma_pdf_file_part_is_sent_as_image_url(): vertex_ai_project="test-project", ) - body = json.loads(mock_http_handler.return_value.post.call_args.kwargs["data"]) - user_msg = next(m for m in body["messages"] if m["role"] == "user") + body: Final = json.loads(mock_http_handler.return_value.post.call_args.kwargs["data"]) + user_msg: Final = next(m for m in body["messages"] if m["role"] == "user") assert user_msg["content"] == [ {"type": "text", "text": "What does the PDF say?"}, {"type": "image_url", "image_url": {"url": pdf_data_url}}, diff --git a/tests/unit/test_stream_chunk_builder_annotations.py b/tests/unit/test_stream_chunk_builder_annotations.py index d2a58dfb2e6..c710697b39c 100644 --- a/tests/unit/test_stream_chunk_builder_annotations.py +++ b/tests/unit/test_stream_chunk_builder_annotations.py @@ -6,6 +6,8 @@ annotation chunk, losing any annotations that arrived in later chunks. This fix merges annotations from ALL chunks. """ +from typing import Final + from litellm import stream_chunk_builder from litellm.types.utils import Delta, ModelResponseStream, StreamingChoices @@ -191,13 +193,13 @@ def test_stream_chunk_builder_no_annotations(): assert not hasattr(message, "annotations") or message.annotations is None -def test_stream_chunk_builder_moves_typed_provider_annotations_like_non_streaming(): - url_citation = { +def test_stream_chunk_builder_moves_typed_provider_annotations_like_non_streaming() -> None: + url_citation: Final = { "type": "url_citation", "url_citation": {"url": "https://example.com", "title": "Example", "start_index": 0, "end_index": 5}, } - file_annotation = {"type": "file", "file": {"hash": "abc123", "name": "report.pdf"}} - chunks = [ + file_annotation: Final = {"type": "file", "file": {"hash": "abc123", "name": "report.pdf"}} + chunks: Final = [ ModelResponseStream( id="chatcmpl-test", created=1700000000, @@ -226,9 +228,9 @@ def test_stream_chunk_builder_moves_typed_provider_annotations_like_non_streamin ), ] - response = stream_chunk_builder(chunks=chunks) + response: Final = stream_chunk_builder(chunks=chunks) assert response is not None - message = response["choices"][0]["message"] + message: Final = response["choices"][0]["message"] assert message.annotations == [url_citation] assert message.provider_specific_fields == {"region": "eu", "annotations": [file_annotation]}