diff --git a/iris_grib/_load_convert.py b/iris_grib/_load_convert.py index 8f72b37a..f27c551d 100644 --- a/iris_grib/_load_convert.py +++ b/iris_grib/_load_convert.py @@ -2515,7 +2515,7 @@ def data_representation_section(section): template = section['dataRepresentationTemplateNumber'] # Supported templates for both grid point and spectral data: - grid_point_templates = (0, 1, 2, 3, 4, 40, 41, 61) + grid_point_templates = (0, 1, 2, 3, 4, 40, 41, 42, 61) spectral_templates = (50, 51) supported_templates = grid_point_templates + spectral_templates diff --git a/iris_grib/tests/unit/load_convert/test_data_representation_section.py b/iris_grib/tests/unit/load_convert/test_data_representation_section.py new file mode 100644 index 00000000..e4992ed5 --- /dev/null +++ b/iris_grib/tests/unit/load_convert/test_data_representation_section.py @@ -0,0 +1,38 @@ +# 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 function :func:`iris_grib._load_convert.data_representation_section.` + +""" + +# import iris_grib.tests first so that some things can be initialised +# before importing anything else. +import iris_grib.tests as tests + +from iris.exceptions import TranslationError + +from iris_grib._load_convert import data_representation_section +from iris_grib.tests.unit import _make_test_message + + +class Test(tests.IrisGribTest): + def test_supported_templates(self): + template_nums = [0, 1, 2, 3, 4, 40, 41, 42, 50, 51, 61] + for template_num in template_nums: + message = _make_test_message( + {5: {'dataRepresentationTemplateNumber': template_num}}) + data_representation_section(message.sections[5]) + + def test_unsupported_template(self): + message = _make_test_message( + {5: {'dataRepresentationTemplateNumber': 5}}) + err_msg = r'Template \[5\] is not supported' + with self.assertRaisesRegex(TranslationError, err_msg): + data_representation_section(message.sections[5]) + + +if __name__ == '__main__': + tests.main()