diff --git a/iris_grib/tests/integration/iris_integration/__init__.py b/iris_grib/tests/integration/iris_integration/__init__.py index 8c25377f3..c565a4379 100644 --- a/iris_grib/tests/integration/iris_integration/__init__.py +++ b/iris_grib/tests/integration/iris_integration/__init__.py @@ -8,43 +8,3 @@ files. """ - -# Import iris_grib.tests first so that some things can be initialised before -# importing anything else. -import iris_grib.tests as tests - - -import iris -import iris.coords - - -class TestCallbacks(tests.IrisGribTest): - def test_grib_callback(self): - def grib_thing_getter(cube, field, filename): - if hasattr(field, "sections"): - # New-style loader callback : 'field' is a GribMessage, which - # has 'sections'. - cube.add_aux_coord( - iris.coords.AuxCoord( - field.sections[1]["year"], - long_name="extra_year_number_coord", - units="no_unit", - ) - ) - else: - # Old-style loader provides 'GribWrapper' type field. - cube.add_aux_coord( - iris.coords.AuxCoord( - field.extra_keys["_periodStartDateTime"], - long_name="random element", - units="no_unit", - ) - ) - - fname = tests.get_data_path(("GRIB", "global_t", "global.grib2")) - cube = iris.load_cube(fname, callback=grib_thing_getter) - self.assertCML(cube) - - -if __name__ == "__main__": - tests.main() diff --git a/iris_grib/tests/integration/iris_integration/test_callback.py b/iris_grib/tests/integration/iris_integration/test_callback.py new file mode 100644 index 000000000..ca2d739c2 --- /dev/null +++ b/iris_grib/tests/integration/iris_integration/test_callback.py @@ -0,0 +1,43 @@ +# Copyright iris-grib contributors +# +# This file is part of iris-grib and is released under the LGPL license. +# See COPYING and COPYING.LESSER in the root of the repository for full +# licensing details. +""" +Test that iris load callbacks work with iris-grib. + +""" + +# Import iris_grib.tests first so that some things can be initialised before +# importing anything else. +import iris_grib.tests as tests + + +import iris +import iris.coords + + +class TestCallbacks(tests.IrisGribTest): + def test_load_callback(self): + # What this actually tests: + # 1. iris.load works with grib (though the GRIB picker is in Iris) + # 2. callbacks work with the grib loader + # 3. grib loaded result matches a cube snapshot + def load_callback(cube, field, filename): + # GRIB2 loader callback : 'field' is a GribMessage, which + # has 'sections'. + cube.add_aux_coord( + iris.coords.AuxCoord( + field.sections[1]["year"], + long_name="extra_year_number_coord", + units="no_unit", + ) + ) + + fname = tests.get_data_path(("GRIB", "global_t", "global.grib2")) + cube = iris.load_cube(fname, callback=load_callback) + self.assertCML(cube) + + +if __name__ == "__main__": + tests.main() diff --git a/iris_grib/tests/results/integration/iris_integration/__init__/TestCallbacks/grib_callback.cml b/iris_grib/tests/results/integration/iris_integration/callback/TestCallbacks/load_callback.cml similarity index 100% rename from iris_grib/tests/results/integration/iris_integration/__init__/TestCallbacks/grib_callback.cml rename to iris_grib/tests/results/integration/iris_integration/callback/TestCallbacks/load_callback.cml