本文整理汇总了Python中transitions.Machine.get_graph方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.get_graph方法的具体用法?Python Machine.get_graph怎么用?Python Machine.get_graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transitions.Machine
的用法示例。
在下文中一共展示了Machine.get_graph方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_agraph_diagram
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import get_graph [as 别名]
def test_agraph_diagram(self):
states = ['A', 'B', 'C', 'D']
transitions = [
{'trigger': 'walk', 'source': 'A', 'dest': 'B'},
{'trigger': 'run', 'source': 'B', 'dest': 'C'},
{'trigger': 'sprint', 'source': 'C', 'dest': 'D', 'conditions': 'is_fast'},
{'trigger': 'sprint', 'source': 'C', 'dest': 'B'}
]
m = Machine(states=states, transitions=transitions, initial='A', auto_transitions=False)
graph = m.get_graph()
self.assertIsNotNone(graph)
self.assertTrue("digraph" in str(graph))
# Test that graph properties match the Machine
self.assertEqual(
set(m.states.keys()), set([n.name for n in graph.nodes()]))
triggers = set([n.attr['label'] for n in graph.edges()])
for t in triggers:
self.assertIsNotNone(getattr(m, t))
self.assertEqual(len(graph.edges()), len(transitions))
# check for a valid pygraphviz diagram
# write diagram to temp file
target = tempfile.NamedTemporaryFile()
graph.draw(target.name, prog='dot')
self.assertTrue(os.path.getsize(target.name) > 0)
# cleanup temp file
target.close()
print(graph)
示例2: test_agraph_diagram
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import get_graph [as 别名]
def test_agraph_diagram(self):
states = ["A", "B", "C", "D"]
transitions = [
{"trigger": "walk", "source": "A", "dest": "B"},
{"trigger": "run", "source": "B", "dest": "C"},
{"trigger": "sprint", "source": "C", "dest": "D", "conditions": "is_fast"},
{"trigger": "sprint", "source": "C", "dest": "B"},
]
m = Machine(states=states, transitions=transitions, initial="A", auto_transitions=False)
graph = m.get_graph()
self.assertIsNotNone(graph)
self.assertTrue("digraph" in str(graph))
# Test that graph properties match the Machine
self.assertEqual(set(m.states.keys()), set([n.name for n in graph.nodes()]))
triggers = set([n.attr["label"] for n in graph.edges()])
for t in triggers:
self.assertIsNotNone(getattr(m, t))
self.assertEqual(len(graph.edges()), len(transitions))
# check for a valid pygraphviz diagram
# write diagram to temp file
target = tempfile.NamedTemporaryFile()
graph.draw(target.name, prog="dot")
self.assertTrue(os.path.getsize(target.name) > 0)
# cleanup temp file
target.close()
print(graph)
示例3: get_fsm
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import get_graph [as 别名]
def get_fsm(self):
reader = FormatReader()
states = ['start', 'suite', 'case', 'section', 'step']
initial = states[0]
transitions = [
{'trigger': 't_section', 'source': 'document', 'dest': 'title'},
{'trigger': 't_section', 'source': 'document', 'dest': 'title'},
{'trigger': 't_step', 'source': 'section', 'dest': 'step'},
]
machine = Machine(model=reader,
states=states,
transitions=transitions,
initial=initial)
graph = machine.get_graph()
graph.draw('fsm.png', prog='dot')
return machine
示例4: test_agraph_diagram
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import get_graph [as 别名]
def test_agraph_diagram(self):
states = ['A', 'B', 'C', 'D']
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')
graph = m.get_graph()
# check for a valid pygraphviz diagram
self.assertIsNotNone(graph)
self.assertTrue("digraph" in str(graph))
# write diagram to temp file
target = tempfile.NamedTemporaryFile()
graph.draw(target.name, prog='dot')
self.assertTrue(os.path.getsize(target.name) > 0)
# cleanup temp file
target.close()