Skip to content

Commit

Permalink
TEST: Extends #2569 to unpickle
Browse files Browse the repository at this point in the history
  • Loading branch information
Carwyn Pelley committed Jun 16, 2017
1 parent 8de737b commit 665875a
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions lib/iris/tests/integration/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,43 @@
from iris.fileformats.grib.message import GribMessage


class Common(object):
def pickle_cube(self, path):
# Ensure that data proxies are pickleable.
cube = iris.load(path)[0]
with self.temp_filename('.pkl') as filename:
with open(filename, 'wb') as f:
pickle.dump(cube, f)
with open(filename, 'r') as f:
ncube = pickle.load(f)
self.assertEqual(ncube, cube)


@tests.skip_data
@tests.skip_grib
class TestGribMessage(tests.IrisTest):
def test(self):
# Check that a GribMessage pickles without errors.
path = tests.get_data_path(('GRIB', 'fp_units', 'hours.grib2'))
messages = GribMessage.messages_from_filename(path)
message = next(messages)
class TestGribMessage(Common, tests.IrisTest):
def setUp(self):
self.path = tests.get_data_path(('GRIB', 'fp_units', 'hours.grib2'))

def pickle_obj(self, obj):
with self.temp_filename('.pkl') as filename:
with open(filename, 'wb') as f:
pickle.dump(message, f)
pickle.dump(obj, f)

def test(self):
# Check that a GribMessage pickles without errors.
messages = GribMessage.messages_from_filename(self.path)
obj = next(messages)
self.pickle_obj(obj)

def test_data(self):
# Check that GribMessage.data pickles without errors.
path = tests.get_data_path(('GRIB', 'fp_units', 'hours.grib2'))
messages = GribMessage.messages_from_filename(path)
message = next(messages)
with self.temp_filename('.pkl') as filename:
with open(filename, 'wb') as f:
pickle.dump(message.data, f)

messages = GribMessage.messages_from_filename(self.path)
obj = next(messages).data
self.pickle_obj(obj)

class Common(object):
# Ensure that data proxies are pickleable.
def pickle_cube(self, path):
cube = iris.load(path)[0]
with self.temp_filename('.pkl') as filename:
with open(filename, 'wb') as f:
pickle.dump(cube, f)
def test_roundtrip(self):
self.pickle_cube(self.path)


@tests.skip_data
Expand Down

0 comments on commit 665875a

Please sign in to comment.