当前位置: 首页>>代码示例>>Python>>正文


Python Machine.walk方法代码示例

本文整理汇总了Python中transitions.Machine.walk方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.walk方法的具体用法?Python Machine.walk怎么用?Python Machine.walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在transitions.Machine的用法示例。


在下文中一共展示了Machine.walk方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_queued

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import walk [as 别名]
    def test_queued(self):
        states = ['A', 'B', 'C', 'D']
        # Define with list of dictionaries

        def change_state(machine):
            self.assertEqual(machine.current_state.name, 'A')
            if machine.has_queue:
                machine.run(machine=machine)
                self.assertEqual(machine.current_state.name, 'A')
            else:
                with self.assertRaises(MachineError):
                    machine.run(machine=machine)

        transitions = [
            {'trigger': 'walk', 'source': 'A', 'dest': 'B', 'before': change_state},
            {'trigger': 'run', 'source': 'B', 'dest': 'C'},
            {'trigger': 'sprint', 'source': 'C', 'dest': 'D'}
        ]

        m = Machine(states=states, transitions=transitions, initial='A')
        m.walk(machine=m)
        self.assertEqual(m.current_state.name, 'B')
        m = Machine(states=states, transitions=transitions, initial='A', queued=True)
        m.walk(machine=m)
        self.assertEqual(m.current_state.name, 'C')
开发者ID:Ak47slayer,项目名称:transitions,代码行数:27,代码来源:test_core.py

示例2: test_queued

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import walk [as 别名]
    def test_queued(self):
        states = ["A", "B", "C", "D"]
        # Define with list of dictionaries

        def change_state(machine):
            self.assertEqual(machine.current_state.name, "A")
            if machine.has_queue:
                machine.run(machine=machine)
                self.assertEqual(machine.current_state.name, "A")
            else:
                with self.assertRaises(MachineError):
                    machine.run(machine=machine)

        transitions = [
            {"trigger": "walk", "source": "A", "dest": "B", "before": change_state},
            {"trigger": "run", "source": "B", "dest": "C"},
            {"trigger": "sprint", "source": "C", "dest": "D"},
        ]

        m = Machine(states=states, transitions=transitions, initial="A")
        m.walk(machine=m)
        self.assertEqual(m.current_state.name, "B")
        m = Machine(states=states, transitions=transitions, initial="A", queued=True)
        m.walk(machine=m)
        self.assertEqual(m.current_state.name, "C")
开发者ID:khigia,项目名称:transitions,代码行数:27,代码来源:test_core.py

示例3: test_transition_definitions

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import walk [as 别名]
 def test_transition_definitions(self):
     states = ["A", "B", "C", "D"]
     # Define with list of dictionaries
     transitions = [
         {"trigger": "walk", "source": "A", "dest": "B"},
         {"trigger": "run", "source": "B", "dest": "C"},
         {"trigger": "sprint", "source": "C", "dest": "D"},
     ]
     m = Machine(states=states, transitions=transitions, initial="A")
     m.walk()
     self.assertEquals(m.state, "B")
     # Define with list of lists
     transitions = [["walk", "A", "B"], ["run", "B", "C"], ["sprint", "C", "D"]]
     m = Machine(states=states, transitions=transitions, initial="A")
     m.to_C()
     m.sprint()
     self.assertEquals(m.state, "D")
开发者ID:khigia,项目名称:transitions,代码行数:19,代码来源:test_core.py

示例4: test_transition_definitions

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import walk [as 别名]
 def test_transition_definitions(self):
     states = ['A', 'B', 'C', 'D']
     # Define with list of dictionaries
     transitions = [
         {'trigger': 'walk', 'source': 'A', 'dest': 'B'},
         {'trigger': 'run', 'source': 'B', 'dest': 'C'},
         {'trigger': 'sprint', 'source': 'C', 'dest': 'D'}
     ]
     m = Machine(states=states, transitions=transitions, initial='A')
     m.walk()
     self.assertEquals(m.state, 'B')
     # Define with list of lists
     transitions = [
         ['walk', 'A', 'B'],
         ['run', 'B', 'C'],
         ['sprint', 'C', 'D']
     ]
     m = Machine(states=states, transitions=transitions, initial='A')
     m.to_C()
     m.sprint()
     self.assertEquals(m.state, 'D')
开发者ID:TheMysteriousX,项目名称:transitions,代码行数:23,代码来源:test_core.py

示例5: test_pickle

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import walk [as 别名]
    def test_pickle(self):
        import sys
        if sys.version_info < (3, 4):
            import dill as pickle
        else:
            import pickle

        states = ['A', 'B', 'C', 'D']
        # Define with list of dictionaries
        transitions = [
            {'trigger': 'walk', 'source': 'A', 'dest': 'B'},
            {'trigger': 'run', 'source': 'B', 'dest': 'C'},
            {'trigger': 'sprint', 'source': 'C', 'dest': 'D'}
        ]
        m = Machine(states=states, transitions=transitions, initial='A')
        m.walk()
        dump = pickle.dumps(m)
        self.assertIsNotNone(dump)
        m2 = pickle.loads(dump)
        self.assertEqual(m.state, m2.state)
        m2.run()
开发者ID:TheMysteriousX,项目名称:transitions,代码行数:23,代码来源:test_core.py

示例6: test_pickle

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import walk [as 别名]
    def test_pickle(self):
        import sys

        if sys.version_info < (3, 4):
            import dill as pickle
        else:
            import pickle

        states = ["A", "B", "C", "D"]
        # Define with list of dictionaries
        transitions = [
            {"trigger": "walk", "source": "A", "dest": "B"},
            {"trigger": "run", "source": "B", "dest": "C"},
            {"trigger": "sprint", "source": "C", "dest": "D"},
        ]
        m = Machine(states=states, transitions=transitions, initial="A")
        m.walk()
        dump = pickle.dumps(m)
        self.assertIsNotNone(dump)
        m2 = pickle.loads(dump)
        self.assertEqual(m.state, m2.state)
        m2.run()
开发者ID:khigia,项目名称:transitions,代码行数:24,代码来源:test_core.py


注:本文中的transitions.Machine.walk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。