Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon committed Dec 17, 2024
1 parent da31fe0 commit 0c0422b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing-dependency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
# - 4.1.0
- 4.3.3
protobuf_version:
- 4.25.3
- 5.28
protoc-gen-openapiv2:
- 0.0.1
googleapis_common_protos_version:
Expand Down
7 changes: 2 additions & 5 deletions pinecone/grpc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
Usage,
ScoredVector,
SparseValues,
FetchResponse,
QueryResponse,
IndexDescription as DescribeIndexStatsResponse,
NamespaceSummary,
)
from pinecone.data.dataclasses import FetchResponse

from google.protobuf.struct_pb2 import Struct

Expand Down Expand Up @@ -55,10 +55,7 @@ def parse_fetch_response(response: Message):
)

return FetchResponse(
vectors=vd,
namespace=namespace,
usage=parse_usage(json_response.get("usage", {})),
_check_type=False,
vectors=vd, namespace=namespace, usage=parse_usage(json_response.get("usage", {}))
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
from pinecone import PineconeApiTypeError
from pinecone import PineconeApiException


class TestCreateIndexTypeErrorCases:
def test_create_index_with_invalid_str_dimension(self, client, create_sl_index_params):
create_sl_index_params["dimension"] = "10"
with pytest.raises(PineconeApiTypeError):
with pytest.raises(PineconeApiException):
client.create_index(**create_sl_index_params)

def test_create_index_with_missing_dimension(self, client, create_sl_index_params):
Expand Down
30 changes: 18 additions & 12 deletions tests/integration/data/test_fetch_future.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from ..helpers import poll_fetch_for_ids_in_namespace, embedding_values
from ..helpers import poll_fetch_for_ids_in_namespace, embedding_values, random_string
from pinecone import Vector
import logging

Expand All @@ -10,8 +10,14 @@
from pinecone.grpc import PineconeGrpcFuture


@pytest.fixture(scope="session")
def fetch_namespace_future():
return random_string(10)


@pytest.mark.usefixtures("fetch_namespace_future")
@pytest.fixture(scope="class")
def seed_for_fetch(idx, namespace):
def seed_for_fetch(idx, fetch_namespace_future):
# Upsert without metadata
logger.info("Seeding vectors without metadata")
idx.upsert(
Expand All @@ -20,7 +26,7 @@ def seed_for_fetch(idx, namespace):
("2", embedding_values(2)),
("3", embedding_values(2)),
],
namespace=namespace,
namespace=fetch_namespace_future,
)

# Upsert with metadata
Expand All @@ -35,7 +41,7 @@ def seed_for_fetch(idx, namespace):
id="6", values=embedding_values(2), metadata={"genre": "romance", "runtime": 240}
),
],
namespace=namespace,
namespace=fetch_namespace_future,
)

# Upsert with dict
Expand All @@ -45,11 +51,11 @@ def seed_for_fetch(idx, namespace):
{"id": "8", "values": embedding_values(2)},
{"id": "9", "values": embedding_values(2)},
],
namespace=namespace,
namespace=fetch_namespace_future,
)

poll_fetch_for_ids_in_namespace(
idx, ids=["1", "2", "3", "4", "5", "6", "7", "8", "9"], namespace=namespace
idx, ids=["1", "2", "3", "4", "5", "6", "7", "8", "9"], namespace=fetch_namespace_future
)
yield

Expand All @@ -62,8 +68,8 @@ class TestFetchFuture:
def setup_method(self):
self.expected_dimension = 2

def test_fetch_multiple_by_id(self, idx, namespace):
target_namespace = namespace
def test_fetch_multiple_by_id(self, idx, fetch_namespace_future):
target_namespace = fetch_namespace_future

results = idx.fetch(ids=["1", "2", "4"], namespace=target_namespace, async_req=True)
assert isinstance(results, PineconeGrpcFuture)
Expand Down Expand Up @@ -91,8 +97,8 @@ def test_fetch_multiple_by_id(self, idx, namespace):
assert results.vectors["1"].values is not None
assert len(results.vectors["1"].values) == self.expected_dimension

def test_fetch_single_by_id(self, idx, namespace):
target_namespace = namespace
def test_fetch_single_by_id(self, idx, fetch_namespace_future):
target_namespace = fetch_namespace_future

future = idx.fetch(ids=["1"], namespace=target_namespace, async_req=True)

Expand All @@ -108,8 +114,8 @@ def test_fetch_single_by_id(self, idx, namespace):
assert results.vectors["1"].values is not None
assert len(results.vectors["1"].values) == self.expected_dimension

def test_fetch_nonexistent_id(self, idx, namespace):
target_namespace = namespace
def test_fetch_nonexistent_id(self, idx, fetch_namespace_future):
target_namespace = fetch_namespace_future

# Fetch id that is missing
future = idx.fetch(ids=["100"], namespace=target_namespace, async_req=True)
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/data/test_list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import pytest
from pinecone import Vector
from ..helpers import poll_fetch_for_ids_in_namespace, embedding_values, random_string

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -40,7 +39,6 @@ def test_list_no_args(self, idx):
assert results is not None
assert results.namespace == ""
assert results.vectors is not None
assert isinstance(results.vectors, list)
# assert results.pagination == None

def test_list_when_limit(self, idx, list_namespace):
Expand Down Expand Up @@ -138,7 +136,6 @@ def test_list_then_fetch(self, idx, list_namespace):
vectors.extend([v for _, v in result.vectors.items()])

assert len(vectors) == 11
assert isinstance(vectors[0], Vector)
assert set([v.id for v in vectors]) == set(
["99", "990", "991", "992", "993", "994", "995", "996", "997", "998", "999"]
)
2 changes: 1 addition & 1 deletion tests/integration/data/test_upsert_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_upsert_fails_when_values_missing_dicts(self, idx):

class TestUpsertFailsWhenValuesWrongType:
def test_upsert_fails_when_values_wrong_type_objects(self, idx):
with pytest.raises(PineconeException):
with pytest.raises(Exception):
idx.upsert(vectors=[Vector(id="1", values="abc"), Vector(id="2", values="def")])

def test_upsert_fails_when_values_wrong_type_tuples(self, idx):
Expand Down
16 changes: 11 additions & 5 deletions tests/integration/data/test_upsert_future.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import pytest
import os
from pinecone import Vector, PineconeException
from ..helpers import poll_stats_for_namespace, embedding_values
from ..helpers import poll_stats_for_namespace, embedding_values, random_string


@pytest.fixture(scope="class")
def namespace_query_async():
return random_string(10)


@pytest.mark.usefixtures("namespace_query_async")
class TestUpsertWithAsyncReq:
@pytest.mark.skipif(
os.getenv("USE_GRPC") != "true", reason="PineconeGrpcFutures only returned from grpc client"
)
def test_upsert_to_namespace(self, idx, namespace):
target_namespace = namespace
def test_upsert_to_namespace(self, idx, namespace_query_async):
target_namespace = namespace_query_async

# Upsert with tuples
upsert1 = idx.upsert(
Expand Down Expand Up @@ -63,8 +69,8 @@ def test_upsert_to_namespace(self, idx, namespace):
@pytest.mark.skipif(
os.getenv("USE_GRPC") != "true", reason="PineconeGrpcFutures only returned from grpc client"
)
def test_upsert_to_namespace_when_failed_req(self, idx, namespace):
target_namespace = namespace
def test_upsert_to_namespace_when_failed_req(self, idx, namespace_query_async):
target_namespace = namespace_query_async

# Upsert with tuples
upsert1 = idx.upsert(
Expand Down

0 comments on commit 0c0422b

Please sign in to comment.