コード例 #1
0
def test_subscriptable():
    def callback():
        pass

    tm = taskmanager.TaskManager()
    task = tm.add_task('subscriptable', callback, 0, False)
    assert task == tm['subscriptable']
コード例 #2
0
def test_timing():
    def callback(a):
        a.append(1)

    cb_counter = []
    tm = taskmanager.TaskManager()
    tm.add_task('counter_task', callback, 0.02, False, (cb_counter, ))
    start_time = time.perf_counter()
    CLK.tick()
    while time.perf_counter() - start_time < 1:
        CLK.tick()
        tm(CLK.get_dt())
    assert sum(cb_counter) == 49
コード例 #3
0
def test_taskmanager():
    def callback_no_dt(arg_a, arg_b, _=None, kwarg_a='blah'):
        assert arg_a == 'a'
        assert arg_b == 'b'
        assert kwarg_a == 'kwa'

    def callback_dt(dt):
        assert dt == 0.0

    tm = taskmanager.TaskManager()
    tm.add_task('test_task_no_dt', callback_no_dt, 0, False, ('a', 'b'),
                {'kwarg_a': 'kwa'})
    tm.add_task('test_task_dt', 0, True, callback_dt)
    tm(0)
コード例 #4
0
def test_delay_change():
    def callback(t):
        assert time.perf_counter() - t > 0.5

    tm = taskmanager.TaskManager()
    CLK.tick()
    tm(CLK.get_dt())
    task = tm.add_task('delay_change', callback, 0, False,
                       (time.perf_counter(), ))
    task.delay = 0.5
    CLK.tick()
    tm(CLK.get_dt())
    time.sleep(0.5)
    CLK.tick()
    tm(CLK.get_dt())
コード例 #5
0
def test_pause_resume():
    def callback(a):
        a.append(1)

    cb_counter = []
    tm = taskmanager.TaskManager()
    task = tm.add_task('pause_test', callback, 0, False, (cb_counter, ))
    tm(0)
    assert sum(cb_counter) == 1
    task.pause()
    tm(0)
    assert task.ispaused is True
    assert sum(cb_counter) == 1
    task.resume()
    tm(0)
    assert task.ispaused is False
    assert sum(cb_counter) == 2