當前位置: 首頁>>代碼示例>>Python>>正文


Python StateMachine.set_state_done方法代碼示例

本文整理匯總了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
開發者ID:wotmods,項目名稱:wot-teamspeak-mod,代碼行數:58,代碼來源:statemachine_test.py


注:本文中的statemachine.StateMachine.set_state_done方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。