Exemple #1
0
def test_fsm_transition_condition_true():
    def test():
        return True

    state_machine = Fsm('idle')
    state_machine.append_transition(src='idle',
                                    event='on',
                                    condition=test,
                                    dst='playing')
    state_machine.event('on')
    assert state_machine.state == 'playing'
Exemple #2
0
def test_fsm_state_exit():
    a = 0

    def stop():
        nonlocal a
        a = a - 1

    state_machine = Fsm('playing')
    state_machine.append_state(name='playing', on_exit=stop)
    state_machine.append_transition(src='playing', event='off', dst='idle')
    state_machine.event('off')
    assert state_machine.state == 'idle'
    assert a == -1
Exemple #3
0
def test_fsm_state_enter():
    a = 0

    def start():
        nonlocal a
        a = a + 1

    state_machine = Fsm('idle')
    state_machine.append_state(name='playing', on_enter=start)
    state_machine.append_transition(src='idle', event='on', dst='playing')
    state_machine.event('on')
    assert state_machine.state == 'playing'
    assert a == 1
Exemple #4
0
def test_fsm_transition_action_only():
    a = 0

    def inc():
        nonlocal a
        a = a + 1

    state_machine = Fsm('idle')
    state_machine.append_transition(
        src='idle',
        event='on',
        action=inc,
    )
    state_machine.event('on')
    assert state_machine.state == 'idle'
    assert a == 1
Exemple #5
0
def test_fsm_transition_action_condition_false():
    a = 0

    def inc():
        nonlocal a
        a = a + 1

    def test():
        return False

    state_machine = Fsm('idle')
    state_machine.append_transition(src='idle',
                                    event='on',
                                    condition=test,
                                    action=inc,
                                    dst='playing')
    state_machine.event('on')
    assert state_machine.state == 'idle'
    assert a == 0
Exemple #6
0
def test_fsm_unknown_transition():
    state_machine = Fsm('idle')
    state_machine.event('on')
    assert state_machine.state == 'idle'
Exemple #7
0
def test_fsm_basic_transition():
    state_machine = Fsm('idle')
    state_machine.append_transition(src='idle', event='on', dst='playing')
    state_machine.event('on')
    assert state_machine.state == 'playing'