def get_command_and_args(self, words): words_tuple = tuple(words) for command in self._commands: nb_words = command.nb_words if command.words == words_tuple[:nb_words]: return command, words[nb_words:] raise NoMatchingCommandError(words)
def test_parse_one_letter_line_with_whitespaces(self): raw_command_line = ' h \n' self.command_registry.get_command_and_args.side_effect = NoMatchingCommandError() command_line = self.parser.parse(raw_command_line) self.command_registry.get_command_and_args.assert_called_once_with(['h']) assert_that(command_line.words, equal_to(['h'])) assert_that(command_line.command, none()) assert_that(command_line.command_args, none())
def test_parse_empty_line(self): raw_command_line = '' self.command_registry.get_command_and_args.side_effect = NoMatchingCommandError() command_line = self.parser.parse(raw_command_line) self.command_registry.get_command_and_args.assert_called_once_with([]) assert_that(command_line.words, equal_to([])) assert_that(command_line.command, none()) assert_that(command_line.command_args, none())
def get_command(self, words): words_tuple = tuple(words) command = self._get_command(words_tuple) if command is None: raise NoMatchingCommandError(words) return command