Fix doc pickling test

This commit is contained in:
Matthew Honnibal 2017-10-17 18:19:57 +02:00
parent 9ce7d6af87
commit 8ca97f32a3

View File

@ -1,8 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import pickle
from ...language import Language from ...language import Language
from ...compat import pickle, unicode_
def test_pickle_single_doc(): def test_pickle_single_doc():
@ -15,11 +14,13 @@ def test_pickle_single_doc():
def test_list_of_docs_pickles_efficiently(): def test_list_of_docs_pickles_efficiently():
nlp = Language() nlp = Language()
for i in range(10000):
_ = nlp.vocab[unicode_(i)]
one_pickled = pickle.dumps(nlp(u'0'), -1) one_pickled = pickle.dumps(nlp(u'0'), -1)
docs = list(nlp.pipe(str(i) for i in range(100))) docs = list(nlp.pipe(unicode_(i) for i in range(100)))
many_pickled = pickle.dumps(docs, -1) many_pickled = pickle.dumps(docs, -1)
assert len(many_pickled) < (len(one_pickled) * 2) assert len(many_pickled) < (len(one_pickled) * 2)
many_unpickled = pickle.loads(many_pickled) many_unpickled = pickle.loads(many_pickled)
assert many_unpickled[0].text == '0' assert many_unpickled[0].text == '0'
assert many_unpickled[-1].text == '99' assert many_unpickled[-1].text == '99'
assert len(many_unpickled) == 99 assert len(many_unpickled) == 100