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


Python transitions.MachineError方法代码示例

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


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

示例1: execute

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def execute(self) -> response.Response:
        """Called when the user specifies an intent for this skill"""
        intent = self.attributes.intent
        previous_state = self.state

        # backup attributes in case of invalid FSM transition
        attributes_backup = self.attributes
        try:
            # trigger is added by transitions library
            self.trigger(intent)
            current_state = self.state
            logger.info(f"Changed from {previous_state} to {current_state} through {intent}")
            self.attributes.state = current_state
            return self.get_current_state_response()
        except MachineError as exception:
            logger.error(str(exception))
            # reset attributes
            self.states.attributes = attributes_backup
            return response.NOT_UNDERSTOOD 
开发者ID:allenai,项目名称:alexafsm,代码行数:21,代码来源:policy.py

示例2: test_queued

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def test_queued(self):
        states = ['A', 'B', 'C', 'D']
        # Define with list of dictionaries

        def change_state(machine):
            self.assertEqual(machine.state, 'A')
            if machine.has_queue:
                machine.run(machine=machine)
                self.assertEqual(machine.state, 'A')
            else:
                with self.assertRaises(MachineError):
                    machine.run(machine=machine)

        transitions = [
            {'trigger': 'walk', 'source': 'A', 'dest': 'B', 'before': change_state},
            {'trigger': 'run', 'source': 'B', 'dest': 'C'},
            {'trigger': 'sprint', 'source': 'C', 'dest': 'D'}
        ]

        m = Machine(states=states, transitions=transitions, initial='A')
        m.walk(machine=m)
        self.assertEqual(m.state, 'B')
        m = Machine(states=states, transitions=transitions, initial='A', queued=True)
        m.walk(machine=m)
        self.assertEqual(m.state, 'C') 
开发者ID:pytransitions,项目名称:transitions,代码行数:27,代码来源:test_core.py

示例3: test_queued_errors

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def test_queued_errors(self):
        def before_change(machine):
            if machine.has_queue:
                machine.to_A(machine)
            machine._queued = False

        def after_change(machine):
            machine.to_C(machine)

        def failed_transition(machine):
            raise ValueError('Something was wrong')

        states = ['A', 'B', 'C']
        transitions = [{'trigger': 'do', 'source': '*', 'dest': 'C', 'before': failed_transition}]
        m = Machine(states=states, transitions=transitions, queued=True,
                    before_state_change=before_change, after_state_change=after_change)
        with self.assertRaises(MachineError):
            m.to_B(machine=m)

        with self.assertRaises(ValueError):
            m.do(machine=m) 
开发者ID:pytransitions,项目名称:transitions,代码行数:23,代码来源:test_core.py

示例4: test_remove_transition

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def test_remove_transition(self):
        self.stuff.machine.add_transition('go', ['A', 'B', 'C'], 'D')
        self.stuff.machine.add_transition('walk', 'A', 'B')
        self.stuff.go()
        self.assertEqual(self.stuff.state, 'D')
        self.stuff.to_A()
        self.stuff.machine.remove_transition('go', source='A')
        with self.assertRaises(MachineError):
            self.stuff.go()
        self.stuff.machine.add_transition('go', 'A', 'D')
        self.stuff.walk()
        self.stuff.go()
        self.assertEqual(self.stuff.state, 'D')
        self.stuff.to_C()
        self.stuff.machine.remove_transition('go', dest='D')
        self.assertFalse(hasattr(self.stuff, 'go')) 
开发者ID:pytransitions,项目名称:transitions,代码行数:18,代码来源:test_core.py

示例5: main

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def main():
    p = Process("p1")
    print("initial state: {}".format(p.state))

    old = p.state
    print("\nwake_up trigger")
    p.wake_up()
    print("{} -> {}".format(old, p.state))

    old = p.state
    print("\nstart trigger")
    p.start()
    print("{} -> {}".format(old, p.state))

    old = p.state
    print("\nrandom trigger (stay in current state or go to terminated 50/50)")
    p.random_trigger()
    print("{} -> {}".format(old, p.state))

    old = p.state
    print("\ninterrupt trigger")
    p.interrupt()
    print("{} -> {}".format(old, p.state))

    print('\nFrom "terminated" we cannot trigger a "start" event')
    try:
        p.start()
    except MachineError as e:
        print(e) 
开发者ID:jackdbd,项目名称:design-patterns,代码行数:31,代码来源:state.py

示例6: testUnconnectedDisconnect

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def testUnconnectedDisconnect(self):
        with self.assertRaises(MachineError):
            self.stateMachine.disconnect() 
开发者ID:bparzella,项目名称:secsgem,代码行数:5,代码来源:test_hsms_connection_state_model.py

示例7: testUnconnectedSelect

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def testUnconnectedSelect(self):
        with self.assertRaises(MachineError):
            self.stateMachine.select() 
