def test_add_cell_method_partial_information(self): """Test adding a cell method, where there is only partial information available i.e. just method and coords.""" cell_methods = {'action': 'add', 'method': 'point', 'coords': 'time'} cm = deepcopy(cell_methods) cm.pop('action') expected_cell_method = iris.coords.CellMethod(**cm) _update_cell_methods(self.cube, cell_methods) self.assertEqual((expected_cell_method, ), self.cube.cell_methods)
def test_add_cell_method_already_on_cube(self): """Test that there is no change to the cell method, if the specified cell method is already on the cube.""" cell_methods = {'action': 'add', 'method': 'point', 'coords': 'time'} cm = deepcopy(cell_methods) cm.pop('action') self.cube.cell_methods = (iris.coords.CellMethod(**cm), ) expected_cell_method = iris.coords.CellMethod(**cm) _update_cell_methods(self.cube, cell_methods) self.assertEqual((expected_cell_method, ), self.cube.cell_methods)
def test_add_cell_method_no_action(self): """Test adding a cell method, where no action is specified.""" cell_methods = { 'method': 'point', 'coords': 'time', 'intervals': (), 'comments': () } msg = "No action has been specified within the cell method definition." with self.assertRaisesRegex(ValueError, msg): _update_cell_methods(self.cube, cell_methods)
def test_add_cell_method_empty_method(self): """Test add a cell method, where the method element is specified as an emtpy string.""" cell_methods = { 'action': 'add', 'method': '', 'coords': 'time', 'intervals': (), 'comments': () } msg = "No method has been specified within the cell method" with self.assertRaisesRegex(ValueError, msg): _update_cell_methods(self.cube, cell_methods)
def test_add_cell_method_no_coords(self): """Test add a cell method, where no coords element is specified.""" cell_methods = { 'action': 'add', 'method': 'point', 'coords': (), 'intervals': (), 'comments': () } cm = deepcopy(cell_methods) cm.pop('action') expected_cell_method = iris.coords.CellMethod(**cm) _update_cell_methods(self.cube, cell_methods) self.assertEqual((expected_cell_method, ), self.cube.cell_methods)
def test_remove_cell_method(self): """Test removing a cell method, when the specified cell method is already on the input cube.""" cell_methods = { 'action': 'delete', 'method': 'point', 'coords': 'time', 'intervals': (), 'comments': () } cm = deepcopy(cell_methods) cm.pop('action') self.cube.cell_methods = (iris.coords.CellMethod(**cm), ) _update_cell_methods(self.cube, cell_methods) self.assertEqual(self.cube.cell_methods, ())
def test_add_cell_method(self): """Test adding a cell method, where all cell method elements are present i.e. method, coords, intervals and comments.""" cell_methods = { 'action': 'add', 'method': 'point', 'coords': 'time', 'intervals': (), 'comments': () } cm = deepcopy(cell_methods) cm.pop('action') expected_cell_method = iris.coords.CellMethod(**cm) _update_cell_methods(self.cube, cell_methods) self.assertEqual((expected_cell_method, ), self.cube.cell_methods)
def test_add_additional_cell_method_to_cube(self): """Test that there is no change to the cell method, if the specified cell method is already on the cube.""" existing_cell_methods = { 'action': 'add', 'method': 'point', 'coords': 'time' } additional_cell_methods = { 'action': 'add', 'method': 'mean', 'coords': 'realization' } cm = deepcopy(existing_cell_methods) cm.pop('action') self.cube.cell_methods = (iris.coords.CellMethod(**cm), ) cm = deepcopy(additional_cell_methods) cm.pop('action') expected_cell_method = iris.coords.CellMethod(**cm) _update_cell_methods(self.cube, additional_cell_methods) self.assertTrue(expected_cell_method in self.cube.cell_methods)