Example #1
0
    def test_delegates_to_autocompleters(self):
        mock_complete = mock.Mock(spec=completer.BaseCompleter)
        expected = [CompletionResult('ec2', -1), CompletionResult('ecs', -1)]
        mock_complete.complete.return_value = expected
        auto_complete = completer.AutoCompleter(self.parser,
                                                completers=[mock_complete])

        results = auto_complete.autocomplete('aws e')
        self.assertEqual(results, expected)
        self.parser.parse.assert_called_with('aws e', None)
        mock_complete.complete.assert_called_with(self.parsed_result)
Example #2
0
    def test_returns_empty_list_if_no_completers_have_results(self):
        first = mock.Mock(spec=completer.BaseCompleter)
        second = mock.Mock(spec=completer.BaseCompleter)

        first.complete.return_value = None
        second.complete.return_value = None

        auto_complete = completer.AutoCompleter(self.parser,
                                                completers=[first, second])
        self.assertEqual(auto_complete.autocomplete('aws e'), [])

        first.complete.assert_called_with(self.parsed_result)
        second.complete.assert_called_with(self.parsed_result)
Example #3
0
def create_autocompleter(index_filename=None, custom_completers=None):
    if custom_completers is None:
        custom_completers = custom.get_custom_completers()
    if index_filename is None:
        index_filename = _get_index_filename()
    index = model.ModelIndex(index_filename)
    cli_parser = parser.CLIParser(index)
    completers = [
        basic.ModelIndexCompleter(index),
        serverside.create_server_side_completer(index_filename)
    ] + custom_completers
    cli_completer = completer.AutoCompleter(cli_parser, completers)
    return cli_completer
Example #4
0
    def test_first_result_wins(self):
        first = mock.Mock(spec=completer.BaseCompleter)
        second = mock.Mock(spec=completer.BaseCompleter)

        first.complete.return_value = [CompletionResult('ec2', -1)]
        second.complete.return_value = [CompletionResult('ecs', -1)]

        auto_complete = completer.AutoCompleter(self.parser,
                                                completers=[first, second])
        self.assertEqual(auto_complete.autocomplete('aws e'),
                         [CompletionResult('ec2', -1)])

        first.complete.assert_called_with(self.parsed_result)
        self.assertFalse(second.complete.called)
Example #5
0
    def test_stops_processing_when_list_returned(self):
        first = mock.Mock(spec=completer.BaseCompleter)
        second = mock.Mock(spec=completer.BaseCompleter)

        first.complete.return_value = None
        expected = [CompletionResult('ec2', -1), CompletionResult('ecs', -1)]
        second.complete.return_value = expected

        auto_complete = completer.AutoCompleter(self.parser,
                                                completers=[first, second])
        self.assertEqual(auto_complete.autocomplete('aws e'), expected)

        first.complete.assert_called_with(self.parsed_result)
        second.complete.assert_called_with(self.parsed_result)