Rev 2435: Create a HelpContexts object to do help lookups. in file:///home/robertc/source/baz/help-contexts/

Robert Collins robertc at robertcollins.net
Fri Apr 20 01:06:48 BST 2007


At file:///home/robertc/source/baz/help-contexts/

------------------------------------------------------------
revno: 2435
revision-id: robertc at robertcollins.net-20070420000646-nwrkgumqaykrg1lz
parent: robertc at robertcollins.net-20070419235717-rdjuxno46v5ugs7y
committer: Robert Collins <robertc at robertcollins.net>
branch nick: help-contexts
timestamp: Fri 2007-04-20 10:06:46 +1000
message:
  Create a HelpContexts object to do help lookups.
modified:
  bzrlib/help.py                 help.py-20050505025907-4dd7a6d63912f894
  bzrlib/tests/test_help.py      test_help.py-20070419045354-6q6rq15j9e2n5fna-1
=== modified file 'bzrlib/help.py'
--- a/bzrlib/help.py	2007-04-19 23:54:43 +0000
+++ b/bzrlib/help.py	2007-04-20 00:06:46 +0000
@@ -25,6 +25,7 @@
 import textwrap
 
 from bzrlib import (
+    commands as _mod_commands,
     help_topics,
     osutils,
     )
@@ -80,10 +81,8 @@
 
 
 def help_on_command(cmdname, outfile=None):
-    from bzrlib.commands import get_cmd_object
-
     cmdname = str(cmdname)
-    cmd_object = get_cmd_object(cmdname)
+    cmd_object = _mod_commands.get_cmd_object(cmdname)
 
     return help_on_command_object(cmd_object, cmdname, outfile)
 
@@ -141,17 +140,14 @@
 
 def _help_commands_to_text(topic):
     """Generate the help text for the list of commands"""
-    from bzrlib.commands import (builtin_command_names,
-                                 plugin_command_names,
-                                 get_cmd_object)
     out = []
     if topic == 'hidden-commands':
         hidden = True
     else:
         hidden = False
-    names = set(builtin_command_names()) # to eliminate duplicates
-    names.update(plugin_command_names())
-    commands = ((n, get_cmd_object(n)) for n in names)
+    names = set(_mod_commands.builtin_command_names()) # to eliminate duplicates
+    names.update(_mod_commands.plugin_command_names())
+    commands = ((n, _mod_commands.get_cmd_object(n)) for n in names)
     shown_commands = [(n, o) for n, o in commands if o.hidden == hidden]
     max_name = max(len(n) for n, o in shown_commands)
     indent = ' ' * (max_name + 1)
@@ -183,3 +179,13 @@
 help_topics.topic_registry.register("hidden-commands",
                                     _help_commands_to_text,
                                     "All hidden commands")
+
+
+class HelpContexts(object):
+    """An object to manage help in multiple contexts."""
+
+    def __init__(self):
+        self.search_path = [
+            help_topics.HelpTopicContext(),
+            _mod_commands.HelpCommandContext(),
+            ]

=== modified file 'bzrlib/tests/test_help.py'
--- a/bzrlib/tests/test_help.py	2007-04-19 23:57:17 +0000
+++ b/bzrlib/tests/test_help.py	2007-04-20 00:06:46 +0000
@@ -44,14 +44,29 @@
 
 
 class TestTopicContext(tests.TestCase):
-    """Tests for the HelpTopicContext object."""
+    """Tests for the HelpTopicContext class."""
 
-    def test_construct(self):
+    def test_default_constructable(self):
         context = help_topics.HelpTopicContext()
 
 
 class TestCommandContext(tests.TestCase):
-    """Tests for the HelpCommandContext object."""
+    """Tests for the HelpCommandContext class."""
 
-    def test_construct(self):
+    def test_default_constructable(self):
         context = commands.HelpCommandContext()
+
+
+class TestHelpContexts(tests.TestCase):
+    """Tests for the HelpContexts class."""
+
+    def test_default_search_path(self):
+        """The default search path should include internal contexts."""
+        contexts = help.HelpContexts()
+        self.assertEqual(2, len(contexts.search_path))
+        # help topics should be searched in first.
+        self.assertIsInstance(contexts.search_path[0],
+            help_topics.HelpTopicContext)
+        # with commands being search second.
+        self.assertIsInstance(contexts.search_path[1],
+            commands.HelpCommandContext)



More information about the bazaar-commits mailing list