Пример #1
0
 def test_addTransitionsDoesNotMutate(self):
     """
     L{TransitionTable.addTransitions} does not change the
     L{TransitionTable} it is called on.
     """
     table = TransitionTable({"foo": {"bar": Transition("baz", "quux")}})
     table.addTransitions("apple", {"banana": ("clementine", "date")})
     self.assertEqual({"foo": {
         "bar": Transition("baz", "quux")
     }}, table.table)
Пример #2
0
 def test_repr(self):
     """
     The other string representation of a L{Transition} includes the output
     and next state it represents.
     """
     self.assertEqual("<Transition output='a' nextState='b'>",
                      repr(Transition("a", "b")))
Пример #3
0
 def test_extraTransitionInput(self):
     """
     L{ExtraTransitionInput} is raised if there are any keys in any of the
     values of C{transitions} that are not defined by C{input}.
     """
     extra = object()
     exc = self.assertRaises(
         ExtraTransitionInput, constructFiniteStateMachine, Input, Output,
         State,
         TransitionTable({
             State.amber: {
                 Input.apple: Transition(Output.aardvark, State.amber),
                 extra: Transition(Output.aardvark, State.amber)
             }
         }), State.amber, [], {}, NULL_WORLD)
     self.assertEqual(({extra}, ), exc.args)
Пример #4
0
 def test_initial(self):
     """
     When constructed with a transition table as an argument,
     L{TransitionTable} contains exactly that table.
     """
     expected = {"foo": {"bar": Transition("baz", "quux")}}
     table = TransitionTable(expected)
     self.assertIs(expected, table.table)
Пример #5
0
 def test_addTransitions(self):
     """
     L{TransitionTable.addTransitions} accepts a state and a mapping from
     inputs to output, next state pairs and adds all of those transitions to
     the given state to a new L{TransitionTable} which it returns.
     """
     table = TransitionTable()
     more = table.addTransitions("apple", {
         "banana": ("clementine", "date"),
         "eggplant": ("fig", "grape")
     })
     self.assertEqual(
         {
             "apple": {
                 "banana": Transition("clementine", "date"),
                 "eggplant": Transition("fig", "grape")
             }
         }, more.table)
Пример #6
0
 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)
Пример #7
0
 def test_missingTransitionOutput(self):
     """
     L{MissingTransitionOutput} is raised if any of the values defined by
     C{output} does not appear as an output value defined by C{transitions}.
     """
     exc = self.assertRaises(
         MissingTransitionOutput, constructFiniteStateMachine, Input,
         Output, State,
         TransitionTable({State.amber: {
             Input.apple: Transition([], None)
         }}), State.amber, [], {}, NULL_WORLD)
     self.assertEqual(({Output.aardvark}, ), exc.args)
Пример #8
0
class Output(Names):
    START = NamedConstant()
    STOP = NamedConstant()


class State(Names):
    IDLE = NamedConstant()
    STARTING = NamedConstant()
    START_CANCELLED = NamedConstant()
    ACTIVE = NamedConstant()
    STOPPING = NamedConstant()
    STOP_CANCELLED = NamedConstant()

table = TransitionTable({
    State.IDLE: {
        Input.REQUEST_START: Transition([Output.START], State.STARTING),
        Input.REQUEST_STOP: Transition([], State.IDLE),
    },
    State.STARTING: {
        Input.REQUEST_START: Transition([], State.STARTING),
        Input.REQUEST_STOP: Transition([], State.START_CANCELLED),
        Input.INSTANCE_STARTED: Transition([], State.ACTIVE),
        Input.START_FAILED: Transition([Output.START], State.STARTING),
    },
    State.START_CANCELLED: {
        Input.REQUEST_START: Transition([], State.STARTING),
        Input.REQUEST_STOP: Transition([], State.START_CANCELLED),
        Input.INSTANCE_STARTED: Transition([Output.STOP], State.STOPPING),
        Input.START_FAILED: Transition([], State.IDLE),
    },
    State.ACTIVE: {
Пример #9
0
 def test_equal(self):
     """
     Two L{Transition} instances are equal to each other if their attributes
     have the same values.
     """
     self.assertTrue(Transition("a", "b") == Transition("a", "b"))