Skip to content

Commit bf477fc

Browse files
committed
Review changes.
1 parent d426cfa commit bf477fc

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

lib/iris/tests/integration/test_grib2.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def test_cell_method(self):
101101
self.assertEqual(cell_method.coord_names, ('time',))
102102

103103

104+
@tests.skip_data
104105
class TestGDT5(tests.IrisTest):
105106
def test_save_load(self):
106107
# Load sample UKV data (variable-resolution rotated grid).
@@ -155,25 +156,31 @@ def test_save_load(self):
155156
# Also load data, before the temporary file gets deleted.
156157
cube_loaded_from_saved.data
157158

159+
# The re-loaded result will not match the original in every respect:
160+
# * cube attributes are discarded
161+
# * horizontal coordinates are rounded to an integer representation
162+
# * bounds on horizontal coords are lost
163+
# Thus the following "equivalence tests" are rather piecemeal..
164+
158165
# Check those re-loaded properties which should match the original.
159166
for test_cube in (cube, cube_loaded_from_saved):
160167
self.assertEqual(test_cube.standard_name,
161168
'air_pressure_at_sea_level')
162169
self.assertEqual(test_cube.units, 'Pa')
163170
self.assertEqual(test_cube.shape, (744, 744))
164-
self.assertEqual(cube_loaded_from_saved.cell_methods, ())
171+
self.assertEqual(test_cube.cell_methods, ())
165172

166173
# Check no cube attributes on the re-loaded cube.
167174
# Note: this does *not* match the original, but is as expected.
168175
self.assertEqual(cube_loaded_from_saved.attributes, {})
169176

170177
# Now remaining to check: coordinates + data...
171178

172-
# Check they have the same set of coordinates.
179+
# Check they have all the same coordinates.
173180
co_names = [coord.name() for coord in cube.coords()]
174181
co_names_reload = [coord.name()
175182
for coord in cube_loaded_from_saved.coords()]
176-
self.assertEqual(set(co_names_reload), set(co_names))
183+
self.assertEqual(sorted(co_names_reload), sorted(co_names))
177184

178185
# Check all the coordinates.
179186
for coord_name in co_names:
@@ -197,7 +204,7 @@ def test_save_load(self):
197204
# but Grib does not store those bounds).
198205
self.assertIsNone(co_load.bounds)
199206

200-
except Exception as err:
207+
except AssertionError as err:
201208
self.assertTrue(False,
202209
'Failed on coordinate "{}" : {}'.format(
203210
coord_name, str(err)))

lib/iris/tests/unit/fileformats/grib/message/test__GribMessage.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,51 @@ def test_regular_mode_64_128(self):
189189
self._test(64 | 128)
190190

191191

192+
def _example_section_3(grib_definition_template_number, scanning_mode):
193+
return {'sourceOfGridDefinition': 0,
194+
'numberOfOctectsForNumberOfPoints': 0,
195+
'interpretationOfNumberOfPoints': 0,
196+
'gridDefinitionTemplateNumber': grib_definition_template_number,
197+
'scanningMode': scanning_mode,
198+
'Nj': 3,
199+
'Ni': 4}
200+
201+
192202
class Test_data__grid_template_0(tests.IrisTest, Mixin_data__grid_template):
193203
def section_3(self, scanning_mode):
194-
return {'sourceOfGridDefinition': 0,
195-
'numberOfOctectsForNumberOfPoints': 0,
196-
'interpretationOfNumberOfPoints': 0,
197-
'gridDefinitionTemplateNumber': 0,
198-
'scanningMode': scanning_mode,
199-
'Nj': 3,
200-
'Ni': 4}
204+
return _example_section_3(0, scanning_mode)
205+
206+
207+
class Test_data__grid_template_1(tests.IrisTest, Mixin_data__grid_template):
208+
def section_3(self, scanning_mode):
209+
return _example_section_3(1, scanning_mode)
210+
211+
212+
class Test_data__grid_template_5(tests.IrisTest, Mixin_data__grid_template):
213+
def section_3(self, scanning_mode):
214+
return _example_section_3(5, scanning_mode)
201215

202216

203217
class Test_data__grid_template_90(tests.IrisTest, Mixin_data__grid_template):
204218
def section_3(self, scanning_mode):
205-
return {'sourceOfGridDefinition': 0,
206-
'numberOfOctectsForNumberOfPoints': 0,
207-
'interpretationOfNumberOfPoints': 0,
208-
'gridDefinitionTemplateNumber': 90,
209-
'scanningMode': scanning_mode,
210-
'Ny': 3,
211-
'Nx': 4}
219+
section_3 = _example_section_3(90, scanning_mode)
220+
# Exceptionally, dimensions are 'Nx' + 'Ny' instead of 'Ni' + 'Nj'.
221+
section_3['Nx'] = section_3['Ni']
222+
section_3['Ny'] = section_3['Nj']
223+
del section_3['Ni']
224+
del section_3['Nj']
225+
return section_3
226+
227+
228+
class Test_data__unknown_grid_template(tests.IrisTest):
229+
def test(self):
230+
message = _make_test_message(
231+
{3: _example_section_3(999, 0),
232+
6: SECTION_6_NO_BITMAP,
233+
7: {'codedValues': np.arange(12)}})
234+
with self.assertRaisesRegexp(TranslationError,
235+
'template 999 is not supported'):
236+
data = message.data
212237

213238

214239
if __name__ == '__main__':

0 commit comments

Comments
 (0)