Exemple #1
0
def test_timer_comparison_coverage ():
    timer = Timer(timer_heap, 0, lambda: None)
    assert timer == timer

    timer.start(.1)
    assert timer < None
    time.sleep(.2)
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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()
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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