Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(llms): wrap remaining lines over 120 chars in migrated unit tests

yunengf61abe00a6bd
diff --git a/tests/unit/llms/bedrock/passthrough/guardrail_translation/test_handler.py b/tests/unit/llms/bedrock/passthrough/guardrail_translation/test_handler.py
index dee8366ce2d..da7ed635dcb 100644
--- a/tests/unit/llms/bedrock/passthrough/guardrail_translation/test_handler.py
+++ b/tests/unit/llms/bedrock/passthrough/guardrail_translation/test_handler.py
@@ -1072,7 +1072,8 @@ class TestDeAnonymizeConverseStream:
@pytest.mark.asyncio
async def test_reasoning_text_delta_de_anonymized(self):
- """Reasoning deltas carry model output; their text must be guardrailed while the reasoning signature is left untouched."""
+ """Reasoning deltas carry model output; their text must be guardrailed while the
+ reasoning signature is left untouched."""
stream_bytes = (
_build_event_stream_frame("messageStart", {"role": "assistant"})
+ _build_event_stream_frame(
@@ -1105,7 +1106,8 @@ class TestDeAnonymizeConverseStream:
@pytest.mark.asyncio
async def test_tool_use_input_delta_de_anonymized(self):
- """toolUse.input deltas carry model-generated tool arguments and must be guardrailed instead of being forwarded raw."""
+ """toolUse.input deltas carry model-generated tool arguments and must be
+ guardrailed instead of being forwarded raw."""
stream_bytes = _build_event_stream_frame(
"contentBlockDelta",
{"contentBlockIndex": 0, "delta": {"toolUse": {"input": '{"q":"<PERSON_1>"}'}}},
@@ -1154,7 +1156,8 @@ class TestDeAnonymizeConverseStream:
@pytest.mark.asyncio
async def test_text_and_reasoning_deltas_de_anonymized_independently(self):
- """Distinct delta kinds must each be guardrailed and written back into their own field without bleeding the de-anonymized text across kinds."""
+ """Distinct delta kinds must each be guardrailed and written back into their own
+ field without bleeding the de-anonymized text across kinds."""
captured = {}
async def mock_hook(data, user_api_key_dict, response):
@@ -1192,7 +1195,8 @@ class TestDeAnonymizeConverseStream:
@pytest.mark.asyncio
async def test_reasoning_signature_only_frame_left_unmodified(self):
- """A reasoning delta carrying only a signature has no guardrailable text; it must be forwarded untouched and the guardrail must not run."""
+ """A reasoning delta carrying only a signature has no guardrailable text; it must
+ be forwarded untouched and the guardrail must not run."""
stream_bytes = _build_event_stream_frame(
"contentBlockDelta",
{"contentBlockIndex": 0, "delta": {"reasoningContent": {"signature": "sig"}}},
diff --git a/tests/unit/llms/bedrock_mantle/passthrough/test_bedrock_mantle_passthrough_transformation.py b/tests/unit/llms/bedrock_mantle/passthrough/test_bedrock_mantle_passthrough_transformation.py
index 090de0a9d3e..27f6c9a9140 100644
--- a/tests/unit/llms/bedrock_mantle/passthrough/test_bedrock_mantle_passthrough_transformation.py
+++ b/tests/unit/llms/bedrock_mantle/passthrough/test_bedrock_mantle_passthrough_transformation.py
@@ -109,7 +109,13 @@ def test_region_falls_back_to_the_mantle_default_without_any_hint(no_ambient_aws
({}, {"AWS_BEARER_TOKEN_BEDROCK": "aws-env-key"}, "aws-env-key"),
],
)
-def test_sign_request_uses_the_deployment_bearer_token(no_ambient_aws, monkeypatch, litellm_params, env, expected_bearer):
+def test_sign_request_uses_the_deployment_bearer_token(
+ no_ambient_aws,
+ monkeypatch,
+ litellm_params,
+ env,
+ expected_bearer,
+):
for name, value in env.items():
monkeypatch.setenv(name, value)
headers, body = BedrockMantlePassthroughConfig().sign_request(
diff --git a/tests/unit/llms/bytez/chat/test_bytez_chat_transformation.py b/tests/unit/llms/bytez/chat/test_bytez_chat_transformation.py
index 440304aeac1..157e2e51175 100644
--- a/tests/unit/llms/bytez/chat/test_bytez_chat_transformation.py
+++ b/tests/unit/llms/bytez/chat/test_bytez_chat_transformation.py
@@ -8,6 +8,32 @@ from litellm.llms.bytez.chat.transformation import BytezChatConfig, API_BASE, ve
TEST_API_KEY = "MOCK_BYTEZ_API_KEY"
TEST_MODEL_NAME = "google/gemma-3-4b-it"
TEST_MODEL = f"bytez/{TEST_MODEL_NAME}"
+CAT_IMAGE_URL = (
+ "https://images.squarespace-cdn.com/content/v1/5452d441e4b0c188b51fef1a/1615326541809-TW01PVTOJ4PXQUX"
+ "VRLHI/male-orange-tabby-cat.jpg"
+)
+KAGGLE_AUDIO_URL = (
+ "https://storage.googleapis.com/kagglesdsdata/datasets/1736753/2838478/dataset/dataset/B_ANI01_MC_FN_"
+ "SIM01_101.wav?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-1616"
+ "07.iam.gserviceaccount.com%2F20250711%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20250711T192905Z&"
+ "X-Goog-Expires=345600&X-Goog-SignedHeaders=host&X-Goog-Signature=812b4bd6fcf9296f8e34f67664d900a81cf"
+ "81a4c8a4f439ce12befc89b4bef07c2645cab20ce5ba8f6b311dffa85aa05b70b4efbe53bced50a43a5e7622ea1ee0d8cc39"
+ "0679cdc6a6aae2c27f75debc1ce2361c595b3c9e1b8c88e2756ffc6b4f290af7f3dfa7232dc69ccc9a2181be756e0d538250"
+ "f9761a8b05ba1ac6c6b5d946f97a16aa14a5609ae62a2c4713c2077fcd34d129dbcdac6bb543ae547507b1a424e4fd09f817"
+ "000943c11507e0a74c514ec212b17427b7fc9e2ce87a250db1258645e4862a4261e3790fd99c9186148ad0653acd2b6a9468"
+ "adbeb94f17b5a685551037fd2cc9fe72fa405a006c0bd42d03be1e4c0dc4023ed3a77171edff3"
+)
+KAGGLE_VIDEO_URL = (
+ "https://storage.googleapis.com/kagglesdsdata/datasets/3957252/6888743/dog1.mp4?X-Goog-Algorithm=GOOG"
+ "4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F202507"
+ "11%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20250711T193025Z&X-Goog-Expires=345600&X-Goog-Signed"
+ "Headers=host&X-Goog-Signature=810961d9abcbc2437954fdf19ef216deb65d3977eb354ec10af0d4644627cc6b143a5f"
+ "c6450996bae1787c09d26334de7cd6ff887510a5ac2a6eed3cfcc6673a47686c84c1f2b0bf543009388d83f2cd9551ad5f72"
+ "084513c6a7acd2c718849a4ebe951ccc5631bed014b0d115225c048b9f5de68673a37db24a98ad39cf3d0ba16fb764bf38eb"
+ "90c78c295c21a4ddac08c3c661b65efd511ccb86bacb87a2e2a97a06f53ea1c64d5dcf274001a61bc20867802549601301d9"
+ "99f5a5b2e49fd444b7db860c68e1c67df6e8edd5ad97171eaafb4fa1462453924ea4d78733be411cb6b5c910d4f829cd7189"
+ "c28dc1b22c8ae2a4da844a0d202e9e64bc7fb17947"
+)
TEST_MESSAGES = [{"role": "user", "content": "Hello"}]
@@ -148,7 +174,7 @@ class TestBytezChatConfig:
"What color is this cat?",
{
"type": "image_url",
- "url": "https://images.squarespace-cdn.com/content/v1/5452d441e4b0c188b51fef1a/1615326541809-TW01PVTOJ4PXQUXVRLHI/male-orange-tabby-cat.jpg",
+ "url": CAT_IMAGE_URL,
},
],
}
@@ -160,7 +186,7 @@ class TestBytezChatConfig:
{"type": "text", "text": "What color is this cat?"},
{
"type": "image",
- "url": "https://images.squarespace-cdn.com/content/v1/5452d441e4b0c188b51fef1a/1615326541809-TW01PVTOJ4PXQUXVRLHI/male-orange-tabby-cat.jpg",
+ "url": CAT_IMAGE_URL,
},
],
}
@@ -174,7 +200,7 @@ class TestBytezChatConfig:
{"type": "text", "text": "What color is this cat?"},
{
"type": "image_url",
- "url": "https://images.squarespace-cdn.com/content/v1/5452d441e4b0c188b51fef1a/1615326541809-TW01PVTOJ4PXQUXVRLHI/male-orange-tabby-cat.jpg",
+ "url": CAT_IMAGE_URL,
},
],
}
@@ -186,7 +212,7 @@ class TestBytezChatConfig:
{"type": "text", "text": "What color is this cat?"},
{
"type": "image",
- "url": "https://images.squarespace-cdn.com/content/v1/5452d441e4b0c188b51fef1a/1615326541809-TW01PVTOJ4PXQUXVRLHI/male-orange-tabby-cat.jpg",
+ "url": CAT_IMAGE_URL,
},
],
}
@@ -200,7 +226,7 @@ class TestBytezChatConfig:
{"type": "text", "text": "What kind of cat meow is this?"},
{
"type": "input_audio",
- "url": "https://storage.googleapis.com/kagglesdsdata/datasets/1736753/2838478/dataset/dataset/B_ANI01_MC_FN_SIM01_101.wav?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20250711%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20250711T192905Z&X-Goog-Expires=345600&X-Goog-SignedHeaders=host&X-Goog-Signature=812b4bd6fcf9296f8e34f67664d900a81cf81a4c8a4f439ce12befc89b4bef07c2645cab20ce5ba8f6b311dffa85aa05b70b4efbe53bced50a43a5e7622ea1ee0d8cc390679cdc6a6aae2c27f75debc1ce2361c595b3c9e1b8c88e2756ffc6b4f290af7f3dfa7232dc69ccc9a2181be756e0d538250f9761a8b05ba1ac6c6b5d946f97a16aa14a5609ae62a2c4713c2077fcd34d129dbcdac6bb543ae547507b1a424e4fd09f817000943c11507e0a74c514ec212b17427b7fc9e2ce87a250db1258645e4862a4261e3790fd99c9186148ad0653acd2b6a9468adbeb94f17b5a685551037fd2cc9fe72fa405a006c0bd42d03be1e4c0dc4023ed3a77171edff3",
+ "url": KAGGLE_AUDIO_URL,
},
],
}
@@ -212,7 +238,7 @@ class TestBytezChatConfig:
{"type": "text", "text": "What kind of cat meow is this?"},
{
"type": "audio",
- "url": "https://storage.googleapis.com/kagglesdsdata/datasets/1736753/2838478/dataset/dataset/B_ANI01_MC_FN_SIM01_101.wav?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20250711%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20250711T192905Z&X-Goog-Expires=345600&X-Goog-SignedHeaders=host&X-Goog-Signature=812b4bd6fcf9296f8e34f67664d900a81cf81a4c8a4f439ce12befc89b4bef07c2645cab20ce5ba8f6b311dffa85aa05b70b4efbe53bced50a43a5e7622ea1ee0d8cc390679cdc6a6aae2c27f75debc1ce2361c595b3c9e1b8c88e2756ffc6b4f290af7f3dfa7232dc69ccc9a2181be756e0d538250f9761a8b05ba1ac6c6b5d946f97a16aa14a5609ae62a2c4713c2077fcd34d129dbcdac6bb543ae547507b1a424e4fd09f817000943c11507e0a74c514ec212b17427b7fc9e2ce87a250db1258645e4862a4261e3790fd99c9186148ad0653acd2b6a9468adbeb94f17b5a685551037fd2cc9fe72fa405a006c0bd42d03be1e4c0dc4023ed3a77171edff3",
+ "url": KAGGLE_AUDIO_URL,
},
],
}
@@ -226,7 +252,7 @@ class TestBytezChatConfig:
{"type": "text", "text": "What kind of dog is this?"},
{
"type": "video_url",
- "url": "https://storage.googleapis.com/kagglesdsdata/datasets/3957252/6888743/dog1.mp4?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20250711%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20250711T193025Z&X-Goog-Expires=345600&X-Goog-SignedHeaders=host&X-Goog-Signature=810961d9abcbc2437954fdf19ef216deb65d3977eb354ec10af0d4644627cc6b143a5fc6450996bae1787c09d26334de7cd6ff887510a5ac2a6eed3cfcc6673a47686c84c1f2b0bf543009388d83f2cd9551ad5f72084513c6a7acd2c718849a4ebe951ccc5631bed014b0d115225c048b9f5de68673a37db24a98ad39cf3d0ba16fb764bf38eb90c78c295c21a4ddac08c3c661b65efd511ccb86bacb87a2e2a97a06f53ea1c64d5dcf274001a61bc20867802549601301d999f5a5b2e49fd444b7db860c68e1c67df6e8edd5ad97171eaafb4fa1462453924ea4d78733be411cb6b5c910d4f829cd7189c28dc1b22c8ae2a4da844a0d202e9e64bc7fb17947",
+ "url": KAGGLE_VIDEO_URL,
},
],
}
@@ -238,7 +264,7 @@ class TestBytezChatConfig:
{"type": "text", "text": "What kind of dog is this?"},
{
"type": "video",
- "url": "https://storage.googleapis.com/kagglesdsdata/datasets/3957252/6888743/dog1.mp4?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20250711%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20250711T193025Z&X-Goog-Expires=345600&X-Goog-SignedHeaders=host&X-Goog-Signature=810961d9abcbc2437954fdf19ef216deb65d3977eb354ec10af0d4644627cc6b143a5fc6450996bae1787c09d26334de7cd6ff887510a5ac2a6eed3cfcc6673a47686c84c1f2b0bf543009388d83f2cd9551ad5f72084513c6a7acd2c718849a4ebe951ccc5631bed014b0d115225c048b9f5de68673a37db24a98ad39cf3d0ba16fb764bf38eb90c78c295c21a4ddac08c3c661b65efd511ccb86bacb87a2e2a97a06f53ea1c64d5dcf274001a61bc20867802549601301d999f5a5b2e49fd444b7db860c68e1c67df6e8edd5ad97171eaafb4fa1462453924ea4d78733be411cb6b5c910d4f829cd7189c28dc1b22c8ae2a4da844a0d202e9e64bc7fb17947",
+ "url": KAGGLE_VIDEO_URL,
},
],
}
diff --git a/tests/unit/llms/chat/test_converse_handler.py b/tests/unit/llms/chat/test_converse_handler.py
index 12b5f03aedc..05debee0602 100644
--- a/tests/unit/llms/chat/test_converse_handler.py
+++ b/tests/unit/llms/chat/test_converse_handler.py
@@ -106,7 +106,10 @@ class TestBedrockRegionInModelPath:
), f"modelId mismatch for {model!r}: got {model_id!r}, expected {expected_model_id!r}"
assert (
optional_params.get("aws_region_name") == expected_region
- ), f"region mismatch for {model!r}: got {optional_params.get('aws_region_name')!r}, expected {expected_region!r}"
+ ), (
+ f"region mismatch for {model!r}: "
+ f"got {optional_params.get('aws_region_name')!r}, expected {expected_region!r}"
+ )
def test_explicit_aws_region_name_not_overridden(self):
"""