def test_bad_calendar(self): # Setup a unit with an unrecognised calendar hrs_unit = Unit('hours since epoch', calendar=cf_units.CALENDAR_ALL_LEAP) # Test against a date with year=0, which requires calendar correction. test_date = nc_datetime(0, 1, 1) # Check that this causes an error. with self.assertRaisesRegexp(ValueError, 'unrecognised calendar'): epoch_hours_call(hrs_unit, test_date)
def test_bad_calendar(self): self.calendar = cf_units.CALENDAR_ALL_LEAP # Setup a unit with an unrecognised calendar hrs_unit = Unit("hours since epoch", calendar=self.calendar) # Test against a date with year=0, which requires calendar correction. test_date = nc_datetime( 0, 1, 1, calendar=self.calendar, has_year_zero=True ) # Check that this causes an error. with self.assertRaisesRegex(ValueError, "unrecognised calendar"): epoch_hours_call(hrs_unit, test_date)
def test_ymd_0_preserves_timeofday(self): hrs, mins, secs, usecs = (7, 13, 24, 335772) hours_in_day = (hrs + 1./60 * mins + 1./3600 * secs + (1.0e-6) / 3600 * usecs) test_date = nc_datetime(0, 0, 0, hour=hrs, minute=mins, second=secs, microsecond=usecs) result = epoch_hours_call(self.hrs_unit, test_date) # NOTE: the calculation is only accurate to approx +/- 0.5 seconds # in such a large number of hours -- even 0.1 seconds is too fine. absolute_tolerance = 0.5 / 3600 self.assertArrayAllClose(result, -17269488.0 + hours_in_day, rtol=0, atol=absolute_tolerance)
def test_year_0(self): test_date = nc_datetime(0, 1, 1) result = epoch_hours_call(self.hrs_unit, test_date) self.assertEqual(result, -17020800.0)
def test_ymd_1_1_1(self): test_date = nc_datetime(1, 1, 1) result = epoch_hours_call(self.hrs_unit, test_date) self.assertEqual(result, -17012160.0)
def test_1970_1_1(self): test_date = nc_datetime(1970, 1, 1) result = epoch_hours_call(self.hrs_unit, test_date) self.assertEqual(result, 0.0)
def test_ymd_0_0_0(self): test_date = nc_datetime(0, 0, 0) result = epoch_hours_call(self.hrs_unit, test_date) self.assertEqual(result, -17269488.0)
def test_year_0(self): test_date = nc_datetime( 0, 1, 1, calendar=self.calendar, has_year_zero=True ) result = epoch_hours_call(self.hrs_unit, test_date) self.assertEqual(result, -17020800.0)
def test_ymd_0_0_0(self): test_date = nc_datetime(0, 0, 0, calendar=None, has_year_zero=True) result = epoch_hours_call(self.hrs_unit, test_date) self.assertEqual(result, -17269488.0)
def test_ymd_1_1_1(self): test_date = nc_datetime(1, 1, 1, calendar=self.calendar) result = epoch_hours_call(self.hrs_unit, test_date) self.assertEqual(result, -17259936.0)