开发者ID:bparzella,项目名称:secsgem,代码行数:5,代码来源:test_hsms_connection_state_model.py

示例8: testUnconnectedDeselect

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def testUnconnectedDeselect(self):
        with self.assertRaises(MachineError):
            self.stateMachine.deselect() 
开发者ID:bparzella,项目名称:secsgem,代码行数:5,代码来源:test_hsms_connection_state_model.py

示例9: testUnconnectedTimeoutT7

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def testUnconnectedTimeoutT7(self):
        with self.assertRaises(MachineError):
            self.stateMachine.timeoutT7() 
开发者ID:bparzella,项目名称:secsgem,代码行数:5,代码来源:test_hsms_connection_state_model.py

示例10: testConnectedNotSelectedConnect

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def testConnectedNotSelectedConnect(self):
        self.stateMachine.connect()
        with self.assertRaises(MachineError):
            self.stateMachine.connect() 
开发者ID:bparzella,项目名称:secsgem,代码行数:6,代码来源:test_hsms_connection_state_model.py

示例11: testConnectedSelectedConnect

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def testConnectedSelectedConnect(self):
        self.stateMachine.connect()
        self.stateMachine.select()
        with self.assertRaises(MachineError):
            self.stateMachine.connect() 
开发者ID:bparzella,项目名称:secsgem,代码行数:7,代码来源:test_hsms_connection_state_model.py

示例12: testConnectedSelectedSelect

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def testConnectedSelectedSelect(self):
        self.stateMachine.connect()
        self.stateMachine.select()
        with self.assertRaises(MachineError):
            self.stateMachine.select() 
开发者ID:bparzella,项目名称:secsgem,代码行数:7,代码来源:test_hsms_connection_state_model.py

示例13: testConnectedSelectedTimeoutT7

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def testConnectedSelectedTimeoutT7(self):
        self.stateMachine.connect()
        self.stateMachine.select()
        with self.assertRaises(MachineError):
            self.stateMachine.timeoutT7()

    # tests for callbacks 
开发者ID:bparzella,项目名称:secsgem,代码行数:9,代码来源:test_hsms_connection_state_model.py

示例14: shutdown

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def shutdown(self):
        """
            Stop broker instance.

            Closes all connected session, stop listening on network socket and free resources.
        """
        try:
            self._sessions = dict()
            self._subscriptions = dict()
            self._retained_messages = dict()
            self.transitions.shutdown()
        except (MachineError, ValueError) as exc:
            # Backwards compat: MachineError is raised by transitions < 0.5.0.
            self.logger.debug("Invalid method call at this moment: %s" % exc)
            raise BrokerException("Broker instance can't be stopped: %s" % exc)

        # Fire broker_shutdown event to plugins
        yield from self.plugins_manager.fire_event(EVENT_BROKER_PRE_SHUTDOWN)

        # Stop broadcast loop
        if self._broadcast_task:
            self._broadcast_task.cancel()
        if self._broadcast_queue.qsize() > 0:
            self.logger.warning("%d messages not broadcasted" % self._broadcast_queue.qsize())

        for listener_name in self._servers:
            server = self._servers[listener_name]
            yield from server.close_instance()
        self.logger.debug("Broker closing")
        self.logger.info("Broker closed")
        yield from self.plugins_manager.fire_event(EVENT_BROKER_POST_SHUTDOWN)
        self.transitions.stopping_success() 
开发者ID:beerfactory,项目名称:hbmqtt,代码行数:34,代码来源:broker.py

示例15: test_prepare

# 需要导入模块: import transitions [as 别名]
# 或者: from transitions import MachineError [as 别名]
def test_prepare(self):
        m = Machine(Stuff(), states=['A', 'B', 'C'], initial='A')
        m.add_transition('move', 'A', 'B', prepare='increase_level')
        m.add_transition('move', 'B', 'C', prepare='increase_level')
        m.add_transition('move', 'C', 'A', prepare='increase_level', conditions='this_fails')
        m.add_transition('dont_move', 'A', 'C', prepare='increase_level')

        m.prepare_move('increase_level')

        m.model.move()
        self.assertEqual(m.model.state, 'B')
        self.assertEqual(m.model.level, 3)

        m.model.move()
        self.assertEqual(m.model.state, 'C')
        self.assertEqual(m.model.level, 5)

        # State does not advance, but increase_level still runs
        m.model.move()
        self.assertEqual(m.model.state, 'C')
        self.assertEqual(m.model.level, 7)

        # An invalid transition shouldn't execute the callback
        try:
            m.model.dont_move()
        except MachineError as e:
            self.assertTrue("Can't trigger event" in str(e))

        self.assertEqual(m.model.state, 'C')
        self.assertEqual(m.model.level, 7) 
开发者ID:pytransitions,项目名称:transitions,代码行数:32,代码来源:test_core.py


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