Rev 2440: HelpTopicContext now returns RegisteredTopic objects for get_topics calls. in file:///home/robertc/source/baz/help-contexts/
Robert Collins
robertc at robertcollins.net
Fri Apr 20 01:45:20 BST 2007
At file:///home/robertc/source/baz/help-contexts/
------------------------------------------------------------
revno: 2440
revision-id: robertc at robertcollins.net-20070420004517-w6lqtu5vz2lli7av
parent: robertc at robertcollins.net-20070420003403-0055vwwp20sdtpti
committer: Robert Collins <robertc at robertcollins.net>
branch nick: help-contexts
timestamp: Fri 2007-04-20 10:45:17 +1000
message:
HelpTopicContext now returns RegisteredTopic objects for get_topics calls.
modified:
bzrlib/help_topics.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
bzrlib/tests/test_help.py test_help.py-20070419045354-6q6rq15j9e2n5fna-1
=== modified file 'bzrlib/help_topics.py'
--- a/bzrlib/help_topics.py 2007-04-19 23:54:43 +0000
+++ b/bzrlib/help_topics.py 2007-04-20 00:45:17 +0000
@@ -246,3 +246,32 @@
class HelpTopicContext(object):
"""A context for bzr help that returns topics."""
+
+ def get_topics(self, topic):
+ """Search for topic in the HelpTopicRegistry.
+
+ :param topic: A topic to search for. None is treated as 'basic'.
+ :return: A list which is either empty or contains a single
+ RegisteredTopic entry.
+ """
+ if topic is None:
+ topic = 'basic'
+ if topic in topic_registry:
+ return [RegisteredTopic(topic)]
+ else:
+ return []
+
+
+class RegisteredTopic(object):
+ """A help topic which has been registered in the HelpTopicRegistry.
+
+ These topics consist of nothing more than the name of the topic - all
+ data is retrieved on demand from the registry.
+ """
+
+ def __init__(self, topic):
+ """Constructor.
+
+ :param topic: The name of the topic that this represents.
+ """
+ self.topic = topic
=== modified file 'bzrlib/tests/test_help.py'
--- a/bzrlib/tests/test_help.py 2007-04-20 00:34:03 +0000
+++ b/bzrlib/tests/test_help.py 2007-04-20 00:45:17 +0000
@@ -44,12 +44,44 @@
'See also: bar, foo\n')
+class TestRegisteredTopic(tests.TestCase):
+ """Tests for the RegisteredTopic class."""
+
+ def test_contruct(self):
+ """Construction takes the help topic name for the registered item."""
+ # validate our test
+ self.assertTrue('basic' in help_topics.topic_registry)
+ topic = help_topics.RegisteredTopic('basic')
+ self.assertEqual('basic', topic.topic)
+
+
class TestTopicContext(tests.TestCase):
"""Tests for the HelpTopicContext class."""
def test_default_constructable(self):
context = help_topics.HelpTopicContext()
+ def test_get_topics_None(self):
+ """Searching for None returns the basic help topic."""
+ context = help_topics.HelpTopicContext()
+ topics = context.get_topics(None)
+ self.assertEqual(1, len(topics))
+ self.assertIsInstance(topics[0], help_topics.RegisteredTopic)
+ self.assertEqual('basic', topics[0].topic)
+
+ def test_get_topics_topics(self):
+ """Searching for a string returns the matching string."""
+ context = help_topics.HelpTopicContext()
+ topics = context.get_topics('topics')
+ self.assertEqual(1, len(topics))
+ self.assertIsInstance(topics[0], help_topics.RegisteredTopic)
+ self.assertEqual('topics', topics[0].topic)
+
+ def test_get_topics_no_topic(self):
+ """Searching for something not registered returns []."""
+ context = help_topics.HelpTopicContext()
+ self.assertEqual([], context.get_topics('nothing by this name'))
+
class TestCommandContext(tests.TestCase):
"""Tests for the HelpCommandContext class."""
More information about the bazaar-commits
mailing list