Skip to content

Commit

Permalink
Add more comprehensive test for document pickling
Browse files Browse the repository at this point in the history
  • Loading branch information
GodTamIt committed Aug 5, 2023
1 parent 21cb627 commit 634b158
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/tantivy_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from io import BytesIO

import copy
import datetime
import tantivy
import pickle
import pytest
Expand Down Expand Up @@ -567,8 +569,6 @@ def test_document(self):
assert doc.to_dict() == {"name": ["Bill"], "reference": [1, 2]}

def test_document_with_date(self):
import datetime

date = datetime.datetime(2019, 8, 12, 13, 0, 0)
doc = tantivy.Document(name="Bill", date=date)
assert doc["date"][0] == date
Expand Down Expand Up @@ -618,7 +618,18 @@ def test_document_copy(self):
assert doc2 == doc3

def test_document_pickle(self):
orig = Document(id=1, title="hello world!")
orig = Document()
orig.add_unsigned("unsigned", 1)
orig.add_integer("integer", 5)
orig.add_float("float", 1.0)
orig.add_date("birth", datetime.datetime(2019, 8, 12, 13, 0, 5))
orig.add_text("title", "hello world!")
orig.add_json("json", '{"a": 1, "b": 2}')
orig.add_bytes("bytes", b"abc")

facet = tantivy.Facet.from_string("/europe/france")
orig.add_facet("facet", facet)

pickled = pickle.loads(pickle.dumps(orig))

assert orig == pickled
Expand Down Expand Up @@ -764,6 +775,7 @@ def test_facet_pickle():

assert orig == pickled


def test_doc_address_pickle():
orig = tantivy.DocAddress(42, 123)
pickled = pickle.loads(pickle.dumps(orig))
Expand Down

0 comments on commit 634b158

Please sign in to comment.