Beispiel #1
0
def test_subclock_speedup(clock):
    """Test Subclock.speed works when set as attribute"""
    subclock = Subclock(clock)
    assert subclock.time == 0
    clock.advance_sync(1)
    assert subclock.time == 1
    subclock.speed = 2
    clock.advance_sync(1)
    assert subclock.time == 3
Beispiel #2
0
def test_subclock(clock):
    """Test Sublock works"""
    subclock = Subclock(clock)
    subclock.advance_sync(1)
    assert clock.time == 0
    assert subclock.time == 1
    clock.advance_sync(1)
    assert clock.time == 1
    assert subclock.time == 2
    subclock.speed = 2
    clock.advance_sync(1)
    assert clock.time == 2
    assert subclock.time == 4

    lst = []

    def _append_const(lst, value):
        def _append():
            lst.append(value)
        return _append

    subclock.schedule(1, _append_const(lst, 'a'))
    clock.schedule(1, _append_const(lst, 'b'))
    subclock.schedule(2, _append_const(lst, 'c'))
    clock.advance_sync(1)
    assert lst == ['a', 'b', 'c']