mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-08-31 20:03:38 +00:00

* add default_to_dict and default_from_dict placeholders to ease migration to canals 0.7.0 * canals==0.7.0 * whisper components * add to_dict/from_dict stubs * import serialization methods in init to hide canals imports * reno * export deserializationerror too * Update haystack/preview/__init__.py Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com> * serialization methods for LocalWhisperTranscriber (#5648) * chore: serialization methods for `FileExtensionClassifier` (#5651) * serialization methods for FileExtensionClassifier * Update test_file_classifier.py * chore: serialization methods for `SentenceTransformersDocumentEmbedder` (#5652) * serialization methods for SentenceTransformersDocumentEmbedder * fix device management * serialization methods for SentenceTransformersTextEmbedder (#5653) * serialization methods for TextFileToDocument (#5654) * chore: serialization methods for `RemoteWhisperTranscriber` (#5650) * serialization methods for RemoteWhisperTranscriber * remove patches * Add default to_dict and from_dict in document stores built with factory (#5674) * fix tests (#5671) * chore: simplify serialization methods for `MemoryDocumentStore` (#5667) * simplify serialization for MemoryDocumentStore * remove redundant tests * pylint * chore: serialization methods for `MemoryRetriever` (#5663) * serialization method for MemoryRetriever * more tests * remove hash from default_document_store_to_dict * remove diff in factory.py * chore: serialization methods for `DocumentWriter` (#5661) * serialization methods for DocumentWriter * more tests * use factory * black --------- Co-authored-by: Silvano Cerza <3314350+silvanocerza@users.noreply.github.com>
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
import pytest
|
|
|
|
from haystack.preview.dataclasses import Document
|
|
from haystack.preview.testing.factory import document_store_class
|
|
from haystack.preview.document_stores.decorator import document_store
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_document_store_class_default():
|
|
MyStore = document_store_class("MyStore")
|
|
store = MyStore()
|
|
assert store.count_documents() == 0
|
|
assert store.filter_documents() == []
|
|
assert store.write_documents([]) is None
|
|
assert store.delete_documents([]) is None
|
|
assert store.to_dict() == {"type": "MyStore", "init_parameters": {}}
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_document_store_from_dict():
|
|
MyStore = document_store_class("MyStore")
|
|
|
|
store = MyStore.from_dict({"type": "MyStore", "init_parameters": {}})
|
|
assert isinstance(store, MyStore)
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_document_store_class_is_registered():
|
|
MyStore = document_store_class("MyStore")
|
|
assert document_store.registry["MyStore"] == MyStore
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_document_store_class_with_documents():
|
|
doc = Document(id="fake_id", content="This is a document")
|
|
MyStore = document_store_class("MyStore", documents=[doc])
|
|
store = MyStore()
|
|
assert store.count_documents() == 1
|
|
assert store.filter_documents() == [doc]
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_document_store_class_with_documents_count():
|
|
MyStore = document_store_class("MyStore", documents_count=100)
|
|
store = MyStore()
|
|
assert store.count_documents() == 100
|
|
assert store.filter_documents() == []
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_document_store_class_with_documents_and_documents_count():
|
|
doc = Document(id="fake_id", content="This is a document")
|
|
MyStore = document_store_class("MyStore", documents=[doc], documents_count=100)
|
|
store = MyStore()
|
|
assert store.count_documents() == 100
|
|
assert store.filter_documents() == [doc]
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_document_store_class_with_bases():
|
|
MyStore = document_store_class("MyStore", bases=(Exception,))
|
|
store = MyStore()
|
|
assert isinstance(store, Exception)
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_document_store_class_with_extra_fields():
|
|
MyStore = document_store_class("MyStore", extra_fields={"my_field": 10})
|
|
store = MyStore()
|
|
assert store.my_field == 10
|