本文整理匯總了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)
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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,
示例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