def test_timer_comparison_coverage (): timer = Timer(timer_heap, 0, lambda: None) assert timer == timer timer.start(.1) assert timer < None time.sleep(.2)
def test_timer_time_remaining(): timer = Timer(timer_heap, 0, lambda: None) assert timer == timer timer.start(.1) time.sleep(0.05) remain = timer.remaining_time() assert 0.047 < remain < 0.052
def test_timer_time_elapsed(): timer = Timer(timer_heap, 0, lambda: None) assert timer == timer timer.start(.1) time.sleep(0.05) elapsed = timer.elapsed_time() assert 0.047 < elapsed < 0.052
def test_timer_uncaught_exception (caplog): """Stop timer test""" def fail (arg): assert False timer = Timer(timer_heap, 0, fail, "key1") timer.start(.1) time.sleep(.2) assert "assert False" in caplog.text()
def test_simple_timer (): """Simple timer test""" test_dict = {} def expired (arg): test_dict[arg] = 1 timer = Timer(timer_heap, 0, expired, "key1") timer.start(.1) time.sleep(.2) assert test_dict["key1"] == 1
def test_restart_timer (): """Stop timer test""" test_dict = {} def expired (arg): test_dict[arg] = 1 timer = Timer(timer_heap, 0, expired, "key1") timer.start(10) time.sleep(.1) timer.start(.1) time.sleep(.2) assert "key1" in test_dict
def test_remove_timer (): """Stop timer test""" test_dict = {} def expired (arg): test_dict[arg] = 1 timer = Timer(timer_heap, 0, expired, "key1") timer.start(.1) # Also test the string name of the timer. with timer_heap: time.sleep(.2) assert timer.is_scheduled() timer.stop() time.sleep(.2) assert "key1" not in test_dict