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


Python TransitionTable.addTransition方法代码示例

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


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

示例1: test_addTransitionDoesNotMutate

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
 def test_addTransitionDoesNotMutate(self):
     """
     L{TransitionTable.addTransition} does not change the L{TransitionTable}
     it is called on.
     """
     table = TransitionTable({"foo": {"bar": Transition("baz", "quux")}})
     table.addTransition("apple", "banana", "clementine", "date")
     self.assertEqual({"foo": {"bar": Transition("baz", "quux")}}, table.table)
开发者ID:ClusterHQ,项目名称:machinist,代码行数:10,代码来源:test_fsm.py

示例2: build_convergence_loop_fsm

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
def build_convergence_loop_fsm(reactor, deployer):
    """
    Create a convergence loop FSM.

    :param IReactorTime reactor: Used to schedule delays in the loop.

    :param IDeployer deployer: Used to discover local state and calcualte
        necessary changes to match desired configuration.
    """
    I = ConvergenceLoopInputs
    O = ConvergenceLoopOutputs
    S = ConvergenceLoopStates

    table = TransitionTable()
    table = table.addTransition(
        S.STOPPED, I.STATUS_UPDATE, [O.STORE_INFO, O.CONVERGE], S.CONVERGING)
    table = table.addTransitions(
        S.CONVERGING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.STOP: ([], S.CONVERGING_STOPPING),
            I.ITERATION_DONE: ([O.CONVERGE], S.CONVERGING),
        })
    table = table.addTransitions(
        S.CONVERGING_STOPPING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.ITERATION_DONE: ([], S.STOPPED),
        })

    loop = ConvergenceLoop(reactor, deployer)
    fsm = constructFiniteStateMachine(
        inputs=I, outputs=O, states=S, initial=S.STOPPED, table=table,
        richInputs=[_ClientStatusUpdate], inputContext={},
        world=MethodSuffixOutputer(loop))
    loop.fsm = fsm
    return fsm
开发者ID:Waynelemars,项目名称:flocker,代码行数:37,代码来源:_loop.py

示例3: _build_convergence_loop_table

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
def _build_convergence_loop_table():
    """
    Create the ``TransitionTable`` needed by the convergence loop FSM.

    :return TransitionTable: The transition table for the state machine for
        converging on the cluster configuration.
    """
    I = ConvergenceLoopInputs
    O = ConvergenceLoopOutputs
    S = ConvergenceLoopStates

    table = TransitionTable()
    table = table.addTransition(
        S.STOPPED, I.STATUS_UPDATE, [O.STORE_INFO, O.CONVERGE], S.CONVERGING)
    table = table.addTransitions(
        S.CONVERGING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.STOP: ([], S.CONVERGING_STOPPING),
            I.SLEEP: ([O.SCHEDULE_WAKEUP], S.SLEEPING),
        })
    table = table.addTransitions(
        S.CONVERGING_STOPPING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.SLEEP: ([], S.STOPPED),
        })
    table = table.addTransitions(
        S.SLEEPING, {
            I.WAKEUP: ([O.CLEAR_WAKEUP, O.CONVERGE], S.CONVERGING),
            I.STOP: ([O.CLEAR_WAKEUP], S.STOPPED),
            I.STATUS_UPDATE: (
                [O.STORE_INFO, O.UPDATE_MAYBE_WAKEUP], S.SLEEPING),
            })
    return table
开发者ID:PradeepSingh1988,项目名称:flocker,代码行数:35,代码来源:_loop.py

示例4: test_addTransition

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
 def test_addTransition(self):
     """
     L{TransitionTable.addTransition} accepts a state, an input, an output,
     and a next state and adds the transition defined by those four values
     to a new L{TransitionTable} which it returns.
     """
     table = TransitionTable()
     more = table.addTransition("foo", "bar", "baz", "quux")
     self.assertEqual({"foo": {"bar": Transition("baz", "quux")}}, more.table)
开发者ID:ClusterHQ,项目名称:machinist,代码行数:11,代码来源:test_fsm.py

