Skip to content

Commit

Permalink
Move tests for count_document from DocumentStoreBaseTests to separate…
Browse files Browse the repository at this point in the history
… class (#6332)
  • Loading branch information
silvanocerza authored Nov 17, 2023
1 parent 68be0d7 commit 326f51d
Showing 1 changed file with 28 additions and 12 deletions.
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

0 comments on commit 326f51d

Please sign in to comment.