Skip to content

Commit

Permalink
Add tests of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
znicholls committed Sep 17, 2018
1 parent 52331d2 commit be08462
Showing 1 changed file with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit be08462

Please sign in to comment.