Rev 5266: (lifeless) Stop raising at runtime when a command has no help, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri May 28 01:25:35 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5266 [merge]
revision-id: pqm at pqm.ubuntu.com-20100528002532-9bzj1fajyxckd1rg
parent: pqm at pqm.ubuntu.com-20100527211549-ebv2csu4te6xdvy7
parent: robertc at robertcollins.net-20100527211648-1mj8m4dh0ricku21
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-05-28 01:25:32 +0100
message:
(lifeless) Stop raising at runtime when a command has no help,
instead have a test in the test suite that checks all known command objects.
(Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
bzrlib/tests/test_commands.py test_command.py-20051019190109-3b17be0f52eaa7a8
=== modified file 'NEWS'
--- a/NEWS 2010-05-27 19:37:34 +0000
+++ b/NEWS 2010-05-27 21:16:48 +0000
@@ -20,6 +20,11 @@
Bug Fixes
*********
+* Final fix for 'no help for command' issue. We now show a clean message
+ when a command has no help, document how to set help more clearly, and
+ test that all commands available to the test suite have help.
+ (Robert Collins, #177500)
+
Improvements
************
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2010-05-11 11:05:49 +0000
+++ b/bzrlib/commands.py 2010-05-27 21:16:48 +0000
@@ -397,6 +397,12 @@
will not mangled.
:cvar hooks: An instance of CommandHooks.
+ :ivar __doc__: The help shown by 'bzr help command' for this command.
+ This is set by assigning explicitly to __doc__ so that -OO can
+ be used::
+
+ class Foo(Command):
+ __doc__ = "My help goes here"
"""
aliases = []
takes_args = []
@@ -407,8 +413,6 @@
def __init__(self):
"""Construct an instance of this command."""
- if self.__doc__ == Command.__doc__ or not self.__doc__:
- raise ValueError("No help message set for %r" % self)
# List of standard options directly supported
self.supported_std_options = []
self._setup_run()
@@ -482,10 +486,8 @@
message explaining how to obtain full help.
"""
doc = self.help()
- if doc is None:
- raise NotImplementedError(
- "self.help() returned None - no detailed help yet for %r" %
- self.name())
+ if not doc:
+ doc = "No help for this command."
# Extract the summary (purpose) and sections out from the text
purpose,sections,order = self._get_help_parts(doc)
=== modified file 'bzrlib/tests/test_commands.py'
--- a/bzrlib/tests/test_commands.py 2010-05-11 11:05:49 +0000
+++ b/bzrlib/tests/test_commands.py 2010-05-27 21:16:48 +0000
@@ -16,6 +16,7 @@
from cStringIO import StringIO
import errno
+import inspect
import sys
from bzrlib import (
@@ -33,6 +34,17 @@
class TestCommands(tests.TestCase):
+ def test_all_commands_have_help(self):
+ commands._register_builtin_commands()
+ commands_without_help = set()
+ base_doc = inspect.getdoc(commands.Command)
+ for cmd_name in commands.all_command_names():
+ cmd = commands.get_cmd_object(cmd_name)
+ cmd_help = cmd.help()
+ if not cmd_help or cmd_help == base_doc:
+ commands_without_help.append(cmd_name)
+ self.assertLength(0, commands_without_help)
+
def test_display_command(self):
"""EPIPE message is selectively suppressed"""
def pipe_thrower():
@@ -79,11 +91,6 @@
c = self.get_command([option.Option('foo', hidden=False)])
self.assertContainsRe(c.get_help_text(), '--foo')
- def test_no_help_init_failure(self):
- class cmd_foo(commands.Command):
- pass
- self.assertRaises(ValueError, cmd_foo)
-
class TestGetAlias(tests.TestCase):
More information about the bazaar-commits
mailing list