本文整理汇总了Python中statemachine.StateMachine.set_state_done方法的典型用法代码示例。如果您正苦于以下问题:Python StateMachine.set_state_done方法的具体用法?Python StateMachine.set_state_done怎么用?Python StateMachine.set_state_done使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statemachine.StateMachine
的用法示例。
在下文中一共展示了StateMachine.set_state_done方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestStateMachine
# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import set_state_done [as 别名]
class TestStateMachine(object):
def setUp(self):
self.sm = StateMachine()
def test_can_transition_to_initial_state(self):
on_state_enter = call_counter()
self.sm.add_state("state1", on_enter=on_state_enter)
self.sm.tick()
assert on_state_enter.count == 1
def test_can_transition_to_second_state(self):
on_state2_enter = call_counter()
state1 = self.sm.add_state("state1")
state2 = self.sm.add_state("state2", on_enter=on_state2_enter)
self.sm.add_transition(state1, state2, "gone foobar")
self.sm.tick()
assert on_state2_enter.count == 0
self.sm.send_event("gone foobar")
self.sm.tick()
assert on_state2_enter.count == 1
def test_can_transition_to_itself(self):
on_state2_enter = call_counter()
state1 = self.sm.add_state("state1", on_enter=on_state2_enter)
self.sm.add_transition(state1, state1, "gone foobar")
self.sm.tick()
assert on_state2_enter.count == 1
self.sm.send_event("gone foobar")
self.sm.tick()
assert on_state2_enter.count == 2
def test_no_transition_until_state_done(self):
def on_state_enter():
return False
state1 = self.sm.add_state("state1", on_enter=on_state_enter)
state2 = self.sm.add_state("state2")
self.sm.add_transition(state1, state2, "gone foobar")
self.sm.tick()
self.sm.send_event("gone foobar")
self.sm.tick()
assert self.sm.current_state() == state1
self.sm.set_state_done()
self.sm.tick()
assert self.sm.current_state() == state2
def test_transition_triggers_callback(self):
on_transit = call_counter()
state1 = self.sm.add_state("state1")
state2 = self.sm.add_state("state2")
self.sm.add_transition(state1, state2, "gone foobar", on_transit=on_transit)
self.sm.tick()
assert on_transit.count == 0
self.sm.send_event("gone foobar")
self.sm.tick()
assert on_transit.count == 1