Пример #1
0
 def get_next_state(self):
     if self.__cmd == Command.EXIT:
         return state.Init()
     elif self.__cmd == Command.ADD_EQUIPMENT:
         return state.AppendNewEquipment()
     else:
         return state.Admin()
Пример #2
0
    def __init__(self):
        self.__logger = getLogger(__name__)
        self.__logger.info("StateController starts.")

        self.__current = state.Init()
        self.__current.entry()
        self.__start_time = time.time()
        self.__pressed_key = input.PressedKey()
        cmn_res.prev_state = self.__current
Пример #3
0
    def test_exit_by_key(self):
        self.state.entry()

        # Test the conditions of exit from this state.
        with patch("dev.input.PressedKey.exists") as mock_pressedKey_exists:
            # If pressed key does not exists, state should not exit.
            mock_pressedKey_exists.return_value = False
            self.state.do()
            self.assertEqual(self.state.should_exit(), False)

            # If pressed key exists, state should exit.
            mock_pressedKey_exists.return_value = True
            self.state.do()
            self.assertEqual(self.state.should_exit(), True)

        # Test the state of the next transition destination.
        # Link with CommonResource.prev_state
        state.CommonResource.prev_state = state.Init()
        self.assertIsInstance(self.state.get_next_state(), state.Init)

        state.CommonResource.prev_state = state.Restart()
        self.assertIsInstance(self.state.get_next_state(), state.Restart)
Пример #4
0
    def test_exit_by_timeout(self):
        timeout = 3

        # Test the conditions of exit from this state.
        with patch("time.time") as mock_time:
            # Initialize before entry
            mock_time.return_value = 0
            self.state.entry()

            # Just the same time when enter this state.
            mock_time.return_value = 0
            self.state.do()
            self.assertEqual(self.state.should_exit(), False)

            # Before 'timeout' seconds have passed.
            mock_time.return_value = timeout - 0.1
            self.state.do()
            self.assertEqual(self.state.should_exit(), False)

            # Just 'timeout' seconds.
            mock_time.return_value = timeout
            self.state.do()
            self.assertEqual(self.state.should_exit(), False)

            # Elapsed 'timeout' seconds.
            mock_time.return_value = timeout + 0.1
            self.state.do()
            self.assertEqual(self.state.should_exit(), True)

        # Test the state of the next transition destination.
        # Link with CommonResource.prev_state
        state.CommonResource.prev_state = state.Init()
        self.assertIsInstance(self.state.get_next_state(), state.Init)

        state.CommonResource.prev_state = state.Restart()
        self.assertIsInstance(self.state.get_next_state(), state.Restart)
Пример #5
0
 def get_next_state(self):
     return state.Init()
Пример #6
0
 def initialize():
     CommonResource.user = AccountRecord()
     CommonResource.equipment = EquipmentRecord()
     CommonResource.prev_state = state.Init()
Пример #7
0
 def setUp(self):
     self.state = state.Init()
Пример #8
0
 def get_next_state(self):
     if self.__pressed_key.is_escape():
         return state.Exit()
     else:
         return state.Init()