예제 #1
0
    def test_notify_with_PseudoState_can_make_choice(self):
        '''
        Test that pseudo choice can make a choice using on_start result
        '''
        def on_start(event, state):
            state.vars['payload'] = event.payload

        sm = StateMachine('test machine')

        src = sm.create_state('src')
        ps = sm.create_state('ps', PseudoState)
        tgt1 = sm.create_state('tgt1')
        tgt2 = sm.create_state('tgt2')

        src.add_transition_to(ps)

        ps.on_start = on_start
        guard1 = lambda evt, st: st.vars['payload'] == 'tgt1'
        ps.add_transition_to(tgt1, guard=guard1)

        guard2 = lambda evt, st: st.vars['payload'] == 'tgt2'
        ps.add_transition_to(tgt2, guard=guard2)

        # Test1
        sm.set_state(src)
        e = Event('test', 'tgt1')
        sm.notify(e)
        self.assertEqual(tgt1, sm.current_state)

        # Test2
        sm.set_state(src)
        e = Event('test', 'tgt2')
        sm.notify(e)
        self.assertEqual(tgt2, sm.current_state)
예제 #2
0
    def test_notify_with_PseudoState(self):

        sm = StateMachine('test machine')

        src = sm.create_state('src')
        ps = sm.create_state('ps', PseudoState)
        tgt = sm.create_state('tgt')

        src.add_transition_to(ps)
        ps.add_transition_to(tgt)

        sm.set_state(src)

        # Test1
        e = Event()
        sm.notify(e)

        self.assertEqual(tgt, sm.current_state)
예제 #3
0
    def test_notify_splits_streams_correctly(self):

        sm = StateMachine('test machine')

        src = sm.create_state('src')
        tgt1 = sm.create_state('tgt1')
        tgt2 = sm.create_state('tgt2')

        src.add_transition_to(tgt1, 'stream1')
        src.add_transition_to(tgt2, 'stream2')

        # Test1
        sm.set_state(src)
        sm.notify(Event('stream1'))
        self.assertEqual(tgt1, sm.current_state)

        # Test2
        sm.set_state(src)
        sm.notify(Event('stream2'))
        self.assertEqual(tgt2, sm.current_state)

        # Test3
        sm.set_state(src)
        sm.notify(Event())
        self.assertEqual(src, sm.current_state)
예제 #4
0
    def test_notify_with_PseudoState_can_store_vars(self):
        '''
        Test that on_start can store data in vars.
        '''
        def on_start(event, state):
            state.vars['payload'] = event.payload

        sm = StateMachine('test machine')

        src = sm.create_state('src')
        ps = sm.create_state('ps', PseudoState)

        src.add_transition_to(ps)
        ps.on_start = on_start

        sm.set_state(src)

        # Test1
        e = Event('test', 'payload')
        sm.notify(e)

        #self.assertEqual(tgt, sm.current_state)
        self.assertEqual('payload', ps.vars['payload'])