Ejemplo n.º 1
0
 def test_set_remaining_succeeds_when_remaining_is_less_than_duration(self):
     duration = datetime.timedelta(days=3)
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          1,
                                                          0,
                                                          0,
                                                          0,
                                                          0,
                                                          tzinfo=pytz.utc)
     timer = clock.Timer(self.mock_clock, duration)
     timer.set_remaining(datetime.timedelta(days=1))
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          1,
                                                          23,
                                                          59,
                                                          59,
                                                          999999,
                                                          tzinfo=pytz.utc)
     self.assertFalse(timer.expired())
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          2,
                                                          0,
                                                          0,
                                                          0,
                                                          0,
                                                          tzinfo=pytz.utc)
     self.assertTrue(timer.expired())
Ejemplo n.º 2
0
 def test_timer_duration_not_matched_or_exceeded(self):
     duration = datetime.timedelta(hours=3 * 24)
     self.mock_clock.now.side_effect = [
         datetime.datetime(
             2000, 1, 1, 0, 0, 0, 0, tzinfo=pytz.utc),
         datetime.datetime(
             2000, 1, 3, 0, 0, 0, 0, tzinfo=pytz.utc)
     ]  # yapf: disable
     self.assertFalse(clock.Timer(self.mock_clock, duration).expired())
Ejemplo n.º 3
0
 def test_set_remaining_succeeds_when_remaining_is_zero(self):
     duration = datetime.timedelta(days=3)
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          1,
                                                          0,
                                                          0,
                                                          0,
                                                          0,
                                                          tzinfo=pytz.utc)
     timer = clock.Timer(self.mock_clock, duration)
     timer.set_remaining(datetime.timedelta(seconds=0))
     self.assertTrue(timer.expired())
Ejemplo n.º 4
0
 def test_set_remaining_fails_when_remaining_is_negative(self):
     duration = datetime.timedelta(days=3)
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          1,
                                                          0,
                                                          0,
                                                          0,
                                                          0,
                                                          tzinfo=pytz.utc)
     timer = clock.Timer(self.mock_clock, duration)
     with self.assertRaises(ValueError):
         timer.set_remaining(datetime.timedelta(days=-1))
Ejemplo n.º 5
0
 def test_reset(self):
     duration = datetime.timedelta(hours=3 * 24)
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          1,
                                                          0,
                                                          0,
                                                          0,
                                                          0,
                                                          tzinfo=pytz.utc)
     timer = clock.Timer(self.mock_clock, duration)
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          2,
                                                          0,
                                                          0,
                                                          0,
                                                          0,
                                                          tzinfo=pytz.utc)
     timer.reset()
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          4,
                                                          23,
                                                          59,
                                                          59,
                                                          999999,
                                                          tzinfo=pytz.utc)
     # First expired call is one microsecond before when the timer should
     # expire, second is right when it should expire.
     self.assertFalse(timer.expired())
     self.mock_clock.now.return_value = datetime.datetime(2000,
                                                          1,
                                                          5,
                                                          0,
                                                          0,
                                                          0,
                                                          0,
                                                          tzinfo=pytz.utc)
     self.assertTrue(timer.expired())