示例5: test_nextStateNotMissingIfInitial

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
    def test_nextStateNotMissingIfInitial(self):
        """
        L{MissingTransitionNextState} is not raised if a value defined by
        C{state} appears nowhere in C{transitions} as a next state but is given
        as C{initial}.
        """
        transitions = TransitionTable()
        transitions = transitions.addTransition(
            MoreState.amber, Input.apple, [Output.aardvark], MoreState.amber)
        transitions = transitions.addTerminalState(MoreState.blue)

        constructFiniteStateMachine(
            Input, Output, MoreState, transitions,
            MoreState.blue, [], {}, NULL_WORLD)
开发者ID:ClusterHQ,项目名称:machinist,代码行数:16,代码来源:test_fsm.py

示例6: test_extraInputContext

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
 def test_extraInputContext(self):
     """
     L{ExtraInputContext} is raised if there are keys in C{inputContext}
     which are not symbols in the output alphabet.
     """
     extra = object()
     transitions = TransitionTable()
     transitions = transitions.addTransition(
         State.amber, Input.apple, [Output.aardvark], State.amber)
     exc = self.assertRaises(
         ExtraInputContext,
         constructFiniteStateMachine,
         Input, Output, State, transitions,
         State.amber, [], {extra: None}, NULL_WORLD)
     self.assertEqual(({extra},), exc.args)
开发者ID:ClusterHQ,项目名称:machinist,代码行数:17,代码来源:test_fsm.py

示例7: test_invalidInitialState

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
 def test_invalidInitialState(self):
     """
     L{InvalidInitialState} is raised if the value given for C{initial} is
     not defined by C{state}.
     """
     extra = object()
     transitions = TransitionTable()
     transitions = transitions.addTransition(
         State.amber, Input.apple, [Output.aardvark], State.amber)
     exc = self.assertRaises(
         InvalidInitialState,
         constructFiniteStateMachine,
         Input, Output, State, transitions,
         extra, [], {}, NULL_WORLD)
     self.assertEqual((extra,), exc.args)
开发者ID:ClusterHQ,项目名称:machinist,代码行数:17,代码来源:test_fsm.py

示例8: test_missingTransitionNextState

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
    def test_missingTransitionNextState(self):
        """
        L{MissingTransitionNextState} is raised if any of the values defined by
        C{state} appears nowhere in C{transitions} as a next state.
        """
        transitions = TransitionTable()
        transitions = transitions.addTransition(
            MoreState.amber, Input.apple, [Output.aardvark], MoreState.amber)
        transitions = transitions.addTerminalState(MoreState.blue)

        exc = self.assertRaises(
            MissingTransitionNextState,
            constructFiniteStateMachine,
            Input, Output, MoreState, transitions,
            MoreState.amber, [], {}, NULL_WORLD)
        self.assertEqual(({MoreState.blue},), exc.args)
开发者ID:ClusterHQ,项目名称:machinist,代码行数:18,代码来源:test_fsm.py

示例9: test_richInputInterface

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
    def test_richInputInterface(self):
        """
        L{DoesNotImplement} is raised if a rich input type is given which does
        not implement the interface required by one of the outputs which can be
        produced when that input is received.
        """
        apple = trivialInput(Input.apple)
        transitions = TransitionTable()
        transitions = transitions.addTransition(
            State.amber, Input.apple, [Output.aardvark], State.amber)

        self.assertRaises(
            DoesNotImplement,
            constructFiniteStateMachine,
            Input, Output, State, transitions,
            State.amber, [apple], {Output.aardvark: IRequiredByAardvark},
            NULL_WORLD)
开发者ID:ClusterHQ,项目名称:machinist,代码行数:19,代码来源:test_fsm.py

