Rev 2451: Ensure each HelpIndex has a unique prefix. in file:///home/robertc/source/baz/help-contexts/
Robert Collins
robertc at robertcollins.net
Fri Apr 20 04:32:23 BST 2007
At file:///home/robertc/source/baz/help-contexts/
------------------------------------------------------------
revno: 2451
revision-id: robertc at robertcollins.net-20070420033220-bwu4sb8t1a6vfamw
parent: robertc at robertcollins.net-20070420031949-sxckxqm8tjtk9tzn
committer: Robert Collins <robertc at robertcollins.net>
branch nick: help-contexts
timestamp: Fri 2007-04-20 13:32:20 +1000
message:
Ensure each HelpIndex has a unique prefix.
modified:
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/help.py help.py-20050505025907-4dd7a6d63912f894
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
bzrlib/tests/test_help.py test_help.py-20070419045354-6q6rq15j9e2n5fna-1
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2007-04-20 00:14:15 +0000
+++ b/bzrlib/errors.py 2007-04-20 03:32:20 +0000
@@ -1540,6 +1540,14 @@
_fmt = "Key %(key)s is already present in map"
+class DuplicateHelpPrefix(BzrError):
+
+ _fmt = "The prefix %(prefix)s is in the help search path twice."
+
+ def __init__(self, prefix):
+ self.prefix = prefix
+
+
class MalformedTransform(BzrError):
_fmt = "Tree transform is malformed %(conflicts)r"
=== modified file 'bzrlib/help.py'
--- a/bzrlib/help.py 2007-04-20 02:56:44 +0000
+++ b/bzrlib/help.py 2007-04-20 03:32:20 +0000
@@ -111,6 +111,15 @@
_mod_commands.HelpCommandIndex(),
]
+ def _check_prefix_uniqueness(self):
+ """Ensure that the index collection is able to differentiate safely."""
+ prefixes = {}
+ for index in self.search_path:
+ prefixes.setdefault(index.prefix, []).append(index)
+ for prefix, indices in prefixes.items():
+ if len(indices) > 1:
+ raise errors.DuplicateHelpPrefix(prefix)
+
def search(self, topic):
"""Search for topic across the help search path.
@@ -118,6 +127,7 @@
:raises: NoHelpTopic if none of the indexs in search_path have topic.
:return: A list of HelpTopics which matched 'topic'.
"""
+ self._check_prefix_uniqueness()
result = []
for index in self.search_path:
result.extend(index.get_topics(topic))
=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py 2007-04-20 00:14:15 +0000
+++ b/bzrlib/tests/test_errors.py 2007-04-20 03:32:20 +0000
@@ -40,6 +40,11 @@
self.assertEqualDiff('File id {a_file_id} already exists in inventory'
' as foo', str(error))
+ def test_duplicate_help_prefix(self):
+ error = errors.DuplicateHelpPrefix('foo')
+ self.assertEqualDiff('The prefix foo is in the help search path twice.',
+ str(error))
+
def test_inventory_modified(self):
error = errors.InventoryModified("a tree to be repred")
self.assertEqualDiff("The current inventory for the tree 'a tree to "
=== modified file 'bzrlib/tests/test_help.py'
--- a/bzrlib/tests/test_help.py 2007-04-20 03:19:49 +0000
+++ b/bzrlib/tests/test_help.py 2007-04-20 03:32:20 +0000
@@ -165,9 +165,9 @@
calls = []
class RecordingIndex(object):
def __init__(self, name):
- self.name = name
+ self.prefix = name
def get_topics(self, topic):
- calls.append(('get_topics', self.name, topic))
+ calls.append(('get_topics', self.prefix, topic))
return ['something']
index = help.HelpIndices()
index.search_path = [RecordingIndex('1'), RecordingIndex('2')]
@@ -190,10 +190,18 @@
def test_search_returns_index_results(self):
"""Searching should return all the help topics found."""
class CannedIndex(object):
- def __init__(self, search_result):
+ 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.search_path = [CannedIndex(['a']), CannedIndex(['b', 'c'])]
+ index.search_path = [CannedIndex('1', ['a']), CannedIndex('2', ['b', 'c'])]
self.assertEqual(['a', 'b', 'c'], index.search(None))
+
+ 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)
More information about the bazaar-commits
mailing list