def test_image_documents_to_base64_multiple_sources(tmp_path: Path):
    """Test converting multiple ImageDocuments with different source types."""
    content = httpx.get(EXP_IMAGE_URLS[0]).content
    expected_b64 = base64.b64encode(content).decode("utf-8")
    fl_path = tmp_path / "test_image.png"
    fl_path.write_bytes(content)
    documents = [
        ImageDocument(image=expected_b64),
        ImageDocument(image_path=fl_path),
        ImageDocument(metadata={"file_path": "test.jpg"}),
        ImageDocument(image_url=EXP_IMAGE_URLS[0]),
    ]
    with patch("requests.get") as mock_get:
        mock_get.return_value.content = content
        with patch("os.path.isfile", return_value=True):
            with patch("builtins.open", mock_open(read_data=content)):
                result = image_documents_to_base64(documents)

    assert len(result) == 4
    assert all(encoding == expected_b64 for encoding in result)
Test converting multiple ImageDocuments with different source types.
llama-index-core/tests/multi_modal_llms/test_generic_utils.py