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


Python StateMachine.send_event方法代码示例

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


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

示例1: TestStateMachine

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import send_event [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
开发者ID:wotmods,项目名称:wot-teamspeak-mod,代码行数:58,代码来源:statemachine_test.py


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