Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-reiss committed Jul 21, 2024
1 parent 50f20e3 commit 7fd3b9c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions integration/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import datetime
import io
import pathlib
import struct
import time
import uuid
from typing import Any, Callable, Dict, List, Optional, Sequence, TypedDict, Union

import numpy as np
import pytest

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


@pytest.mark.parametrize(
"objects, should_error",
[
(
[
DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])),
],
False,
),
(
[
DataObject(properties={"name": "some numpy one"}, vector=np.array([1, 2, 3])),
DataObject(properties={"name": "some numpy two"}, vector=np.array([11, 12, 13])),
],
False,
),
(
[
DataObject(
properties={"name": "some numpy 2d"}, vector=np.array([[1, 2, 3], [11, 12, 13]])
),
],
True,
),
],
)
def test_insert_many_with_numpy(
collection_factory: CollectionFactory,
objects: Sequence[DataObject[WeaviateProperties, Any]],
should_error: bool,
) -> None:
collection = collection_factory(
properties=[Property(name="Name", data_type=DataType.TEXT)],
vectorizer_config=Configure.Vectorizer.none(),
)
if not should_error:
ret = collection.data.insert_many(objects)
for idx, uuid_ in ret.uuids.items():
obj1 = collection.query.fetch_object_by_id(uuid_, include_vector=True)
inserted = objects[idx]
assert inserted.properties["name"] == obj1.properties["name"]
assert inserted.vector.tolist() == obj1.vector["default"] # type: ignore[union-attr]
else:
with pytest.raises(struct.error) as e:
collection.data.insert_many(objects)
assert str(e.value) == "required argument is not a float"


def test_insert_many_with_refs(collection_factory: CollectionFactory) -> None:
ref_collection = collection_factory(
name="target", vectorizer_config=Configure.Vectorizer.none()
Expand Down

0 comments on commit 7fd3b9c

Please sign in to comment.