diff --git a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py index 21578dc5963..501dd5bd0c6 100644 --- a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -9866,9 +9866,9 @@ def _five_cache_hint_conversation() -> list[dict[str, object]]: def _cached_texts(node: object) -> Iterator[str]: if isinstance(node, dict): yield from ((node["text"],) if "cache_control" in node and "text" in node else ()) - yield from (text for value in node.values() for text in _cached_texts(value)) + yield from chain.from_iterable(map(_cached_texts, node.values())) elif isinstance(node, list): - yield from (text for item in node for text in _cached_texts(item)) + yield from chain.from_iterable(map(_cached_texts, node)) @pytest.mark.parametrize( diff --git a/tests/unit/llms/openai/chat/test_openai_gpt_transformation.py b/tests/unit/llms/openai/chat/test_openai_gpt_transformation.py index e5ea76d4894..79fe7061297 100644 --- a/tests/unit/llms/openai/chat/test_openai_gpt_transformation.py +++ b/tests/unit/llms/openai/chat/test_openai_gpt_transformation.py @@ -1891,9 +1891,7 @@ class TestCacheControlStrippingDoesNotMutateCallerInput: request = self._transform(messages, tools) - # the outbound body must still be stripped, both message-level and nested assert "cache_control" not in json.dumps(request) - # and the caller's objects must be untouched, nested content blocks included assert messages == messages_before assert tools == tools_before diff --git a/tests/unit/llms/openai/responses/test_openai_responses_transformation.py b/tests/unit/llms/openai/responses/test_openai_responses_transformation.py index 63511025b83..41c54bf6cc9 100644 --- a/tests/unit/llms/openai/responses/test_openai_responses_transformation.py +++ b/tests/unit/llms/openai/responses/test_openai_responses_transformation.py @@ -582,9 +582,7 @@ class TestOpenAIResponsesAPIConfig: headers={}, ) - # the outbound body is still stripped assert "cache_control" not in json.dumps(result) - # and the caller's objects are untouched, nested content blocks included assert input_with_cache_control == input_before assert tools_with_cache_control == tools_before diff --git a/tests/unit/llms/openrouter/chat/test_openrouter_chat_transformation.py b/tests/unit/llms/openrouter/chat/test_openrouter_chat_transformation.py index 8e21e8a0913..6cef65f8a88 100644 --- a/tests/unit/llms/openrouter/chat/test_openrouter_chat_transformation.py +++ b/tests/unit/llms/openrouter/chat/test_openrouter_chat_transformation.py @@ -2,6 +2,7 @@ import copy import json from collections.abc import Iterator +from itertools import chain from typing import Final from unittest.mock import MagicMock @@ -890,9 +891,9 @@ def _five_message_level_cache_hints() -> list[dict[str, object]]: def _cached_texts(node: object) -> Iterator[str]: if isinstance(node, dict): yield from ((node["text"],) if "cache_control" in node and "text" in node else ()) - yield from (text for value in node.values() for text in _cached_texts(value)) + yield from chain.from_iterable(map(_cached_texts, node.values())) elif isinstance(node, list): - yield from (text for item in node for text in _cached_texts(item)) + yield from chain.from_iterable(map(_cached_texts, node)) @pytest.mark.parametrize(