def test_repr(self): """ The result of L{repr} when called with an instance of the type returned by L{trivialInput} is a string that mentions the symbol name and nothing else. """ self.assertEqual("<Apple>", repr(trivialInput(Input.apple)()))
def test_illegalRichInput(self): """ L{IFiniteStateMachine.receive} raises L{IllegalInput} if called with a rich input that doesn't map to a symbol in the input alphabet. """ banana = trivialInput(MoreInput.banana) exc = self.assertRaises(IllegalInput, self.fsm.receive, banana()) self.assertEqual((MoreInput.banana,), exc.args)
def test_illegalRichInput(self): """ L{IFiniteStateMachine.receive} raises L{IllegalInput} if called with a rich input that doesn't map to a symbol in the input alphabet. """ banana = trivialInput(MoreInput.banana) exc = self.assertRaises(IllegalInput, self.fsm.receive, banana()) self.assertEqual((MoreInput.banana, ), exc.args)
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)
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)
class _Sleep(trivialInput(ConvergenceLoopInputs.SLEEP)): """ Sleep for given number of seconds. :ivar float delay_seconds: How many seconds to sleep. """ @classmethod def with_jitter(cls, delay_seconds): """ Add some noise to the delay, so sleeps aren't exactly the same across all processes. :param delay_seconds: How many seconds to sleep approximately. :return: ``_Sleep`` with jitter added. """ jitter = 1 + uniform(-0.2, 0.2) return cls(delay_seconds=delay_seconds * jitter)
class _ClientStatusUpdate(trivialInput(ConvergenceLoopInputs.STATUS_UPDATE)): """
}, State.STOPPING: { Input.REQUEST_START: Transition([], State.STOP_CANCELLED), Input.REQUEST_STOP: Transition([], State.STOPPING), Input.INSTANCE_STOPPED: Transition([], State.IDLE), Input.STOP_FAILED: Transition([Output.STOP], State.STOPPING), }, State.STOP_CANCELLED: { Input.REQUEST_START: Transition([], State.STOP_CANCELLED), Input.REQUEST_STOP: Transition([], State.STOPPING), Input.INSTANCE_STOPPED: Transition([Output.START], State.STARTING), Input.STOP_FAILED: Transition([], State.ACTIVE), }, }) RequestStart = trivialInput(Input.REQUEST_START) @implementer(IRichInput) @attributes(['instance_id', 'image_metadata', 'instance_metadata']) class InstanceStarted(object): @staticmethod def symbol(): return Input.INSTANCE_STARTED StartFailed = trivialInput(Input.START_FAILED) RequestStop = trivialInput(Input.REQUEST_STOP) InstanceStopped = trivialInput(Input.INSTANCE_STOPPED) StopFailed = trivialInput(Input.STOP_FAILED)
def test_symbol(self): """ The C{symbol} method of the object returned by L{trivialInput} returns the symbol passed in. """ self.assertIs(Input.apple, trivialInput(Input.apple).symbol())
def test_interface(self): """ The type returned by L{trivialInput} implements L{IRichInput}. """ self.assertTrue(verifyClass(IRichInput, trivialInput(Input.apple)))
class Gravenstein(trivialInput(Input.apple)): # Conveniently, apples are approximately spherical. radius = 3
def test_interfaceOnInstance(self): """ The an instance of the object returned by L{trivialInput} provides L{IRichInput}. """ self.assertTrue(verifyObject(IRichInput, trivialInput(Input.apple)()))
class _ConnectedToControlService( trivialInput(ClusterStatusInputs.CONNECTED_TO_CONTROL_SERVICE)): """
class _StatusUpdate(trivialInput(ClusterStatusInputs.STATUS_UPDATE)): """