def test_invalid_method(self):
        """
        Test that the plugin can handle an invalid method being passed in.

        """
        plugin = Plugin('smallest distance')
        msg = 'Unknown method'
        with self.assertRaisesRegex(AttributeError, msg):
            plugin.process(self.cube, self.sites, self.ancillary_data)
 def without_ancillary_data(self,
                            method,
                            vertical_bias=None,
                            land_constraint=False):
     """Test plugins behaviour with no ancillary data provided."""
     plugin = Plugin(method, vertical_bias, land_constraint)
     if method == 'fast_nearest_neighbour':
         result = plugin.process(self.cube, self.sites, {})
         self.assertIsInstance(result, np.ndarray)
     else:
         with self.assertRaises(KeyError):
             plugin.process(self.cube, self.sites, {})
 def correct_neighbour(self,
                       method,
                       i_expected,
                       j_expected,
                       dz_expected,
                       vertical_bias=None,
                       land_constraint=False):
     """Test that the plugin returns the expected neighbour."""
     plugin = Plugin(method, vertical_bias, land_constraint)
     result = plugin.process(self.cube, self.sites, self.ancillary_data)
     self.assertEqual(result['i'], i_expected)
     self.assertEqual(result['j'], j_expected)
     self.assertEqual(result['dz'], dz_expected)
    def test_invalid_no_neighbours(self):
        """
        Test use of a larger but invalid no of neighbours over which to find
        the minimum vertical displacement.

        """
        plugin = Plugin(method='minimum_height_error_neighbour',
                        vertical_bias=None,
                        land_constraint=False)
        msg = 'Invalid nearest no'
        with self.assertRaisesRegex(ValueError, msg):
            plugin.process(self.cube,
                           self.sites,
                           self.ancillary_data,
                           no_neighbours=20)
    def test_variable_no_neighbours(self):
        """
        Test that the plugin can handle a variable number of neigbours to use
        when relaxing the 'nearest' condition. Make the smallest displacement
        point 2-grid cells away, so it should be captured with no_neighbours
        set to 25.

        """
        self.ancillary_data['orography'].data[13, 10] = 10.
        plugin = Plugin(method='minimum_height_error_neighbour',
                        vertical_bias=None,
                        land_constraint=False)
        result = plugin.process(self.cube,
                                self.sites,
                                self.ancillary_data,
                                no_neighbours=25)
        self.assertEqual(result['i'], 13)
        self.assertEqual(result['j'], 10)
        self.assertEqual(result['dz'], 0.)
 def return_types(self, method, vertical_bias=None, land_constraint=False):
     """Test that the plugin returns a numpy array."""
     plugin = Plugin(method, vertical_bias, land_constraint)
     result = plugin.process(self.cube, self.sites, self.ancillary_data)
     self.assertIsInstance(result, np.ndarray)
     self.assertEqual(result.dtype, self.neighbour_list.dtype)