Skip to content

Commit bef4906

Browse files
committed
Add tests for invalid content types and for unsupported asset types
1 parent 8f5055a commit bef4906

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/models/test_transformers_multimodal_type_adapter.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,32 @@ def test_transformers_multimodal_type_adapter_format_input_chat_missing_type_key
170170

171171
with pytest.raises(ValueError, match="Each item in the content list must be a dictionary with a 'type' key"):
172172
adapter.format_input(chat_prompt)
173+
174+
175+
def test_transformers_multimodal_type_adapter_format_input_invalid_content_type(adapter):
176+
chat_prompt = Chat(messages=[
177+
{"role": "user", "content": 42} # Invalid content type (integer)
178+
])
179+
180+
with pytest.raises(ValueError, match="Invalid content type"):
181+
adapter.format_input(chat_prompt)
182+
183+
# Test with another invalid type
184+
chat_prompt = Chat(messages=[
185+
{"role": "user", "content": {"invalid": "dict"}} # Invalid content type (dict not in list)
186+
])
187+
188+
with pytest.raises(ValueError, match="Invalid content type"):
189+
adapter.format_input(chat_prompt)
190+
191+
192+
def test_transformers_multimodal_type_adapter_format_asset_for_template_invalid_type(adapter):
193+
class MockUnsupportedAsset:
194+
pass
195+
196+
# This test requires accessing the private method directly since the error
197+
# would normally be caught earlier in the validation chain
198+
unsupported_asset = MockUnsupportedAsset()
199+
200+
with pytest.raises(ValueError, match="Assets must be of type `Image`, `Video` or `Audio`"):
201+
adapter._format_asset_for_template(unsupported_asset)

0 commit comments

Comments
 (0)