示例#1
0
def test_repeat_non_blocking():
    """
    A repeated action (i.e. timer) should always be executed in a separate
    thread, even the first execution.
    """
    def foo(x):
        time.sleep(x)

    timer = repeat(1., foo, 2.)
    timer.stop()
示例#2
0
def test_repeat_non_blocking():
    """
    A repeated action (i.e. timer) should always be executed in a separate
    thread, even the first execution.
    """
    def foo(x):
        time.sleep(x)

    timer = repeat(1., foo, 2.)
    timer.stop()
示例#3
0
def test_repeat_stop():
    """
    Test closing a timer returned by repeat.
    """
    class Bar():
        def __init__(self):
            self.a = 0

        def foo(self):
            self.a += 1

    bar = Bar()
    timer = repeat(0.1, bar.foo)
    time.sleep(1.)
    assert abs(bar.a - 10) <= 1
    timer.stop()
    time.sleep(1.)
    assert abs(bar.a - 10) <= 1
示例#4
0
def test_repeat_stop():
    """
    Test closing a timer returned by repeat.
    """
    class Bar():
        def __init__(self):
            self.a = 0

        def foo(self):
            self.a += 1

    bar = Bar()
    timer = repeat(0.1, bar.foo)
    time.sleep(1.)
    assert abs(bar.a - 10) <= 1
    timer.stop()
    time.sleep(1.)
    assert abs(bar.a - 10) <= 1