Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move tests for count_documents from DocumentStoreBaseTests to separate class #6332

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions haystack/preview/testing/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,34 @@ def _random_embeddings(n):
return [random.random() for _ in range(n)]


class DocumentStoreBaseTests:
class CountDocumentsTest:
"""
Utility class to test a Document Store `count_documents` method.

To use it create a custom test class and override the `docstore` fixture to return your Document Store.
Example usage:

```python
class MyDocumentStoreTest(CountDocumentsTest):
@pytest.fixture
def docstore(self):
return MyDocumentStore()
```
"""

@pytest.mark.unit
def test_count_empty(self, docstore: DocumentStore):
assert docstore.count_documents() == 0

@pytest.mark.unit
def test_count_not_empty(self, docstore: DocumentStore):
docstore.write_documents(
[Document(content="test doc 1"), Document(content="test doc 2"), Document(content="test doc 3")]
)
assert docstore.count_documents() == 3


class DocumentStoreBaseTests(CountDocumentsTest):
@pytest.fixture
def docstore(self) -> DocumentStore:
raise NotImplementedError()
Expand Down Expand Up @@ -64,17 +91,6 @@ def filterable_docs(self) -> List[Document]:
)
return documents

@pytest.mark.unit
def test_count_empty(self, docstore: DocumentStore):
assert docstore.count_documents() == 0

@pytest.mark.unit
def test_count_not_empty(self, docstore: DocumentStore):
docstore.write_documents(
[Document(content="test doc 1"), Document(content="test doc 2"), Document(content="test doc 3")]
)
assert docstore.count_documents() == 3

@pytest.mark.unit
def test_no_filter_empty(self, docstore: DocumentStore):
assert docstore.filter_documents() == []
Expand Down