Skip to content

Commit

Permalink
Move generic filter_documents tests from DocumentStoreBaseTests to se…
Browse files Browse the repository at this point in the history
…parate class
  • Loading branch information
silvanocerza committed Nov 17, 2023
1 parent 9f064ac commit 963eb0e
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions haystack/preview/testing/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,20 @@ def filterable_docs(self) -> List[Document]:
return documents


class DocumentStoreBaseTests(CountDocumentsTest, WriteDocumentsTest, DeleteDocumentsTest, FilterableDocsFixtureMixin):
@pytest.fixture
def docstore(self) -> DocumentStore:
raise NotImplementedError()
class LegacyFilterDocumentsTest(FilterableDocsFixtureMixin):
"""
Utility class to test a Document Store `filter_documents` method using different types of legacy filters
To use it create a custom test class and override the `docstore` fixture to return your Document Store.
Example usage:
```python
class MyDocumentStoreTest(LegacyFilterDocumentsTest):
@pytest.fixture
def docstore(self):
return MyDocumentStore()
```
"""

@pytest.mark.unit
def test_no_filter_empty(self, docstore: DocumentStore):
Expand All @@ -208,6 +218,12 @@ def test_no_filter_not_empty(self, docstore: DocumentStore):
assert docstore.filter_documents() == docs
assert docstore.filter_documents(filters={}) == docs


class DocumentStoreBaseTests(CountDocumentsTest, WriteDocumentsTest, DeleteDocumentsTest, LegacyFilterDocumentsTest):
@pytest.fixture
def docstore(self) -> DocumentStore:
raise NotImplementedError()

@pytest.mark.unit
def test_filter_simple_metadata_value(self, docstore: DocumentStore, filterable_docs: List[Document]):
docstore.write_documents(filterable_docs)
Expand Down

0 comments on commit 963eb0e

Please sign in to comment.