From 37bb689a49a5618d85027534bf170d66c269191c Mon Sep 17 00:00:00 2001 From: Patrick Peglar Date: Tue, 19 Mar 2024 14:51:29 +0000 Subject: [PATCH] Convert unit/fileformats/__init__ code to pytest + move to pp_load_rules where it belongs. --- lib/iris/tests/unit/fileformats/__init__.py | 60 ------------------- .../fileformats/pp_load_rules/__init__.py | 56 +++++++++++++++++ .../pp_load_rules/test__all_other_rules.py | 17 +++--- ...est__convert_scalar_pseudo_level_coords.py | 4 +- ...test__convert_scalar_realization_coords.py | 4 +- .../test__convert_time_coords.py | 29 ++++----- .../test__convert_vertical_coords.py | 37 ++++++------ .../fileformats/pp_load_rules/test_convert.py | 39 ++++++------ 8 files changed, 123 insertions(+), 123 deletions(-) diff --git a/lib/iris/tests/unit/fileformats/__init__.py b/lib/iris/tests/unit/fileformats/__init__.py index 81e6c8cedf..c5982fc475 100644 --- a/lib/iris/tests/unit/fileformats/__init__.py +++ b/lib/iris/tests/unit/fileformats/__init__.py @@ -3,63 +3,3 @@ # This file is part of Iris and is released under the BSD license. # See LICENSE in the root of the repository for full licensing details. """Unit tests for the :mod:`iris.fileformats` package.""" - -import iris.tests as tests # isort:skip - - -class TestField(tests.IrisTest): - def _test_for_coord( - self, field, convert, coord_predicate, expected_points, expected_bounds - ): - ( - factories, - references, - standard_name, - long_name, - units, - attributes, - cell_methods, - dim_coords_and_dims, - aux_coords_and_dims, - ) = convert(field) - - # Check for one and only one matching coordinate. - coords_and_dims = dim_coords_and_dims + aux_coords_and_dims - matching_coords = [ - coord for coord, _ in coords_and_dims if coord_predicate(coord) - ] - self.assertEqual(len(matching_coords), 1, str(matching_coords)) - coord = matching_coords[0] - - # Check points and bounds. - if expected_points is not None: - self.assertArrayEqual(coord.points, expected_points) - - if expected_bounds is None: - self.assertIsNone(coord.bounds) - else: - self.assertArrayEqual(coord.bounds, expected_bounds) - - def assertCoordsAndDimsListsMatch( - self, coords_and_dims_got, coords_and_dims_expected - ): - """Check that coords_and_dims lists are equivalent. - - The arguments are lists of pairs of (coordinate, dimensions). - The elements are compared one-to-one, by coordinate name (so the order - of the lists is _not_ significant). - It also checks that the coordinate types (DimCoord/AuxCoord) match. - - """ - - def sorted_by_coordname(list): - return sorted(list, key=lambda item: item[0].name()) - - coords_and_dims_got = sorted_by_coordname(coords_and_dims_got) - coords_and_dims_expected = sorted_by_coordname(coords_and_dims_expected) - self.assertEqual(coords_and_dims_got, coords_and_dims_expected) - # Also check coordinate type equivalences (as Coord.__eq__ does not). - self.assertEqual( - [type(coord) for coord, dims in coords_and_dims_got], - [type(coord) for coord, dims in coords_and_dims_expected], - ) diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/__init__.py b/lib/iris/tests/unit/fileformats/pp_load_rules/__init__.py index c8361feae4..27d79d6cd3 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/__init__.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/__init__.py @@ -3,3 +3,59 @@ # This file is part of Iris and is released under the BSD license. # See LICENSE in the root of the repository for full licensing details. """Unit tests for the :mod:`iris.fileformats.pp_load_rules` module.""" + +# general utility functions for PP field tests +from iris.tests._shared_utils import assert_array_equal + + +def assert_test_for_coord( + field, convert, coord_predicate, expected_points, expected_bounds +): + ( + factories, + references, + standard_name, + long_name, + units, + attributes, + cell_methods, + dim_coords_and_dims, + aux_coords_and_dims, + ) = convert(field) + + # Check for one and only one matching coordinate. + coords_and_dims = dim_coords_and_dims + aux_coords_and_dims + matching_coords = [coord for coord, _ in coords_and_dims if coord_predicate(coord)] + assert len(matching_coords) == 1, str(matching_coords) + coord = matching_coords[0] + + # Check points and bounds. + if expected_points is not None: + assert_array_equal(coord.points, expected_points) + + if expected_bounds is None: + assert coord.bounds is None + else: + assert_array_equal(coord.bounds, expected_bounds) + + +def assert_coords_and_dims_lists_match(coords_and_dims_got, coords_and_dims_expected): + """Check that coords_and_dims lists are equivalent. + + The arguments are lists of pairs of (coordinate, dimensions). + The elements are compared one-to-one, by coordinate name (so the order + of the lists is _not_ significant). + It also checks that the coordinate types (DimCoord/AuxCoord) match. + + """ + + def sorted_by_coordname(list): + return sorted(list, key=lambda item: item[0].name()) + + coords_and_dims_got = sorted_by_coordname(coords_and_dims_got) + coords_and_dims_expected = sorted_by_coordname(coords_and_dims_expected) + assert coords_and_dims_got == coords_and_dims_expected + # Also check coordinate type equivalences (as Coord.__eq__ does not). + assert [type(coord) for coord, dims in coords_and_dims_got] == [ + type(coord) for coord, dims in coords_and_dims_expected + ] diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py index aa6b79e9a0..6346abbe7b 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py @@ -17,7 +17,8 @@ from iris.coords import AuxCoord, CellMethod, DimCoord from iris.fileformats.pp import SplittableInt from iris.fileformats.pp_load_rules import _all_other_rules -from iris.tests.unit.fileformats import TestField +from iris.tests import IrisTest +from iris.tests.unit.fileformats.pp_load_rules import assert_coords_and_dims_lists_match # iris.fileformats.pp_load_rules._all_other_rules() returns a tuple of # of various metadata. This constant is the index into this @@ -142,7 +143,7 @@ def test_multiple_unordered_rotated_lbprocs(self): self.assertEqual(res, expected) -class TestCrossSectionalTime(TestField): +class TestCrossSectionalTime(IrisTest): def test_lbcode3x23(self): time_bounds = np.array( [[0.875, 1.125], [1.125, 1.375], [1.375, 1.625], [1.625, 1.875]] @@ -201,10 +202,10 @@ def test_lbcode3x23(self): 0, ) ] - self.assertCoordsAndDimsListsMatch(res, expected) + assert_coords_and_dims_lists_match(res, expected) -class TestLBTIMx2x_ZeroYears(TestField): +class TestLBTIMx2x_ZeroYears(IrisTest): _spec = [ "lbtim", "lbcode", @@ -272,28 +273,28 @@ def test_month_coord(self): None, ), ] - self.assertCoordsAndDimsListsMatch(res, expected) + assert_coords_and_dims_lists_match(res, expected) def test_diff_month(self): field = self._make_field(lbmon=3, lbmond=4) field.mock_add_spec(self._spec) res = _all_other_rules(field)[AUX_COORDS_INDEX] - self.assertCoordsAndDimsListsMatch(res, []) + assert_coords_and_dims_lists_match(res, []) def test_nonzero_year(self): field = self._make_field(lbyr=1) field.mock_add_spec(self._spec) res = _all_other_rules(field)[AUX_COORDS_INDEX] - self.assertCoordsAndDimsListsMatch(res, []) + assert_coords_and_dims_lists_match(res, []) def test_nonzero_yeard(self): field = self._make_field(lbyrd=1) field.mock_add_spec(self._spec) res = _all_other_rules(field)[AUX_COORDS_INDEX] - self.assertCoordsAndDimsListsMatch(res, []) + assert_coords_and_dims_lists_match(res, []) if __name__ == "__main__": diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_pseudo_level_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_pseudo_level_coords.py index bc3cf8ed86..1c1ebde074 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_pseudo_level_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_pseudo_level_coords.py @@ -13,10 +13,10 @@ from iris.coords import DimCoord from iris.fileformats.pp_load_rules import _convert_scalar_pseudo_level_coords -from iris.tests.unit.fileformats import TestField +from iris.tests import IrisTest -class Test(TestField): +class Test(IrisTest): def test_valid(self): coords_and_dims = _convert_scalar_pseudo_level_coords(lbuser5=21) self.assertEqual( diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_realization_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_realization_coords.py index ac28fe0a1c..011051b1ab 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_realization_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_realization_coords.py @@ -13,10 +13,10 @@ from iris.coords import DimCoord from iris.fileformats.pp_load_rules import _convert_scalar_realization_coords -from iris.tests.unit.fileformats import TestField +from iris.tests import IrisTest -class Test(TestField): +class Test(IrisTest): def test_valid(self): coords_and_dims = _convert_scalar_realization_coords(lbrsvd4=21) self.assertEqual( diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_time_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_time_coords.py index 5cebc009b9..faabc478b7 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_time_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_time_coords.py @@ -18,7 +18,8 @@ from iris.coords import AuxCoord, DimCoord from iris.fileformats.pp import SplittableInt from iris.fileformats.pp_load_rules import _convert_time_coords -from iris.tests.unit.fileformats import TestField +from iris.tests import IrisTest as TestField +from iris.tests.unit.fileformats.pp_load_rules import assert_coords_and_dims_lists_match def _lbtim(ia=0, ib=0, ic=0): @@ -69,7 +70,7 @@ def _check_timepoint(self, lbcode, expect_match=True): ] else: expect_result = [] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) def test_normal_xy_dims(self): self._check_timepoint(_lbcode(1)) @@ -126,7 +127,7 @@ def _check_forecast(self, lbcode, expect_match=True): ] else: expect_result = [] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) def test_normal_xy(self): self._check_forecast(_lbcode(1)) @@ -218,7 +219,7 @@ def _check_period(self, lbcode, expect_match=True): ] else: expect_result = [] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) def test_normal_xy(self): self._check_period(_lbcode(1)) @@ -280,7 +281,7 @@ def _check_yearly(self, lbcode, expect_match=True): ] else: expect_result = [] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) def test_normal_xy(self): self._check_yearly(_lbcode(1)) @@ -355,7 +356,7 @@ def test(self): None, ) ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected_result) + assert_coords_and_dims_lists_match(coords_and_dims, expected_result) class TestArrayInputWithLBTIM_0_0_1(TestField): @@ -387,7 +388,7 @@ def test_t1_list(self): (24 * 8) + 3 + hours, standard_name="time", units=_EPOCH_HOURS_UNIT ) expected = [(time_coord, (0,))] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected) + assert_coords_and_dims_lists_match(coords_and_dims, expected) class TestArrayInputWithLBTIM_0_1_1(TestField): @@ -436,7 +437,7 @@ def test_t1_list_t2_scalar(self): (time_coord, (0,)), (fref_time_coord, None), ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected) + assert_coords_and_dims_lists_match(coords_and_dims, expected) def test_t1_and_t2_list(self): # lbtim ia = 0, ib = 1, ic = 1 @@ -485,7 +486,7 @@ def test_t1_and_t2_list(self): (time_coord, (0,)), (fref_time_coord, None), ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected) + assert_coords_and_dims_lists_match(coords_and_dims, expected) def test_t1_and_t2_orthogonal_lists(self): # lbtim ia = 0, ib = 1, ic = 1 @@ -532,7 +533,7 @@ def test_t1_and_t2_orthogonal_lists(self): (time_coord, (0,)), (fref_time_coord, (1,)), ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected) + assert_coords_and_dims_lists_match(coords_and_dims, expected) def test_t1_multi_dim_list_t2_scalar(self): # Another case of lbtim ia = 0, ib = 1, ic = 1 but @@ -586,7 +587,7 @@ def test_t1_multi_dim_list_t2_scalar(self): (time_coord, (0, 1)), (fref_time_coord, None), ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected) + assert_coords_and_dims_lists_match(coords_and_dims, expected) def test_t1_and_t2_nparrays(self): # lbtim ia = 0, ib = 1, ic = 1 @@ -639,7 +640,7 @@ def test_t1_and_t2_nparrays(self): (time_coord, (0,)), (fref_time_coord, None), ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected) + assert_coords_and_dims_lists_match(coords_and_dims, expected) class TestArrayInputWithLBTIM_0_2_1(TestField): @@ -694,7 +695,7 @@ def test_t1_list_t2_scalar(self): (time_coord, (0,)), (fref_time_coord, None), ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected) + assert_coords_and_dims_lists_match(coords_and_dims, expected) class TestArrayInputWithLBTIM_0_3_1(TestField): @@ -754,7 +755,7 @@ def test_t1_scalar_t2_list(self): (time_coord, (0,)), (fref_time_coord, (0,)), ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expected) + assert_coords_and_dims_lists_match(coords_and_dims, expected) if __name__ == "__main__": diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py index 0e159b254e..b790b77884 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py @@ -17,7 +17,8 @@ from iris.coords import AuxCoord, DimCoord from iris.fileformats.pp import STASH, SplittableInt from iris.fileformats.pp_load_rules import Reference, _convert_vertical_coords -from iris.tests.unit.fileformats import TestField +from iris.tests import IrisTest +from iris.tests.unit.fileformats.pp_load_rules import assert_coords_and_dims_lists_match def _lbcode(value=None, ix=None, iy=None): @@ -31,7 +32,7 @@ def _lbcode(value=None, ix=None, iy=None): return result -class TestLBVC001_Height(TestField): +class TestLBVC001_Height(IrisTest): def _check_height( self, blev, @@ -89,7 +90,7 @@ def _check_height( ] else: expect_result = [] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) self.assertEqual(factories, []) def test_normal_height__present(self): @@ -172,7 +173,7 @@ def test_implied_height_10m__vector(self): ) -class TestLBVC002_Depth(TestField): +class TestLBVC002_Depth(IrisTest): def _check_depth( self, lbcode, @@ -248,7 +249,7 @@ def _check_depth( ) else: expect_result = [] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) self.assertEqual(factories, []) def test_unbounded(self): @@ -323,7 +324,7 @@ def test_cross_section__vector(self): ) -class TestLBVC006_SoilLevel(TestField): +class TestLBVC006_SoilLevel(IrisTest): def _check_soil_level(self, lbcode, lblev=12.3, expect_match=True, dim=None): lbvc = 6 stash = STASH(1, 1, 1) @@ -354,7 +355,7 @@ def _check_soil_level(self, lbcode, lblev=12.3, expect_match=True, dim=None): units="1", ) expect_result = [(coord, dim)] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) self.assertEqual(factories, []) def test_normal(self): @@ -374,7 +375,7 @@ def test_cross_section__vector(self): ) -class TestLBVC006_SoilDepth(TestField): +class TestLBVC006_SoilDepth(IrisTest): def _check_soil_depth( self, lbcode, @@ -410,7 +411,7 @@ def _check_soil_depth( attributes={"positive": "down"}, ) expect_result = [(coord, dim)] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) self.assertEqual(factories, []) def test_normal(self): @@ -450,7 +451,7 @@ def test_cross_section__vector(self): ) -class TestLBVC008_Pressure(TestField): +class TestLBVC008_Pressure(IrisTest): def _check_pressure(self, lbcode, blev=250.3, expect_match=True, dim=None): lbvc = 8 stash = STASH(1, 1, 1) @@ -479,7 +480,7 @@ def _check_pressure(self, lbcode, blev=250.3, expect_match=True, dim=None): expect_result = [(DimCoord(blev, long_name="pressure", units="hPa"), dim)] else: expect_result = [] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) self.assertEqual(factories, []) def test_normal(self): @@ -504,7 +505,7 @@ def test_pressure_cross_section__vector(self): self._check_pressure(_lbcode(ix=10, iy=1), blev=blev, dim=1, expect_match=False) -class TestLBVC019_PotentialTemperature(TestField): +class TestLBVC019_PotentialTemperature(IrisTest): def _check_potm(self, lbcode, blev=130.6, expect_match=True, dim=None): lbvc = 19 stash = STASH(1, 1, 1) @@ -543,7 +544,7 @@ def _check_potm(self, lbcode, blev=130.6, expect_match=True, dim=None): ] else: expect_result = [] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) + assert_coords_and_dims_lists_match(coords_and_dims, expect_result) self.assertEqual(factories, []) def test_normal(self): @@ -561,7 +562,7 @@ def test_cross_section__vector(self): self._check_potm(_lbcode(ix=10, iy=11), blev=blev, dim=1, expect_match=False) -class TestLBVC009_HybridPressure(TestField): +class TestLBVC009_HybridPressure(IrisTest): def _check( self, lblev=37.0, @@ -638,7 +639,7 @@ def _check( ], ) ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_coords_and_dims) + assert_coords_and_dims_lists_match(coords_and_dims, expect_coords_and_dims) self.assertEqual(factories, expect_factories) def test_normal(self): @@ -664,7 +665,7 @@ def test_normal__vector(self): ) -class TestLBVC065_HybridHeight(TestField): +class TestLBVC065_HybridHeight(IrisTest): def _check( self, lblev=37.0, @@ -740,7 +741,7 @@ def _check( ], ) ] - self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_coords_and_dims) + assert_coords_and_dims_lists_match(coords_and_dims, expect_coords_and_dims) self.assertEqual(factories, expect_factories) def test_normal(self): @@ -767,7 +768,7 @@ def test_normal__vector(self): ) -class TestLBVCxxx_Unhandled(TestField): +class TestLBVCxxx_Unhandled(IrisTest): def test_unknown_lbvc(self): lbvc = 999 blev, lblev, bhlev, bhrlev, brsvd1, brsvd2, brlev = ( diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test_convert.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test_convert.py index 476ecbc8ae..66e428470d 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test_convert.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test_convert.py @@ -18,6 +18,7 @@ from iris.fileformats.pp import STASH, PPField3, SplittableInt from iris.fileformats.pp_load_rules import convert import iris.tests.unit.fileformats +from iris.tests.unit.fileformats.pp_load_rules import assert_test_for_coord from iris.util import guess_coord_axis @@ -31,7 +32,7 @@ def _mock_field(**kwargs): return field -class TestLBCODE(iris.tests.unit.fileformats.TestField): +class TestLBCODE(iris.tests.IrisTest): @staticmethod def _is_cross_section_height_coord(coord): return ( @@ -45,7 +46,7 @@ def test_cross_section_height_bdy_zero(self): points = np.array([10, 20, 30, 40]) bounds = np.array([[0, 15], [15, 25], [25, 35], [35, 45]]) field = _mock_field(lbcode=lbcode, bdy=0, y=points, y_bounds=bounds) - self._test_for_coord( + assert_test_for_coord( field, convert, TestLBCODE._is_cross_section_height_coord, @@ -61,7 +62,7 @@ def test_cross_section_height_bdy_bmdi(self): field = _mock_field( lbcode=lbcode, bdy=bmdi, bmdi=bmdi, y=points, y_bounds=bounds ) - self._test_for_coord( + assert_test_for_coord( field, convert, TestLBCODE._is_cross_section_height_coord, @@ -70,7 +71,7 @@ def test_cross_section_height_bdy_bmdi(self): ) -class TestLBVC(iris.tests.unit.fileformats.TestField): +class TestLBVC(iris.tests.IrisTest): @staticmethod def _is_potm_level_coord(coord): return ( @@ -113,7 +114,7 @@ def _is_soil_depth_coord(coord): def test_soil_levels(self): level = 1234 field = _mock_field(lbvc=6, lblev=level, brsvd=[0, 0], brlev=0) - self._test_for_coord( + assert_test_for_coord( field, convert, self._is_soil_model_level_number_coord, @@ -124,7 +125,7 @@ def test_soil_levels(self): def test_soil_depth(self): lower, point, upper = 1.2, 3.4, 5.6 field = _mock_field(lbvc=6, blev=point, brsvd=[lower, 0], brlev=upper) - self._test_for_coord( + assert_test_for_coord( field, convert, self._is_soil_depth_coord, @@ -143,7 +144,7 @@ def test_hybrid_pressure_model_level_number(self): bhrlev=45, brsvd=[17, 40], ) - self._test_for_coord( + assert_test_for_coord( field, convert, TestLBVC._is_model_level_number_coord, @@ -164,7 +165,7 @@ def test_hybrid_pressure_delta(self): bhrlev=delta_lower_bound, brsvd=[17, delta_upper_bound], ) - self._test_for_coord( + assert_test_for_coord( field, convert, TestLBVC._is_level_pressure_coord, @@ -185,7 +186,7 @@ def test_hybrid_pressure_sigma(self): bhrlev=11, brsvd=[sigma_upper_bound, 13], ) - self._test_for_coord( + assert_test_for_coord( field, convert, TestLBVC._is_sigma_coord, @@ -196,7 +197,7 @@ def test_hybrid_pressure_sigma(self): def test_potential_temperature_levels(self): potm_value = 27.32 field = _mock_field(lbvc=19, blev=potm_value) - self._test_for_coord( + assert_test_for_coord( field, convert, TestLBVC._is_potm_level_coord, @@ -205,7 +206,7 @@ def test_potential_temperature_levels(self): ) -class TestLBTIM(iris.tests.unit.fileformats.TestField): +class TestLBTIM(iris.tests.IrisTest): def test_365_calendar(self): f = mock.MagicMock( lbtim=SplittableInt(4, {"ia": 2, "ib": 1, "ic": 0}), @@ -278,7 +279,7 @@ def test_time_mean_ib2(self): field.lbyrd, field.lbmond, field.lbdatd = 1970, 1, 2 field.lbhrd, field.lbmind, field.lbsecd = 15, 0, 0 - self._test_for_coord( + assert_test_for_coord( field, convert, self.is_forecast_period, @@ -286,7 +287,7 @@ def test_time_mean_ib2(self): expected_bounds=[[6, 9]], ) - self._test_for_coord( + assert_test_for_coord( field, convert, self.is_time, @@ -306,7 +307,7 @@ def test_time_mean_ib3(self): field.lbyrd, field.lbmond, field.lbdatd = 1971, 1, 2 field.lbhrd, field.lbmind, field.lbsecd = 15, 0, 0 - self._test_for_coord( + assert_test_for_coord( field, convert, self.is_forecast_period, @@ -314,7 +315,7 @@ def test_time_mean_ib3(self): expected_bounds=[[36 - 30, lbft]], ) - self._test_for_coord( + assert_test_for_coord( field, convert, self.is_time, @@ -323,7 +324,7 @@ def test_time_mean_ib3(self): ) -class TestLBRSVD(iris.tests.unit.fileformats.TestField): +class TestLBRSVD(iris.tests.IrisTest): @staticmethod def _is_realization(coord): return coord.standard_name == "realization" and coord.units == "1" @@ -334,7 +335,7 @@ def test_realization(self): points = np.array([71]) bounds = None field = _mock_field(lbrsvd=lbrsvd) - self._test_for_coord( + assert_test_for_coord( field, convert, TestLBRSVD._is_realization, @@ -384,7 +385,7 @@ def test_um_version(self): ) -class Test_STASH_CF(iris.tests.unit.fileformats.TestField): +class Test_STASH_CF(iris.tests.IrisTest): def test_stash_cf_air_temp(self): lbuser = [1, 0, 0, 16203, 0, 0, 1] lbfc = 16 @@ -424,7 +425,7 @@ def test_no_std_name(self): self.assertIsNone(units) -class Test_LBFC_CF(iris.tests.unit.fileformats.TestField): +class Test_LBFC_CF(iris.tests.IrisTest): def test_fc_cf_air_temp(self): lbuser = [1, 0, 0, 0, 0, 0, 0] lbfc = 16