Skip to content

Commit 7bb43a2

Browse files
committed
add unit test
1 parent 9fa0b14 commit 7bb43a2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pymongo_voyageai/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def load_image(self, document: StoredDocument) -> ImageDocument:
8787
)
8888

8989
def read_from_url(self, url: str) -> io.BytesIO:
90-
bucket, key = url.split("/", 2)[-1].split("/", 1)
90+
bucket, key = url.replace("s3://", "").split("/")
9191
buffer = io.BytesIO()
9292
self.client.download_fileobj(bucket, key, buffer)
9393
return buffer

tests/test_client_unit.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import os
2+
import tempfile
3+
import urllib.request
24
from collections.abc import Generator
5+
from pathlib import Path
36
from typing import Any
47

58
import pytest
@@ -83,6 +86,25 @@ def test_pdf_pages(client: PyMongoVoyageAI):
8386
client.delete_by_ids([d["_id"] for d in resp])
8487

8588

89+
def test_pdf_pages_storage(client: PyMongoVoyageAI):
90+
query = "The consequences of a dictator's peace"
91+
url = "https://www.fdrlibrary.org/documents/356632/390886/readingcopy.pdf"
92+
with urllib.request.urlopen(url) as response:
93+
data = response.read()
94+
with tempfile.NamedTemporaryFile(suffix=".pdf") as fp:
95+
fp.write(data)
96+
fp.flush()
97+
url = f"file://{Path(fp.name).as_posix()}"
98+
images = client.url_to_images(url)
99+
fp.close()
100+
resp = client.add_documents(images)
101+
client.wait_for_indexing()
102+
data = client.similarity_search(query, extract_images=True)
103+
assert len(data[0]["inputs"][0].image.tobytes()) > 0
104+
assert len(client.get_by_ids([d["_id"] for d in resp])) == len(resp)
105+
client.delete_by_ids([d["_id"] for d in resp])
106+
107+
86108
@pytest.mark.asyncio
87109
async def test_image_set_async(client: PyMongoVoyageAI):
88110
url = "hf://datasets/princeton-nlp/CharXiv/val.parquet"

0 commit comments

Comments
 (0)