示例10: build_convergence_loop_fsm

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
def build_convergence_loop_fsm(reactor, deployer):
    """
    Create a convergence loop FSM.

    Once cluster config+cluster state updates from control service are
    received the basic loop is:

    1. Discover local state.
    2. Calculate ``IStateChanges`` based on local state and cluster
       configuration and cluster state we received from control service.
    3. Execute the change.
    4. Sleep.

    However, if an update is received during sleep then we calculate based
    on that updated config+state whether a ``IStateChange`` needs to
    happen. If it does that means this change will have impact on what we
    do, so we interrupt the sleep. If calculation suggests a no-op then we
    keep sleeping. Notably we do **not** do a discovery of local state
    when an update is received while sleeping, since that is an expensive
    operation that can involve talking to external resources. Moreover an
    external update only implies external state/config changed, so we're
    not interested in the latest local state in trying to decide if this
    update requires us to do something; a recently cached version should
    suffice.

    :param IReactorTime reactor: Used to schedule delays in the loop.

    :param IDeployer deployer: Used to discover local state and calcualte
        necessary changes to match desired configuration.
    """
    I = ConvergenceLoopInputs
    O = ConvergenceLoopOutputs
    S = ConvergenceLoopStates

    table = TransitionTable()
    table = table.addTransition(
        S.STOPPED, I.STATUS_UPDATE, [O.STORE_INFO, O.CONVERGE], S.CONVERGING)
    table = table.addTransitions(
        S.CONVERGING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.STOP: ([], S.CONVERGING_STOPPING),
            I.SLEEP: ([O.SCHEDULE_WAKEUP], S.SLEEPING),
        })
    table = table.addTransitions(
        S.CONVERGING_STOPPING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.SLEEP: ([], S.STOPPED),
        })
    table = table.addTransitions(
        S.SLEEPING, {
            I.WAKEUP: ([O.CLEAR_WAKEUP, O.CONVERGE], S.CONVERGING),
            I.STOP: ([O.CLEAR_WAKEUP], S.STOPPED),
            I.STATUS_UPDATE: (
                [O.STORE_INFO, O.UPDATE_MAYBE_WAKEUP], S.SLEEPING),
            })

    loop = ConvergenceLoop(reactor, deployer)
    fsm = constructFiniteStateMachine(
        inputs=I, outputs=O, states=S, initial=S.STOPPED, table=table,
        richInputs=[_ClientStatusUpdate, _Sleep], inputContext={},
        world=MethodSuffixOutputer(loop))
    loop.fsm = fsm
    return fsm
开发者ID:bertothunder,项目名称:flocker,代码行数:65,代码来源:_loop.py

示例11: IFood

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]

class IFood(Interface):
    radius = Attribute("The radius of the food (all food is spherical)")



@implementer(IFood)
class Gravenstein(trivialInput(Input.apple)):
    # Conveniently, apples are approximately spherical.
    radius = 3



TRANSITIONS = TransitionTable()
TRANSITIONS = TRANSITIONS.addTransition(
    MoreState.amber, Input.apple, [Output.aardvark], MoreState.blue)
TRANSITIONS = TRANSITIONS.addTerminalState(MoreState.blue)


class FiniteStateMachineTests(TestCase):
    """
    Tests for the L{IFiniteStateMachine} provider returned by
    L{constructFiniteStateMachine}.
    """
    def setUp(self):
        self.animals = []
        self.initial = MoreState.amber

        self.world = AnimalWorld(self.animals)
        self.fsm = constructFiniteStateMachine(
            Input, Output, MoreState, TRANSITIONS, self.initial,
开发者ID:ClusterHQ,项目名称:machinist,代码行数:33,代码来源:test_fsm.py

示例12: NamedConstant

# 需要导入模块: from machinist import TransitionTable [as 别名]
# 或者: from machinist.TransitionTable import addTransition [as 别名]
    DISENGAGE_LOCK = NamedConstant()

class State(Names):
    LOCKED = NamedConstant()
    UNLOCKED = NamedConstant()
    ACTIVE = NamedConstant()
# end setup

# begin table def
from machinist import TransitionTable

table = TransitionTable()
# end table def

# begin first transition
table = table.addTransition(
    State.LOCKED, Input.FARE_PAID, [Output.DISENGAGE_LOCK], State.ACTIVE)
# end first transition

# begin second transition
table = table.addTransition(
    State.UNLOCKED, Input.ARM_TURNED, [Output.ENGAGE_LOCK], State.ACTIVE)
# end second transition

# begin last transitions
table = table.addTransitions(
    State.ACTIVE, {
        Input.ARM_UNLOCKED: ([], State.UNLOCKED),
        Input.ARM_LOCKED: ([], State.LOCKED),
        })
# end last transitions
开发者ID:ClusterHQ,项目名称:machinist,代码行数:33,代码来源:turnstile.py


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