Esempio n. 1
0
    def test_remain_time_returns_positive_if_not_passed_duration_sec(
            self, duration):
        timer = Timer(duration=duration)

        remain_time = timer.remain_time()
        assert 0 < remain_time < duration

        with freeze_time(datetime.datetime.utcnow() +
                         datetime.timedelta(seconds=duration)) as frozen_time:
            frozen_time.tick(TICK_INTERVAL)
            remain_time = timer.remain_time()

            assert remain_time == 0
Esempio n. 2
0
    def test_reset_timer_restores_its_start_time(self):
        duration = 5
        offset = 1
        timer = Timer(duration=duration)

        with freeze_time(datetime.datetime.utcnow() + datetime.timedelta(
                seconds=duration - offset)) as frozen_time:
            frozen_time.tick(TICK_INTERVAL)
            assert 0 < timer.remain_time() < offset

            timer.reset()
            frozen_time.tick(TICK_INTERVAL)

            assert offset < timer.remain_time() < duration