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
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