Exemple #1
0
    def test_search_calls_get_topic(self):
        """Searching should call get_topics in all indexes in order."""
        calls = []

        class RecordingIndex(object):
            def __init__(self, name):
                self.prefix = name

            def get_topics(self, topic):
                calls.append(('get_topics', self.prefix, topic))
                return ['something']

        index = help.HelpIndices()
        index.search_path = [RecordingIndex('1'), RecordingIndex('2')]
        # try with None
        index.search(None)
        self.assertEqual([
            ('get_topics', '1', None),
            ('get_topics', '2', None),
        ], calls)
        # and with a string
        del calls[:]
        index.search('bar')
        self.assertEqual([
            ('get_topics', '1', 'bar'),
            ('get_topics', '2', 'bar'),
        ], calls)
Exemple #2
0
 def test_search_checks_for_duplicate_prefixes(self):
     """Its an error when there are multiple indices with the same prefix."""
     indices = help.HelpIndices()
     indices.search_path = [
         help_topics.HelpTopicIndex(),
         help_topics.HelpTopicIndex()
     ]
     self.assertRaises(errors.DuplicateHelpPrefix, indices.search, None)
Exemple #3
0
 def test_default_search_path(self):
     """The default search path should include internal indexs."""
     indices = help.HelpIndices()
     self.assertEqual(3, len(indices.search_path))
     # help topics should be searched in first.
     self.assertIsInstance(indices.search_path[0],
                           help_topics.HelpTopicIndex)
     # with commands being search second.
     self.assertIsInstance(indices.search_path[1],
                           commands.HelpCommandIndex)
     # and plugins are a third index.
     self.assertIsInstance(indices.search_path[2], plugin.PluginsHelpIndex)
Exemple #4
0
    def test_search_returns_index_and_results(self):
        """Searching should return help topics with their index"""
        class CannedIndex(object):
            def __init__(self, prefix, search_result):
                self.prefix = prefix
                self.result = search_result

            def get_topics(self, topic):
                return self.result

        index = help.HelpIndices()
        index_one = CannedIndex('1', ['a'])
        index_two = CannedIndex('2', ['b', 'c'])
        index.search_path = [index_one, index_two]
        self.assertEqual([(index_one, 'a'), (index_two, 'b'),
                          (index_two, 'c')], index.search(None))
Exemple #5
0
 def test_search_for_unknown_topic_raises(self):
     """Searching for an unknown topic should raise NoHelpTopic."""
     indices = help.HelpIndices()
     indices.search_path = []
     error = self.assertRaises(errors.NoHelpTopic, indices.search, 'foo')
     self.assertEqual('foo', error.topic)