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


Python Machine.get_graph方法代码示例

本文整理汇总了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)
开发者ID:Justin-W,项目名称:transitions,代码行数:34,代码来源:test_graphing.py

示例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)
开发者ID:wtgee,项目名称:transitions,代码行数:33,代码来源:test_graphing.py

示例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
开发者ID:ehles,项目名称:rst2tr,代码行数:19,代码来源:fsm.py

示例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()
开发者ID:paulormart,项目名称:transitions,代码行数:24,代码来源:test_diagrams.py


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