Reformat pickle tests

This commit is contained in:
ines 2017-03-15 17:39:54 +01:00
parent 2a0fcf1354
commit 4cfc8ffbd2

View File

@ -1,40 +1,36 @@
# coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import io
import pytest import pytest
import dill as pickle import dill as pickle
from ..strings import StringStore
from ..vocab import Vocab from ..vocab import Vocab
from ..attrs import NORM from ..attrs import NORM
def test_pickle_string_store(): @pytest.mark.parametrize('text1,text2', [('hello', 'bye')])
sstore = StringStore() def test_pickle_string_store(stringstore, text1, text2):
hello = sstore['hello'] store1 = stringstore[text1]
bye = sstore['bye'] store2 = stringstore[text2]
bdata = pickle.dumps(sstore, protocol=-1) data = pickle.dumps(stringstore, protocol=-1)
unpickled = pickle.loads(bdata) unpickled = pickle.loads(data)
assert unpickled['hello'] == hello assert unpickled[text1] == store1
assert unpickled['bye'] == bye assert unpickled[text2] == store2
assert len(sstore) == len(unpickled) assert len(stringstore) == len(unpickled)
@pytest.mark.xfail @pytest.mark.xfail
def test_pickle_vocab(): @pytest.mark.parametrize('text1,text2', [('dog', 'cat')])
def test_pickle_vocab(text1, text2):
vocab = Vocab(lex_attr_getters={int(NORM): lambda string: string[:-1]}) vocab = Vocab(lex_attr_getters={int(NORM): lambda string: string[:-1]})
dog = vocab[u'dog'] lex1 = vocab[text1]
cat = vocab[u'cat'] lex2 = vocab[text2]
assert dog.norm_ == 'do' assert lex1.norm_ == text1[:-1]
assert cat.norm_ == 'ca' assert lex2.norm_ == text2[:-1]
data = pickle.dumps(vocab)
bdata = pickle.dumps(vocab) unpickled = pickle.loads(data)
unpickled = pickle.loads(bdata) assert unpickled[text1].orth == lex1.orth
assert unpickled[text2].orth == lex2.orth
assert unpickled[u'dog'].orth == dog.orth assert unpickled[text1].norm == lex1.norm
assert unpickled[u'cat'].orth == cat.orth assert unpickled[text2].norm == lex2.norm
assert unpickled[u'dog'].norm == dog.norm assert unpickled[text1].norm != unpickled[text2].norm
assert unpickled[u'cat'].norm == cat.norm
dog_ = unpickled[u'dog']
cat_ = unpickled[u'cat']
assert dog_.norm != cat_.norm