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


Python Machine.after_check方法代码示例

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


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

示例1: test_callback_identification

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import after_check [as 别名]
    def test_callback_identification(self):
        m = Machine(Stuff(), states=['A', 'B', 'C', 'D', 'E', 'F'], initial='A')
        m.add_transition('transition', 'A', 'B', before='increase_level')
        m.add_transition('after', 'B', 'C', before='increase_level')
        m.add_transition('on_exit_A', 'C', 'D', before='increase_level', conditions='this_fails')
        m.add_transition('check', 'C', 'E', before='increase_level')
        m.add_transition('prepare', 'E', 'F', before='increase_level')
        m.add_transition('before', 'F', 'A', before='increase_level')

        m.before_transition('increase_level')
        m.before_after('increase_level')
        m.before_on_exit_A('increase_level')
        m.after_check('increase_level')
        m.before_prepare('increase_level')
        m.before_before('increase_level')

        m.model.transition()
        self.assertEquals(m.model.state, 'B')
        self.assertEquals(m.model.level, 3)

        m.model.after()
        self.assertEquals(m.model.state, 'C')
        self.assertEquals(m.model.level, 5)

        m.model.on_exit_A()
        self.assertEquals(m.model.state, 'C')
        self.assertEquals(m.model.level, 5)

        m.model.check()
        self.assertEquals(m.model.state, 'E')
        self.assertEquals(m.model.level, 7)

        m.model.prepare()
        self.assertEquals(m.model.state, 'F')
        self.assertEquals(m.model.level, 9)

        m.model.before()
        self.assertEquals(m.model.state, 'A')
        self.assertEquals(m.model.level, 11)

        # An invalid transition shouldn't execute the callback
        with self.assertRaises(MachineError):
                m.model.on_exit_A()
开发者ID:Ak47slayer,项目名称:transitions,代码行数:45,代码来源:test_core.py

示例2: test_callback_identification

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import after_check [as 别名]
    def test_callback_identification(self):
        m = Machine(Stuff(), states=["A", "B", "C", "D", "E", "F"], initial="A")
        m.add_transition("transition", "A", "B", before="increase_level")
        m.add_transition("after", "B", "C", before="increase_level")
        m.add_transition("on_exit_A", "C", "D", before="increase_level", conditions="this_fails")
        m.add_transition("check", "C", "E", before="increase_level")
        m.add_transition("prepare", "E", "F", before="increase_level")
        m.add_transition("before", "F", "A", before="increase_level")

        m.before_transition("increase_level")
        m.before_after("increase_level")
        m.before_on_exit_A("increase_level")
        m.after_check("increase_level")
        m.before_prepare("increase_level")
        m.before_before("increase_level")

        m.model.transition()
        self.assertEquals(m.model.state, "B")
        self.assertEquals(m.model.level, 3)

        m.model.after()
        self.assertEquals(m.model.state, "C")
        self.assertEquals(m.model.level, 5)

        m.model.on_exit_A()
        self.assertEquals(m.model.state, "C")
        self.assertEquals(m.model.level, 5)

        m.model.check()
        self.assertEquals(m.model.state, "E")
        self.assertEquals(m.model.level, 7)

        m.model.prepare()
        self.assertEquals(m.model.state, "F")
        self.assertEquals(m.model.level, 9)

        m.model.before()
        self.assertEquals(m.model.state, "A")
        self.assertEquals(m.model.level, 11)

        # An invalid transition shouldn't execute the callback
        with self.assertRaises(MachineError):
            m.model.on_exit_A()
开发者ID:khigia,项目名称:transitions,代码行数:45,代码来源:test_core.py


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