diff --git a/lib/iris/tests/unit/fileformats/pyke_rules/compiled_krb/fc_rules_cf_fc/test_build_dimension_coordinate.py b/lib/iris/tests/unit/fileformats/pyke_rules/compiled_krb/fc_rules_cf_fc/test_build_dimension_coordinate.py index c645f984cc..7cd07ca580 100644 --- a/lib/iris/tests/unit/fileformats/pyke_rules/compiled_krb/fc_rules_cf_fc/test_build_dimension_coordinate.py +++ b/lib/iris/tests/unit/fileformats/pyke_rules/compiled_krb/fc_rules_cf_fc/test_build_dimension_coordinate.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2014 - 2015, Met Office +# (C) British Crown Copyright 2014 - 2018, Met Office # # This file is part of Iris. # @@ -112,6 +112,60 @@ def test_dim_coord_construction(self): self.engine.cube.add_dim_coord.assert_called_with( expected_coord, [0]) + def test_dim_coord_construction_masked_array(self): + self._set_cf_coord_var(np.ma.array( + np.arange(6), + mask=[True, False, False, False, False, False], + fill_value=-999, + )) + + expected_coord = DimCoord( + np.array([-999, 1, 2, 3, 4, 5]), + long_name=self.cf_coord_var.long_name, + var_name=self.cf_coord_var.cf_name, + units=self.cf_coord_var.units, + bounds=self.bounds) + + with warnings.catch_warnings(record=True) as w: + # Asserts must lie within context manager because of deferred + # loading. + with self.deferred_load_patch, self.get_cf_bounds_var_patch: + build_dimension_coordinate(self.engine, self.cf_coord_var) + + # Test that expected coord is built and added to cube. + self.engine.cube.add_dim_coord.assert_called_with( + expected_coord, [0]) + + # Assert warning is raised + assert len(w) == 1 + assert 'Gracefully filling' in w[0].message.args[0] + + def test_dim_coord_construction_masked_array_mask_does_nothing(self): + self._set_cf_coord_var(np.ma.array( + np.arange(6), + mask=False, + )) + + expected_coord = DimCoord( + self.cf_coord_var[:], + long_name=self.cf_coord_var.long_name, + var_name=self.cf_coord_var.cf_name, + units=self.cf_coord_var.units, + bounds=self.bounds) + + with warnings.catch_warnings(record=True) as w: + # Asserts must lie within context manager because of deferred + # loading. + with self.deferred_load_patch, self.get_cf_bounds_var_patch: + build_dimension_coordinate(self.engine, self.cf_coord_var) + + # Test that expected coord is built and added to cube. + self.engine.cube.add_dim_coord.assert_called_with( + expected_coord, [0]) + + # Assert no warning is raised + assert len(w) == 0 + def test_aux_coord_construction(self): # Use non monotonically increasing coordinates to force aux coord # construction.