本文整理汇总了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')
示例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")
示例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")
示例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')
示例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()
示例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()