2015-10-12 08:33:11 +00:00
|
|
|
import cloudpickle
|
2015-10-24 05:18:47 +00:00
|
|
|
import io
|
|
|
|
import os
|
2015-10-12 08:33:11 +00:00
|
|
|
import pickle
|
2015-10-24 05:18:47 +00:00
|
|
|
import pytest
|
|
|
|
import tempfile
|
2015-10-12 08:33:11 +00:00
|
|
|
|
2015-11-03 03:57:02 +00:00
|
|
|
try:
|
|
|
|
unicode
|
|
|
|
except NameError:
|
|
|
|
unicode = str
|
|
|
|
|
2015-10-12 08:33:11 +00:00
|
|
|
@pytest.mark.models
|
|
|
|
def test_pickle_english(EN):
|
2015-10-13 09:20:10 +00:00
|
|
|
file_ = io.BytesIO()
|
2015-10-12 08:33:11 +00:00
|
|
|
cloudpickle.dump(EN, file_)
|
|
|
|
|
|
|
|
file_.seek(0)
|
|
|
|
|
|
|
|
loaded = pickle.load(file_)
|
2015-10-24 05:18:47 +00:00
|
|
|
assert loaded is not None
|
2015-10-12 08:33:11 +00:00
|
|
|
|
2015-10-24 05:18:47 +00:00
|
|
|
@pytest.mark.models
|
|
|
|
def test_cloudpickle_to_file(EN):
|
|
|
|
f = tempfile.NamedTemporaryFile(delete=False)
|
|
|
|
p = cloudpickle.CloudPickler(f)
|
|
|
|
p.dump(EN)
|
|
|
|
f.close()
|
2015-11-03 03:57:02 +00:00
|
|
|
loaded_en = cloudpickle.load(open(f.name, 'rb'))
|
2015-10-24 05:18:47 +00:00
|
|
|
os.unlink(f.name)
|
|
|
|
doc = loaded_en(unicode('test parse'))
|
|
|
|
assert len(doc) == 2
|