From 9f915525663130ce65a59ba3e39875be90c971f0 Mon Sep 17 00:00:00 2001 From: cpelley Date: Tue, 9 Jul 2019 11:08:35 +0100 Subject: [PATCH 1/5] TEST: Extends #2569 to unpickle --- lib/iris/tests/integration/test_pickle.py | 79 +++++++++++++---------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/lib/iris/tests/integration/test_pickle.py b/lib/iris/tests/integration/test_pickle.py index a6506ea91e..2e6914f8ac 100644 --- a/lib/iris/tests/integration/test_pickle.py +++ b/lib/iris/tests/integration/test_pickle.py @@ -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,69 @@ 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 +@unittest.expectedFailure +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) + + 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. + 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__': From 22543c05e26d37df49db260bc8aac4c08b495c15 Mon Sep 17 00:00:00 2001 From: cpelley Date: Tue, 9 Jul 2019 11:36:53 +0100 Subject: [PATCH 2/5] Decorator re-ordering --- lib/iris/tests/integration/test_pickle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/tests/integration/test_pickle.py b/lib/iris/tests/integration/test_pickle.py index 2e6914f8ac..9068714c4c 100644 --- a/lib/iris/tests/integration/test_pickle.py +++ b/lib/iris/tests/integration/test_pickle.py @@ -53,9 +53,9 @@ def test_protocol_2(self): self.pickle_cube(2) +@unittest.expectedFailure @tests.skip_data @tests.skip_grib -@unittest.expectedFailure class TestGribMessage(Common, tests.IrisTest): def setUp(self): self.path = tests.get_data_path(('GRIB', 'fp_units', 'hours.grib2')) From f07409a5cbccaaf21932b5b055050db0841fa4ab Mon Sep 17 00:00:00 2001 From: cpelley Date: Tue, 9 Jul 2019 14:53:07 +0100 Subject: [PATCH 3/5] MAINT: Review changes --- lib/iris/tests/integration/test_pickle.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/iris/tests/integration/test_pickle.py b/lib/iris/tests/integration/test_pickle.py index 9068714c4c..c8edb31cb0 100644 --- a/lib/iris/tests/integration/test_pickle.py +++ b/lib/iris/tests/integration/test_pickle.py @@ -53,7 +53,6 @@ def test_protocol_2(self): self.pickle_cube(2) -@unittest.expectedFailure @tests.skip_data @tests.skip_grib class TestGribMessage(Common, tests.IrisTest): @@ -65,12 +64,14 @@ def pickle_obj(self, obj): with open(filename, 'wb') as f: pickle.dump(obj, f) + @unittest.expectedFailure def test(self): # Check that a GribMessage pickles without errors. messages = GribMessage.messages_from_filename(self.path) obj = next(messages) self.pickle_obj(obj) + @unittest.expectedFailure def test_data(self): # Check that GribMessage.data pickles without errors. messages = GribMessage.messages_from_filename(self.path) From bad4de43fe3aa4b43d72cb1a18e17f89e9c1e51e Mon Sep 17 00:00:00 2001 From: cpelley Date: Tue, 9 Jul 2019 15:10:03 +0100 Subject: [PATCH 4/5] MAINT: Review changes --- lib/iris/tests/integration/test_pickle.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/iris/tests/integration/test_pickle.py b/lib/iris/tests/integration/test_pickle.py index c8edb31cb0..80f4e43a39 100644 --- a/lib/iris/tests/integration/test_pickle.py +++ b/lib/iris/tests/integration/test_pickle.py @@ -65,13 +65,23 @@ def pickle_obj(self, obj): pickle.dump(obj, f) @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) - @unittest.expectedFailure def test_data(self): # Check that GribMessage.data pickles without errors. messages = GribMessage.messages_from_filename(self.path) From 665fd147593bb346ce3637ba172e9bf46f469295 Mon Sep 17 00:00:00 2001 From: cpelley Date: Wed, 10 Jul 2019 10:54:44 +0100 Subject: [PATCH 5/5] MAINT: Review changes --- lib/iris/tests/integration/test_pickle.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/iris/tests/integration/test_pickle.py b/lib/iris/tests/integration/test_pickle.py index 80f4e43a39..779602964b 100644 --- a/lib/iris/tests/integration/test_pickle.py +++ b/lib/iris/tests/integration/test_pickle.py @@ -64,6 +64,8 @@ def pickle_obj(self, obj): with open(filename, 'wb') as 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()