Skip to content

Commit

Permalink
Ditch redundant test code + clarify purpose. (#199)
Browse files Browse the repository at this point in the history
* Ditch redundant test code + clarify purpose.

* Some moves and renames.
  • Loading branch information
pp-mo authored Feb 24, 2020
1 parent ab9bc7d commit d76c228
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 40 deletions.
40 changes: 0 additions & 40 deletions iris_grib/tests/integration/iris_integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
43 changes: 43 additions & 0 deletions iris_grib/tests/integration/iris_integration/test_callback.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d76c228

Please # to comment.