def test_timer_reports_how_many_times_it_triggered_since_last_wait():
    with Timer(interval=0.0125) as timer:
        timer.start()
        sleep(0.5)
        n = timer.wait()

        assert n >= 4
def test_timer_cannot_be_started_if_offset_and_interval_are_both_zero():
    with Timer() as timer:
        try:
            timer.start()
            assert False, u"should have thrown ValueError"
        except ValueError:
            # expected
            pass
def test_can_change_offset_while_timer_is_running():
    with Timer(offset=1.0) as timer:
        start = time()
        timer.start()
        timer.offset = 0.125
        timer.wait()

        duration = time() - start

        assert duration < 1
def test_timer_waits_for_time_to_pass():
    with Timer(offset=0.125) as timer:
        start = time()

        timer.start()
        timer.wait()

        duration = time() - start

        assert duration >= 0.125
def test_timer_can_repeat_with_interval():
    with Timer(interval=0.125) as timer:
        start = time()

        timer.start()
        timer.wait()
        timer.wait()

        duration = time() - start

        assert duration >= 0.25