def test_raise_on_unknown_interval_unit(self): with self.assertRaisesRegex(ValueError, "invalid interval_unit"): utils.step_interval( self.dt, 3, unittest.mock.sentinel.foo, )
def test_month_unit(self): self.assertEqual( utils.step_interval( self.dt, 3, config.IntervalUnit.MONTH, ), datetime(2017, 3, 2, 9, 17, 26, 432304))
def test_year_unit(self): self.assertEqual( utils.step_interval( self.dt, 3, config.IntervalUnit.YEAR, ), datetime(2019, 12, 2, 9, 17, 26, 432304))
def test_week_unit(self): self.assertEqual( utils.step_interval( self.dt, 3, config.IntervalUnit.WEEK, ), self.dt + timedelta(days=7 * 3), )
def test_day_unit(self): self.assertEqual( utils.step_interval( self.dt, 3, config.IntervalUnit.DAY, ), self.dt + timedelta(days=3), )
def test_hour_unit(self): self.assertEqual( utils.step_interval( self.dt, 7, config.IntervalUnit.HOUR, ), self.dt + timedelta(seconds=60 * 60 * 7), )
def test_minute_unit(self): self.assertEqual( utils.step_interval( self.dt, 7, config.IntervalUnit.MINUTE, ), self.dt + timedelta(seconds=60 * 7), )
def test_reject_timezoned_timestamp(self): tz = pytz.timezone("Europe/Berlin") dt = tz.normalize(datetime.utcnow().replace(tzinfo=pytz.UTC)) with self.assertRaisesRegex(ValueError, "needs naive datetime"): utils.step_interval(dt, unittest.mock.sentinel.step, unittest.mock.sentinel.unit)