def test_spring_forward(self): """This test checks the behavior of the scheduler at the daylight savings time 'spring forward' point, when the system time zone changes from (e.g.) PST to PDT. """ sch = scheduler.GeneralScheduler(time_zone=pytz.timezone('US/Pacific')) # Exact crossover time: # datetime.datetime(2011, 3, 13, 2, 0, 0, tzinfo=pytz.utc) # This test will use times on either side of it. # From the PST vantage point, the run time is 20.2 hours away: s1a, s1b = self.hours_diff_at_datetime(sch, 2011, 3, 13, 2, 50, 0) # From the PDT vantage point, the run time is 20.8 hours away: # (this is measured from the point in absolute time 20 minutes after # the other measurement) s2a, s2b = self.hours_diff_at_datetime(sch, 2011, 3, 13, 3, 10, 0) self._assert_range(s1b - s1a, 23.99, 24.11) self._assert_range(s2b - s2a, 23.99, 24.11) self._assert_range(s1a - s2a, -0.61, -0.59)
def build_scheduler(self): self.scheduler = scheduler.GeneralScheduler(timestr='14:30') one_day = datetime.timedelta(days=1) self.today = self.now.date() self.yesterday = self.now - one_day self.tomorrow = self.now + one_day
def test_handles_changing_the_time_zone(self): pacific_now = datetime.datetime.now(pytz.timezone('US/Pacific')) pacific_offset = pacific_now.utcoffset().total_seconds() / 60 / 60 sch = scheduler.GeneralScheduler(time_zone=pytz.timezone('US/Pacific')) next_run_time = sch.next_run_time(self.now_utc) assert_equal(next_run_time.hour, -pacific_offset)
def test_handles_unsetting_the_time_zone(self): sch = scheduler.GeneralScheduler(time_zone=None) next_run_time = sch.next_run_time(self.now_utc) assert_equal(next_run_time.hour, 0)
def test_handles_tz_specific_jobs_with_tz_specific_start_time(self): sch = scheduler.GeneralScheduler(time_zone=pytz.timezone('UTC')) next_run_time = sch.next_run_time(self.now_utc) assert_equal(next_run_time.hour, 0)
def test_correct_time(self): sch = scheduler.GeneralScheduler(time_zone=pytz.timezone('US/Pacific')) next_run_time = sch.next_run_time(self.now) assert_equal(next_run_time.hour, 0)
def build_scheduler(self): self.scheduler = scheduler.GeneralScheduler(timestr='14:30')