Skip to content

Commit

Permalink
edit tests to reference most recent pickle protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenworsley committed Feb 26, 2025
1 parent f54115b commit 307be7a
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions lib/iris/tests/integration/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,43 @@
import iris.tests as tests # isort:skip

import pickle
import pytest

import iris


class Common:
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(cube, f, protocol)
with open(filename, "rb") as f:
ncube = pickle.load(f)
self.assertEqual(ncube, cube)
MIN_PICKLE_PROTOCOL = 4
TESTED_PROTOCOLS = list(range(MIN_PICKLE_PROTOCOL, pickle.HIGHEST_PROTOCOL + 1))

def test_protocol_0(self):
self.pickle_cube(0)

def test_protocol_1(self):
self.pickle_cube(1)

def test_protocol_2(self):
self.pickle_cube(2)
def pickle_cube(path, protocol):
# 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, protocol)
with open(filename, "rb") as f:
ncube = pickle.load(f)
assert ncube == cube


@pytest.mark.parametrize("protocol", TESTED_PROTOCOLS)
@tests.skip_data
class test_netcdf(Common, tests.IrisTest):
def setUp(self):
self.path = tests.get_data_path(
("NetCDF", "global", "xyt", "SMALL_hires_wind_u_for_ipcc4.nc")
)
def test_netcdf(protocol):
path = tests.get_data_path(
("NetCDF", "global", "xyt", "SMALL_hires_wind_u_for_ipcc4.nc")
)
pickle_cube(path, protocol)


@pytest.mark.parametrize("protocol", TESTED_PROTOCOLS)
@tests.skip_data
class test_pp(Common, tests.IrisTest):
def setUp(self):
self.path = tests.get_data_path(("PP", "aPPglob1", "global.pp"))
def test_pp(protocol):
path = tests.get_data_path(("PP", "aPPglob1", "global.pp"))
pickle_cube(path, protocol)


@pytest.mark.parametrize("protocol", TESTED_PROTOCOLS)
@tests.skip_data
class test_ff(Common, tests.IrisTest):
def setUp(self):
self.path = tests.get_data_path(("FF", "n48_multi_field"))


if __name__ == "__main__":
tests.main()
def test_ff(protocol):
self.path = tests.get_data_path(("FF", "n48_multi_field"))
pickle_cube(path, protocol)

0 comments on commit 307be7a

Please sign in to comment.