spaCy/spacy/tests/test_pickle.py

28 lines
579 B
Python
Raw Normal View History

import cloudpickle
import io
import os
import pickle
import pytest
import tempfile
@pytest.mark.models
def test_pickle_english(EN):
2015-10-13 12:20:10 +03:00
file_ = io.BytesIO()
cloudpickle.dump(EN, file_)
file_.seek(0)
loaded = pickle.load(file_)
assert loaded is not None
@pytest.mark.models
def test_cloudpickle_to_file(EN):
f = tempfile.NamedTemporaryFile(delete=False)
p = cloudpickle.CloudPickler(f)
p.dump(EN)
f.close()
loaded_en = cloudpickle.load(open(f.name))
os.unlink(f.name)
doc = loaded_en(unicode('test parse'))
assert len(doc) == 2