Esempio n. 1
0
    def test_initial_substate_as_nameless_object(self):
        # To get a nameless state, we must create in isolation, because if in
        # a statechart, name for the state would be set.
        state_U = State()

        # Make a new state, isolated (not in a statechart), and set initial
        # state as an object, not a string key.
        state_W = State(initial_substate_key=state_U)
        self.assertEqual(state_W.initial_substate_key, None)
        self.assertEqual(state_W.initial_substate_object, state_U)
    def test_initial_state_without_default_state(self):
        msg = ("Initial substate is invalid. History state requires the name "
                "of a default state to be set.")

        state_P = State(name='P')
        state_P.InitialSubstate = HistoryState

        with self.assertRaises(Exception) as cm:
            state_P.init_state()

        self.assertEqual(str(cm.exception), msg)
    def test_initial_state_without_default_state(self):
        msg = ("Initial substate is invalid. History state requires the name "
               "of a default state to be set.")

        state_P = State(name='P')
        state_P.InitialSubstate = HistoryState

        with self.assertRaises(Exception) as cm:
            state_P.init_state()

        self.assertEqual(str(cm.exception), msg)
    def test_init_for_unnamed_state(self):
        state_O = State()
        state_P = State()

        state_P.parent_state = state_O

        with self.assertRaises(Exception) as cm:
            state_P.init_state()

        the_exception = cm.exception
        self.assertEqual(str(the_exception),
                         'Cannot init_state() an unnamed state.')
Esempio n. 5
0
    def test_initial_substate_as_object(self):
        # state_X is in statechart_2, and is initial substate
        self.assertTrue(state_X.is_current_state())

        # Make a new state, isolated (not in a statechart), and set initial
        # state as an object, not a string key. Test if set as string key.
        state_Z = State(initial_substate_key=state_Y)
        self.assertEqual(state_Z.initial_substate_key, 'Y')
Esempio n. 6
0
    def test_trying_to_get_relative_path_to_nonparent(self):
        nobody = State(name='nobody')

        # Note: The test will fail after the parentage is searched all the
        #       way to the root, and at that point the path will be B.X.

        with self.assertRaises(Exception) as cm:
            state_X.path_relative_to(nobody)

        msg = ("Cannot generate relative path from {0} since it is not a "
               "parent state of {1}").format('nobody', 'B.X')
        self.assertEqual(str(cm.exception), msg)
    def test_create(self):
        state_O = State(name='O')
        state_P = State(name='P')

        self.assertEqual(len(state_O._registered_substates), 0)

        state_P.parent_state = state_O
        state_P.init_state()

        self.assertEqual(len(state_O._registered_substates), 1)

        # Nothing should happen if init_state() called again.
        state_P.init_state()
        self.assertEqual(len(state_O._registered_substates), 1)
    def test_init_for_unnamed_state(self):
        state_O = State()
        state_P = State()

        state_P.parent_state = state_O

        with self.assertRaises(Exception) as cm:
            state_P.init_state()

        the_exception = cm.exception
        self.assertEqual(str(the_exception),
                         'Cannot init_state() an unnamed state.')
    def test_create(self):
        state_O = State(name='O')
        state_P = State(name='P')

        self.assertEqual(len(state_O._registered_substates), 0)

        state_P.parent_state = state_O
        state_P.init_state()

        self.assertEqual(len(state_O._registered_substates), 1)

        # Nothing should happen if init_state() called again.
        state_P.init_state()
        self.assertEqual(len(state_O._registered_substates), 1)