本文整理汇总了Python中fysom.Fysom.multiple方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.multiple方法的具体用法?Python Fysom.multiple怎么用?Python Fysom.multiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fysom.Fysom
的用法示例。
在下文中一共展示了Fysom.multiple方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FysomRepeatedAfterEventCallbackTests
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import multiple [as 别名]
class FysomRepeatedAfterEventCallbackTests(unittest.TestCase):
def setUp(self):
self.fired = []
def record_event(event):
self.fired.append(event.msg)
return 42
self.fsm = Fysom({
'initial': 'notcalled',
'events': [
{'name': 'multiple', 'src': 'notcalled', 'dst': 'called'},
{'name': 'multiple', 'src': 'called', 'dst': 'called'},
],
'callbacks': {
'onaftermultiple': record_event
}
})
def test_should_fire_onafter_event_repeatedly(self):
self.fsm.multiple(msg="first")
self.fsm.multiple(msg="second")
self.assertEqual(self.fired, ["first", "second"])
示例2: FysomEventWithStateCallbackTests
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import multiple [as 别名]
class FysomEventWithStateCallbackTests(unittest.TestCase):
def setUp(self):
self.fired_nocalled_to_called = []
self.fired_called_to_called = []
def record_event_nocalled_to_called(event):
self.fired_nocalled_to_called.append(event.msg)
return 42
def record_event_called_to_called(event):
self.fired_called_to_called.append(event.msg)
return 42
self.fsm = Fysom({
'initial': 'notcalled',
'events': [
{'name': 'multiple', 'src': 'notcalled', 'dst': 'called'},
{'name': 'multiple', 'src': 'called', 'dst': 'called'},
],
'callbacks': {
'onaftermultiple_notcalled_called': record_event_nocalled_to_called,
'onaftermultiple_called_called': record_event_called_to_called
}
})
def test_should_fire_on_event(self):
self.fsm.multiple(msg="first")
self.fsm.multiple(msg="second")
self.assertEqual(self.fired_nocalled_to_called, ["first"])
self.assertEqual(self.fired_called_to_called, ["second"])
示例3: FysomEventWithStateWithOnbeforeCallbackTests
# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import multiple [as 别名]
class FysomEventWithStateWithOnbeforeCallbackTests(unittest.TestCase):
def setUp(self):
self.fired_nocalled_to_called = []
self.fired_called_to_called = []
def record_event_nocalled_to_called(event):
self.fired_nocalled_to_called.append(event.msg)
return 42
def record_event_called_to_called(event):
self.fired_called_to_called.append(event.msg)
return 42
def record_event_before_notcalled_to_called(event):
return True
def record_event_before_called_to_called(event):
return False
self.fsm = Fysom({
'initial': 'notcalled',
'events': [
{'name': 'multiple', 'src': 'notcalled', 'dst': 'called'},
{'name': 'multiple', 'src': 'called', 'dst': 'called'},
],
'callbacks': {
'onbeforemultiple_notcalled_called': record_event_before_notcalled_to_called,
'onaftermultiple_notcalled_called': record_event_nocalled_to_called,
'onbeforemultiple_called_called': record_event_before_called_to_called,
'onaftermultiple_called_called': record_event_called_to_called
}
})
def test_onbefore_called_to_called_callbacks_raising_exceptions_should_not_be_eaten(self):
self.fsm.multiple(msg="first")
with self.assertRaises(Canceled):
self.fsm.multiple(msg="second")
self.assertEqual(self.fired_nocalled_to_called, ["first"])
self.assertEqual(self.fired_called_to_called, [])