Skip to content

Commit 4fcaba3

Browse files
committed
add tests for exception import path
1 parent aef41b8 commit 4fcaba3

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

tests/integration/inference/test_embed.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import pytest
12
from pinecone import Pinecone
23
from pinecone.grpc import PineconeGRPC
4+
from pinecone.exceptions import PineconeApiException
35

46

57
class TestInferencePlugin:
@@ -32,3 +34,15 @@ def test_embed_grpc(self, api_key):
3234
assert len(embeddings.get("data")[0]["values"]) == 1024
3335
assert len(embeddings.get("data")[1]["values"]) == 1024
3436
assert embeddings.get("model") == embedding_model
37+
38+
def test_embed_exception(self, api_key):
39+
pc = Pinecone(api_key=api_key)
40+
41+
with pytest.raises(PineconeApiException) as e_info:
42+
embedding_model = "DOES NOT EXIST"
43+
pc.inference.embed(
44+
model=embedding_model,
45+
inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"],
46+
parameters={"input_type": "query", "truncate": "END"},
47+
)
48+
assert e_info.value.status == 404

tests/integration/inference/test_rerank.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import pytest
12
from pinecone import Pinecone
23
from pinecone.grpc import PineconeGRPC
4+
from pinecone.exceptions import PineconeApiException
35

46

57
class TestInferencePluginRerank:
@@ -10,7 +12,11 @@ def test_rerank(self, api_key):
1012
result = pc.inference.rerank(
1113
model=model,
1214
query="i love dogs",
13-
documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"],
15+
documents=[
16+
"dogs are pretty cool",
17+
"everyone loves dogs",
18+
"I'm a cat person",
19+
],
1420
top_n=1,
1521
return_documents=True,
1622
)
@@ -28,7 +34,11 @@ def test_rerank_grpc(self, api_key):
2834
result = pc.inference.rerank(
2935
model=model,
3036
query="i love dogs",
31-
documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"],
37+
documents=[
38+
"dogs are pretty cool",
39+
"everyone loves dogs",
40+
"I'm a cat person",
41+
],
3242
top_n=1,
3343
return_documents=True,
3444
)
@@ -38,3 +48,20 @@ def test_rerank_grpc(self, api_key):
3848
assert result.model == model
3949
assert isinstance(result.usage.rerank_units, int)
4050
assert result.usage.rerank_units == 1
51+
52+
def test_rerank_exception(self, api_key):
53+
pc = Pinecone(api_key=api_key)
54+
with pytest.raises(PineconeApiException) as e_info:
55+
pc.inference.rerank(
56+
model="DOES NOT EXIST",
57+
query="i love dogs",
58+
documents=[
59+
"dogs are pretty cool",
60+
"everyone loves dogs",
61+
"I'm a cat person",
62+
],
63+
rank_fields=["custom-field"],
64+
top_n=1,
65+
return_documents=True,
66+
)
67+
assert e_info.value.status == 404

0 commit comments

Comments
 (0)