Skip to content

Commit 7fd3b9c

Browse files
committed
Add tests
1 parent 50f20e3 commit 7fd3b9c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

integration/test_collection.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import datetime
22
import io
33
import pathlib
4+
import struct
45
import time
56
import uuid
67
from typing import Any, Callable, Dict, List, Optional, Sequence, TypedDict, Union
78

9+
import numpy as np
810
import pytest
911

1012
from integration.conftest import CollectionFactory, CollectionFactoryGet, _sanitize_collection_name
@@ -295,6 +297,54 @@ class TestInsertManyWithTypedDict(TypedDict):
295297
assert obj2.properties["name"] == "some other name"
296298

297299

300+
@pytest.mark.parametrize(
301+
"objects, should_error",
302+
[
303+
(
304+
[
305+
DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])),
306+
],
307+
False,
308+
),
309+
(
310+
[
311+
DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])),
312+
DataObject(properties={"name": "some numpy two"}, vector=np.array([11, 12, 13])),
313+
],
314+
False,
315+
),
316+
(
317+
[
318+
DataObject(
319+
properties={"name": "some numpy 2d"}, vector=np.array([[1, 2, 3], [11, 12, 13]])
320+
),
321+
],
322+
True,
323+
),
324+
],
325+
)
326+
def test_insert_many_with_numpy(
327+
collection_factory: CollectionFactory,
328+
objects: Sequence[DataObject[WeaviateProperties, Any]],
329+
should_error: bool,
330+
) -> None:
331+
collection = collection_factory(
332+
properties=[Property(name="Name", data_type=DataType.TEXT)],
333+
vectorizer_config=Configure.Vectorizer.none(),
334+
)
335+
if not should_error:
336+
ret = collection.data.insert_many(objects)
337+
for idx, uuid_ in ret.uuids.items():
338+
obj1 = collection.query.fetch_object_by_id(uuid_, include_vector=True)
339+
inserted = objects[idx]
340+
assert inserted.properties["name"] == obj1.properties["name"]
341+
assert inserted.vector.tolist() == obj1.vector["default"] # type: ignore[union-attr]
342+
else:
343+
with pytest.raises(struct.error) as e:
344+
collection.data.insert_many(objects)
345+
assert str(e.value) == "required argument is not a float"
346+
347+
298348
def test_insert_many_with_refs(collection_factory: CollectionFactory) -> None:
299349
ref_collection = collection_factory(
300350
name="target", vectorizer_config=Configure.Vectorizer.none()

0 commit comments

Comments
 (0)