コード例 #1
0
def test_simple_timer():
    r_list = []
    def _func(now, t):
        r_list.append(from_nanotime(now))

    now = time.time()
    t = Timer(_func, 0.1)
    t.start()
    run()
    delay = r_list[0]
    assert (now + 0.09) <= delay <= (now + 0.11), delay
コード例 #2
0
def test_simple_timer():
    r_list = []

    def _func(now, t):
        r_list.append(from_nanotime(now))

    now = time.time()
    t = Timer(_func, 0.1)
    t.start()
    run()
    delay = r_list[0]
    assert (now + 0.09) <= delay <= (now + 0.11), delay
コード例 #3
0
def test_repeat():
    r = []
    def f(now, t):
        if len(r) == 3:
            t.stop()
            return
        r.append(now)

    t = Timer(f, 0.01, 0.01)
    t.start()
    run()
    assert len(r) == 3
    assert r[2] > r[1]
    assert r[1] > r[0]
コード例 #4
0
def test_repeat():
    r = []

    def f(now, t):
        if len(r) == 3:
            t.stop()
            return
        r.append(now)

    t = Timer(f, 0.01, 0.01)
    t.start()
    run()
    assert len(r) == 3
    assert r[2] > r[1]
    assert r[1] > r[0]
コード例 #5
0
def test_multiple_timer():
    r1 = []

    def f(now, t):
        r1.append(from_nanotime(now))

    r2 = []

    def f1(now, t):
        r2.append(from_nanotime(now))

    now = time.time()

    t = Timer(f, 0.4)
    t.start()

    t1 = Timer(f1, 0.1)
    t1.start()

    run()
    assert r1[0] > r2[0]
    assert (now + 0.39) <= r1[0] <= (now + 0.41), r1[0]
    assert (now + 0.09) <= r2[0] <= (now + 0.11), r2[0]
コード例 #6
0
def test_multiple_timer():
    r1 = []
    def f(now, t):
        r1.append(from_nanotime(now))

    r2 = []
    def f1(now, t):
        r2.append(from_nanotime(now))

    now = time.time()

    t = Timer(f, 0.4)
    t.start()

    t1 = Timer(f1, 0.1)
    t1.start()

    run()
    assert r1[0] > r2[0]
    assert (now + 0.39) <= r1[0] <= (now + 0.41), r1[0]
    assert (now + 0.09) <= r2[0] <= (now + 0.11), r2[0]