2017-03-07 16:15:18 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import io
|
2017-03-07 19:58:55 +00:00
|
|
|
import pytest
|
|
|
|
import dill as pickle
|
2017-03-07 16:15:18 +00:00
|
|
|
|
|
|
|
from ..strings import StringStore
|
2017-03-07 19:58:55 +00:00
|
|
|
from ..vocab import Vocab
|
|
|
|
from ..attrs import NORM
|
2017-03-07 16:15:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_pickle_string_store():
|
|
|
|
sstore = StringStore()
|
|
|
|
hello = sstore['hello']
|
|
|
|
bye = sstore['bye']
|
|
|
|
bdata = pickle.dumps(sstore, protocol=-1)
|
|
|
|
unpickled = pickle.loads(bdata)
|
|
|
|
assert unpickled['hello'] == hello
|
|
|
|
assert unpickled['bye'] == bye
|
2017-03-07 19:58:55 +00:00
|
|
|
assert len(sstore) == len(unpickled)
|
2017-03-07 16:15:18 +00:00
|
|
|
|
2017-03-07 19:58:55 +00:00
|
|
|
|
|
|
|
def test_pickle_vocab():
|
|
|
|
vocab = Vocab(lex_attr_getters={int(NORM): lambda string: string[:-1]})
|
|
|
|
dog = vocab[u'dog']
|
|
|
|
cat = vocab[u'cat']
|
|
|
|
assert dog.norm_ == 'do'
|
|
|
|
assert cat.norm_ == 'ca'
|
|
|
|
|
|
|
|
bdata = pickle.dumps(vocab)
|
|
|
|
unpickled = pickle.loads(bdata)
|
|
|
|
|
|
|
|
assert unpickled[u'dog'].orth == dog.orth
|
|
|
|
assert unpickled[u'cat'].orth == cat.orth
|
|
|
|
assert unpickled[u'dog'].norm == dog.norm
|
|
|
|
assert unpickled[u'cat'].norm == cat.norm
|
|
|
|
dog_ = unpickled[u'dog']
|
|
|
|
cat_ = unpickled[u'cat']
|
|
|
|
assert dog_.norm != cat_.norm
|