def test_raises_error(self): """Test the error is raised if time is dimensional""" input_cube2 = iris.util.new_axis(self.input_cube2, "forecast_reference_time") input_cubelist = iris.cube.CubeList([self.input_cube, input_cube2]) msg = "Expecting scalar forecast_reference_time for each input cube" with self.assertRaisesRegex(ValueError, msg): _find_latest_cycletime(input_cubelist)
def test_one_input_cube(self): """Test the a cycletime is still found when only one input cube.""" input_cubelist = iris.cube.CubeList([self.input_cube]) cycletime = _find_latest_cycletime(input_cubelist) expected_datetime = datetime(2015, 11, 23, 3) self.assertEqual(timedelta(hours=0, seconds=0), cycletime - expected_datetime)
def test_different_units(self): """Test the right cycletime is still returned if the coords have different units.""" self.input_cube2.coord("forecast_reference_time").convert_units( "minutes since 1970-01-01 00:00:00") cycletime = _find_latest_cycletime(self.input_cubelist) expected_datetime = datetime(2015, 11, 23, 4) self.assertEqual(timedelta(hours=0, seconds=0), cycletime - expected_datetime)
def test_two_cubes_same_reference_time(self): """Test the a cycletime is still found when two cubes have the same cycletime.""" input_cubelist = iris.cube.CubeList( [self.input_cube, self.input_cube.copy()]) cycletime = _find_latest_cycletime(input_cubelist) expected_datetime = datetime(2015, 11, 23, 3) self.assertEqual(timedelta(hours=0, seconds=0), cycletime - expected_datetime)
def test_basic(self): """Test the type of the output and that the input is unchanged.""" original_cubelist = iris.cube.CubeList( [self.input_cube.copy(), self.input_cube2.copy()]) cycletime = _find_latest_cycletime(self.input_cubelist) self.assertEqual(self.input_cubelist[0], original_cubelist[0]) self.assertEqual(self.input_cubelist[1], original_cubelist[1]) self.assertIsInstance(cycletime, datetime)
def test_returns_latest(self): """Test the returned cycle time is the latest in the input cubelist.""" cycletime = _find_latest_cycletime(self.input_cubelist) expected_datetime = datetime(2015, 11, 23, 4) self.assertEqual(timedelta(hours=0, seconds=0), cycletime - expected_datetime)