def test_add_state(self):

        state = MagicMock()
        state.name = 'test_state'

        sm = StateMachine('test machine')
        sm.add_state(state)

        self.assertEqual(state, sm.states['test_state'])

        with self.assertRaises(StateMachineException):
            sm.add_state(state)
Example #2
0
class TestStateMachine(unittest.TestCase):
    def setUp(self):
        self.factory_controller = DummyFactoryController()
        self.sm = StateMachine()
        self.s_ini = StateInitializing(self.factory_controller)
        #self.s_fil_o1 = StateFillingO1()
        #self.s_warming_watter = StateWarmingWater()


    def test_no_states(self):
        with self.assertRaises(InitializationError):
            self.sm.run()

    def test_no_end_state(self):
        self.sm.add_state("name", "handler", end_state=False)
        self.sm.set_start("name")
        with self.assertRaises(InitializationError):
            self.sm.run()

    def test_state_initializing(self):
        self.sm.add_state(STATES.INITIALIZING, self.s_ini, end_state=False)
        self.sm.add_state(STATES.FILLING_01, DummyEndState(), end_state=True)
        self.sm.set_start(STATES.INITIALIZING)
        self.sm.run()