From 55239b972d9443a67c8e404b812460791810be9b Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Mon, 22 Jan 2024 17:15:08 +0100 Subject: [PATCH] fix tests --- integrations/pinecone/pyproject.toml | 8 +- .../retrievers/pinecone/dense_retriever.py | 1 + integrations/pinecone/tests/conftest.py | 1 + .../pinecone/tests/test_dense_retriever.py | 1 + .../pinecone/tests/test_document_store.py | 79 ++++++++++--------- 5 files changed, 48 insertions(+), 42 deletions(-) diff --git a/integrations/pinecone/pyproject.toml b/integrations/pinecone/pyproject.toml index f11fa0f68..2d73cdf58 100644 --- a/integrations/pinecone/pyproject.toml +++ b/integrations/pinecone/pyproject.toml @@ -146,7 +146,7 @@ unfixable = [ ] [tool.ruff.isort] -known-first-party = ["pinecone_haystack"] +known-first-party = ["haystack_integrations"] [tool.ruff.flake8-tidy-imports] ban-relative-imports = "parents" @@ -156,7 +156,7 @@ ban-relative-imports = "parents" "tests/**/*" = ["PLR2004", "S101", "TID252"] [tool.coverage.run] -source_pkgs = ["pinecone_haystack", "tests"] +source_pkgs = ["src", "tests"] branch = true parallel = true omit = [ @@ -164,8 +164,8 @@ omit = [ ] [tool.coverage.paths] -pinecone_haystack = ["src/pinecone_haystack", "*/pinecone_haystack/src/pinecone_haystack"] -tests = ["tests", "*/pinecone_haystack/tests"] +pinecone_haystack = ["src/*"] +tests = ["tests"] [tool.coverage.report] exclude_lines = [ diff --git a/integrations/pinecone/src/haystack_integrations/components/retrievers/pinecone/dense_retriever.py b/integrations/pinecone/src/haystack_integrations/components/retrievers/pinecone/dense_retriever.py index d9715a465..279ef4977 100644 --- a/integrations/pinecone/src/haystack_integrations/components/retrievers/pinecone/dense_retriever.py +++ b/integrations/pinecone/src/haystack_integrations/components/retrievers/pinecone/dense_retriever.py @@ -5,6 +5,7 @@ from haystack import component, default_from_dict, default_to_dict from haystack.dataclasses import Document + from haystack_integrations.document_stores.pinecone import PineconeDocumentStore diff --git a/integrations/pinecone/tests/conftest.py b/integrations/pinecone/tests/conftest.py index f2947cffc..c7a1342d5 100644 --- a/integrations/pinecone/tests/conftest.py +++ b/integrations/pinecone/tests/conftest.py @@ -2,6 +2,7 @@ import pytest from haystack.document_stores.types import DuplicatePolicy + from haystack_integrations.document_stores.pinecone import PineconeDocumentStore # This is the approximate time it takes for the documents to be available diff --git a/integrations/pinecone/tests/test_dense_retriever.py b/integrations/pinecone/tests/test_dense_retriever.py index 1e0961338..e0f6dc375 100644 --- a/integrations/pinecone/tests/test_dense_retriever.py +++ b/integrations/pinecone/tests/test_dense_retriever.py @@ -4,6 +4,7 @@ from unittest.mock import Mock, patch from haystack.dataclasses import Document + from haystack_integrations.components.retrievers.pinecone import PineconeDenseRetriever from haystack_integrations.document_stores.pinecone import PineconeDocumentStore diff --git a/integrations/pinecone/tests/test_document_store.py b/integrations/pinecone/tests/test_document_store.py index fc2462e6d..6da66aa5c 100644 --- a/integrations/pinecone/tests/test_document_store.py +++ b/integrations/pinecone/tests/test_document_store.py @@ -4,9 +4,50 @@ import pytest from haystack import Document from haystack.testing.document_store import CountDocumentsTest, DeleteDocumentsTest, WriteDocumentsTest + from haystack_integrations.document_stores.pinecone import PineconeDocumentStore +@patch("haystack_integrations.document_stores.pinecone.document_store.pinecone") +def test_init(mock_pinecone): + mock_pinecone.Index.return_value.describe_index_stats.return_value = {"dimension": 30} + + document_store = PineconeDocumentStore( + api_key="fake-api-key", + environment="gcp-starter", + index="my_index", + namespace="test", + batch_size=50, + dimension=30, + metric="euclidean", + ) + + mock_pinecone.init.assert_called_with(api_key="fake-api-key", environment="gcp-starter") + + assert document_store.environment == "gcp-starter" + assert document_store.index == "my_index" + assert document_store.namespace == "test" + assert document_store.batch_size == 50 + assert document_store.dimension == 30 + assert document_store.index_creation_kwargs == {"metric": "euclidean"} + + +@patch("haystack_integrations.document_stores.pinecone.document_store.pinecone") +def test_init_api_key_in_environment_variable(mock_pinecone, monkeypatch): + monkeypatch.setenv("PINECONE_API_KEY", "fake-api-key") + + PineconeDocumentStore( + environment="gcp-starter", + index="my_index", + namespace="test", + batch_size=50, + dimension=30, + metric="euclidean", + ) + + mock_pinecone.init.assert_called_with(api_key="fake-api-key", environment="gcp-starter") + + @pytest.mark.integration class TestDocumentStore(CountDocumentsTest, DeleteDocumentsTest, WriteDocumentsTest): def test_write_documents(self, document_store: PineconeDocumentStore): @@ -21,44 +62,6 @@ def test_write_documents_duplicate_fail(self, document_store: PineconeDocumentSt def test_write_documents_duplicate_skip(self, document_store: PineconeDocumentStore): ... - @patch("pinecone_haystack.document_store.pinecone") - def test_init(self, mock_pinecone): - mock_pinecone.Index.return_value.describe_index_stats.return_value = {"dimension": 30} - - document_store = PineconeDocumentStore( - api_key="fake-api-key", - environment="gcp-starter", - index="my_index", - namespace="test", - batch_size=50, - dimension=30, - metric="euclidean", - ) - - mock_pinecone.init.assert_called_with(api_key="fake-api-key", environment="gcp-starter") - - assert document_store.environment == "gcp-starter" - assert document_store.index == "my_index" - assert document_store.namespace == "test" - assert document_store.batch_size == 50 - assert document_store.dimension == 30 - assert document_store.index_creation_kwargs == {"metric": "euclidean"} - - @patch("pinecone_haystack.document_store.pinecone") - def test_init_api_key_in_environment_variable(self, mock_pinecone, monkeypatch): - monkeypatch.setenv("PINECONE_API_KEY", "fake-api-key") - - PineconeDocumentStore( - environment="gcp-starter", - index="my_index", - namespace="test", - batch_size=50, - dimension=30, - metric="euclidean", - ) - - mock_pinecone.init.assert_called_with(api_key="fake-api-key", environment="gcp-starter") - def test_init_fails_wo_api_key(self, monkeypatch): api_key = None monkeypatch.delenv("PINECONE_API_KEY", raising=False)