Files
qdrant-client/tests/embed_tests/test_utils.py
George e823402cf5 new: add b64 encoding function (#1031)
* new: add b64 encoding function

* tests: remove garbage

* refactor base64 function name and params

* manual test for remove iamge inference with base64

* use tempfile

* fix: rename remove_inference->remote_inference

---------

Co-authored-by: generall <andrey@vasnetsov.com>
2025-07-15 18:41:58 +03:00

27 lines
766 B
Python

import base64
from pathlib import Path
import pytest
from qdrant_client.embed.utils import read_base64
from tests.utils import TESTS_PATH
EMBED_TESTS_DATA = TESTS_PATH / "embed_tests" / "misc"
def test_image_path_to_b64():
# Test with a valid image file
image_path = Path(EMBED_TESTS_DATA / "image.jpeg")
original_bytes = image_path.read_bytes()
b64_string = read_base64(image_path)
assert isinstance(b64_string, str)
decoded_bytes = base64.b64decode(b64_string)
assert decoded_bytes == original_bytes, "Decoded bytes do not match original bytes"
# Test with a non-existent file
non_existent_path = Path(EMBED_TESTS_DATA / "gibberish.jpg")
with pytest.raises(FileNotFoundError):
read_base64(non_existent_path)