~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Robert Collins
  • Date: 2007-04-20 03:32:20 UTC
  • mto: This revision was merged to the branch mainline in revision 2441.
  • Revision ID: robertc@robertcollins.net-20070420033220-bwu4sb8t1a6vfamw
Ensure each HelpIndex has a unique prefix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
        calls = []
166
166
        class RecordingIndex(object):
167
167
            def __init__(self, name):
168
 
                self.name = name
 
168
                self.prefix = name
169
169
            def get_topics(self, topic):
170
 
                calls.append(('get_topics', self.name, topic))
 
170
                calls.append(('get_topics', self.prefix, topic))
171
171
                return ['something']
172
172
        index = help.HelpIndices()
173
173
        index.search_path = [RecordingIndex('1'), RecordingIndex('2')]
190
190
    def test_search_returns_index_results(self):
191
191
        """Searching should return all the help topics found."""
192
192
        class CannedIndex(object):
193
 
            def __init__(self, search_result):
 
193
            def __init__(self, prefix, search_result):
 
194
                self.prefix = prefix
194
195
                self.result = search_result
195
196
            def get_topics(self, topic):
196
197
                return self.result
197
198
        index = help.HelpIndices()
198
 
        index.search_path = [CannedIndex(['a']), CannedIndex(['b', 'c'])]
 
199
        index.search_path = [CannedIndex('1', ['a']), CannedIndex('2', ['b', 'c'])]
199
200
        self.assertEqual(['a', 'b', 'c'], index.search(None))
 
201
 
 
202
    def test_search_checks_for_duplicate_prefixes(self):
 
203
        """Its an error when there are multiple indices with the same prefix."""
 
204
        indices = help.HelpIndices()
 
205
        indices.search_path = [help_topics.HelpTopicIndex(),
 
206
            help_topics.HelpTopicIndex()]
 
207
        self.assertRaises(errors.DuplicateHelpPrefix, indices.search, None)