def test_no_matches_exception(self): """Test for when no matches in validity time are found between the historic forecasts and the truths. In this case, an exception is raised.""" partial_truth = self.truth[2] msg = "The filtering has found no matches in validity time " with self.assertRaisesRegex(ValueError, msg): Plugin._filter_non_matching_cubes(self.partial_historic_forecasts, partial_truth)
def test_fewer_historic_forecasts(self): """Test for when there are fewer historic forecasts than truths, for example, if there is a missing forecast cycle.""" hf_result, truth_result = Plugin._filter_non_matching_cubes( self.partial_historic_forecasts, self.temperature_truth_cube) self.assertEqual(hf_result, self.partial_historic_forecasts) self.assertEqual(truth_result, self.partial_truth)
def test_fewer_truths(self): """Test for when there are fewer truths than historic forecasts, for example, if there is a missing analysis.""" hf_result, truth_result = Plugin._filter_non_matching_cubes( self.historic_temperature_forecast_cube, self.partial_truth) self.assertEqual(hf_result, self.partial_historic_forecasts) self.assertEqual(truth_result, self.partial_truth)
def test_all_matching(self): """Test for when the historic forecast and truth cubes all match.""" hf_result, truth_result = Plugin._filter_non_matching_cubes( self.historic_temperature_forecast_cube, self.temperature_truth_cube) self.assertEqual(hf_result, self.historic_temperature_forecast_cube) self.assertEqual(truth_result, self.temperature_truth_cube)
def test_mismatching(self): """Test for when there is both a missing historic forecasts and a missing truth at different validity times. This results in the expected historic forecasts and the expected truths containing cubes at three matching validity times.""" partial_truth = self.truth[1:].merge_cube() expected_historical_forecasts = iris.cube.CubeList([ self.historic_forecasts[index] for index in (1, 3, 4) ]).merge_cube() expected_truth = iris.cube.CubeList( [self.truth[index] for index in (1, 3, 4)]).merge_cube() hf_result, truth_result = Plugin._filter_non_matching_cubes( self.partial_historic_forecasts, partial_truth) self.assertEqual(hf_result, expected_historical_forecasts) self.assertEqual(truth_result, expected_truth)