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


Python Fysom.multiple方法代码示例

本文整理汇总了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"])
开发者ID:PeerXu,项目名称:fysom3,代码行数:27,代码来源:test_callbacks.py

示例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"])
开发者ID:PeerXu,项目名称:fysom3,代码行数:34,代码来源:test_callbacks.py

示例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, [])
开发者ID:PeerXu,项目名称:fysom3,代码行数:43,代码来源:test_callbacks.py


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