-
Notifications
You must be signed in to change notification settings - Fork 283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TEST: Extends #2569 to unpickle #2608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# (C) British Crown Copyright 2014 - 2017, Met Office | ||
# (C) British Crown Copyright 2014 - 2019, Met Office | ||
# | ||
# This file is part of Iris. | ||
# | ||
|
@@ -23,6 +23,7 @@ | |
# importing anything else. | ||
import iris.tests as tests | ||
|
||
import unittest | ||
import six.moves.cPickle as pickle | ||
|
||
import iris | ||
|
@@ -31,57 +32,82 @@ | |
from iris_grib.message import GribMessage | ||
|
||
|
||
@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 Common(object): | ||
def pickle_cube(self, protocol): | ||
# Ensure that data proxies are pickleable. | ||
cube = iris.load(self.path)[0] | ||
with self.temp_filename('.pkl') as filename: | ||
with open(filename, 'wb') as f: | ||
pickle.dump(message, f) | ||
pickle.dump(cube, f, protocol) | ||
with open(filename, 'rb') as f: | ||
ncube = pickle.load(f) | ||
self.assertEqual(ncube, cube) | ||
|
||
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) | ||
def test_protocol_0(self): | ||
self.pickle_cube(0) | ||
|
||
def test_protocol_1(self): | ||
self.pickle_cube(1) | ||
|
||
class Common(object): | ||
# Ensure that data proxies are pickleable. | ||
def pickle_cube(self, path): | ||
cube = iris.load(path)[0] | ||
def test_protocol_2(self): | ||
self.pickle_cube(2) | ||
|
||
|
||
@tests.skip_data | ||
@tests.skip_grib | ||
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(cube, f) | ||
pickle.dump(obj, f) | ||
|
||
# These probably "ought" to work, but currently fail. | ||
# see https://github.com/SciTools/iris/pull/2608 | ||
@unittest.expectedFailure | ||
def test_protocol_0(self): | ||
super(TestGribMessage, self).test_protocol_0() | ||
|
||
@unittest.expectedFailure | ||
def test_protocol_1(self): | ||
super(TestGribMessage, self).test_protocol_1() | ||
|
||
@unittest.expectedFailure | ||
def test_protocol_2(self): | ||
super(TestGribMessage, self).test_protocol_2() | ||
|
||
def test(self): | ||
# Check that a GribMessage pickles without errors. | ||
messages = GribMessage.messages_from_filename(self.path) | ||
obj = next(messages) | ||
self.pickle_obj(obj) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cpelley Is the test simply that there are no exceptions raised by There are no explicit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right, these are the original two tests from this module which I refactored only to perform a common pickle dump (self.pickle_obj). I have added I do not know enough about grib to understand whether |
||
|
||
def test_data(self): | ||
# Check that GribMessage.data pickles without errors. | ||
messages = GribMessage.messages_from_filename(self.path) | ||
obj = next(messages).data | ||
self.pickle_obj(obj) | ||
|
||
|
||
@tests.skip_data | ||
class test_netcdf(Common, tests.IrisTest): | ||
def test(self): | ||
path = tests.get_data_path(('NetCDF', 'global', 'xyt', | ||
'SMALL_hires_wind_u_for_ipcc4.nc')) | ||
self.pickle_cube(path) | ||
def setUp(self): | ||
self.path = tests.get_data_path(('NetCDF', 'global', 'xyt', | ||
'SMALL_hires_wind_u_for_ipcc4.nc')) | ||
|
||
|
||
@tests.skip_data | ||
class test_pp(Common, tests.IrisTest): | ||
def test(self): | ||
path = tests.get_data_path(('PP', 'aPPglob1', 'global.pp')) | ||
self.pickle_cube(path) | ||
def setUp(self): | ||
self.path = tests.get_data_path(('PP', 'aPPglob1', 'global.pp')) | ||
|
||
|
||
@tests.skip_data | ||
class test_ff(Common, tests.IrisTest): | ||
def test(self): | ||
path = tests.get_data_path(('FF', 'n48_multi_field')) | ||
self.pickle_cube(path) | ||
def setUp(self): | ||
self.path = tests.get_data_path(('FF', 'n48_multi_field')) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpelley Now we're exclusively Python3, isn't this now simply
super().test_protocol_0()
?If true, also applies through out. Fix this and I'll merge 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpelley This'll all be resolved by #3457, so let's bank some progress 👍