本文整理汇总了Python中transitions.Machine.before_on_exit_A方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.before_on_exit_A方法的具体用法?Python Machine.before_on_exit_A怎么用?Python Machine.before_on_exit_A使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transitions.Machine
的用法示例。
在下文中一共展示了Machine.before_on_exit_A方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_callback_identification
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import before_on_exit_A [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()
示例2: test_callback_identification
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import before_on_exit_A [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()