Repository: pydantic/pydantic-ai
File: tests/test_ag_ui.py (Python)

Code before:
    """Test that ActivityMessage is not supported."""
    messages = [
        ActivityMessage(
            id='activity_1',
            role='activity',
            activity_type='PLAN',
            content={'steps': ['Step 1', 'Step 2'], 'status': 'in_progress'},
        )
    ]
    with pytest.raises(ValueError, match=r"Unsupported message type: <class '.*ActivityMessage'>"):
        AGUIAdapter.load_messages(messages)


def test_load_messages_empty_user_content() -> None:
    """Test load_messages with a UserMessage that has an empty content list."""
    messages = [
        UserMessage(
            id='msg_1',
            content=[],
        )
    ]
    loaded_messages = AGUIAdapter.load_messages(messages)
    assert not loaded_messages


def test_load_binary_part() -> None:
    """Test the _load_binary_part method of the AGUIAdapter."""
    # Test data URI
    data_uri_part = BinaryInputContent(
        url='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=',
        mime_type='image/png',
    )
    result = AGUIAdapter.load_binary_part(data_uri_part)
    assert isinstance(result, BinaryContent)
    assert result.data == b64decode(
        'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='
    )

    # Test ImageUrl
    image_url_part = BinaryInputContent(url='http://example.com/image.png', mime_type='image/png', id='img1')
    result = AGUIAdapter.load_binary_part(image_url_part)
    assert isinstance(result, ImageUrl)
    assert result.url == 'http://example.com/image.png'
    assert result.media_type == 'image/png'
    assert result.identifier == 'img1'

    # Test VideoUrl
    video_url_part = BinaryInputContent(url='http://example.com/video.mp4', mime_type='video/mp4', id='vid1')
    result = AGUIAdapter.load_binary_part(video_url_part)
    assert isinstance(result, VideoUrl)
    assert result.url == 'http://example.com/video.mp4'

Review comment (suggestion):
I'd rather test this at the `load_messages` level so we can verify these end up in the correct Pydantic AI message history, not just individual parts

Code after:
                        timestamp=IsDatetime(),
                    ),
                    UserPromptPart(
                        content=[
                            ImageUrl(
                                url='http://example.com/image.png', _media_type='image/png', media_type='image/png'
                            )
                        ],
                        timestamp=IsDatetime(),
                    ),
                    UserPromptPart(
                        content=[
                            VideoUrl(
                                url='http://example.com/video.mp4', _media_type='video/mp4', media_type='video/mp4'
                            )
                        ],
                        timestamp=IsDatetime(),
                    ),
                    UserPromptPart(
                        content=[
                            AudioUrl(
                                url='http://example.com/audio.mp3', _media_type='audio/mpeg', media_type='audio/mpeg'
                            )
                        ],
                        timestamp=IsDatetime(),
                    ),
                    UserPromptPart(
                        content=[
                            DocumentUrl(
                                url='http://example.com/doc.pdf',
                                _media_type='application/pdf',
                                media_type='application/pdf',
                            )
                        ],
                        timestamp=IsDatetime(),
                    ),
                    UserPromptPart(
                        content=[document_content],
                        timestamp=IsDatetime(),
                    ),
                ]
            ),
            ModelResponse(
                parts=[
                    BuiltinToolCallPart(
                        tool_name='web_search',
                        args='{"query": "Hello, world!"}',
                        tool_call_id='search_1',
                        provider_name='function',
                    ),
                    BuiltinToolReturnPart(