Merge lp:~lifeless/bzr/command-help-bug-177500 into lp:bzr

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 5266
Proposed branch: lp:~lifeless/bzr/command-help-bug-177500
Merge into: lp:bzr
Diff against target: 95 lines (+25/-11)
3 files modified
NEWS (+5/-0)
bzrlib/commands.py (+8/-6)
bzrlib/tests/test_commands.py (+12/-5)
To merge this branch: bzr merge lp:~lifeless/bzr/command-help-bug-177500
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+26248@code.launchpad.net

Commit message

Stop raising at runtime when a command has no help, instead have a test in the test suite that checks all known command objects.

Description of the change

Stop raising at runtime when a command has no help, instead have a test in
the test suite that checks all known command objects.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

Thanks very much.

review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-05-27 19:37:34 +0000
3+++ NEWS 2010-05-27 21:20:50 +0000
4@@ -20,6 +20,11 @@
5 Bug Fixes
6 *********
7
8+* Final fix for 'no help for command' issue. We now show a clean message
9+ when a command has no help, document how to set help more clearly, and
10+ test that all commands available to the test suite have help.
11+ (Robert Collins, #177500)
12+
13 Improvements
14 ************
15
16
17=== modified file 'bzrlib/commands.py'
18--- bzrlib/commands.py 2010-05-11 11:05:49 +0000
19+++ bzrlib/commands.py 2010-05-27 21:20:50 +0000
20@@ -397,6 +397,12 @@
21 will not mangled.
22
23 :cvar hooks: An instance of CommandHooks.
24+ :ivar __doc__: The help shown by 'bzr help command' for this command.
25+ This is set by assigning explicitly to __doc__ so that -OO can
26+ be used::
27+
28+ class Foo(Command):
29+ __doc__ = "My help goes here"
30 """
31 aliases = []
32 takes_args = []
33@@ -407,8 +413,6 @@
34
35 def __init__(self):
36 """Construct an instance of this command."""
37- if self.__doc__ == Command.__doc__ or not self.__doc__:
38- raise ValueError("No help message set for %r" % self)
39 # List of standard options directly supported
40 self.supported_std_options = []
41 self._setup_run()
42@@ -482,10 +486,8 @@
43 message explaining how to obtain full help.
44 """
45 doc = self.help()
46- if doc is None:
47- raise NotImplementedError(
48- "self.help() returned None - no detailed help yet for %r" %
49- self.name())
50+ if not doc:
51+ doc = "No help for this command."
52
53 # Extract the summary (purpose) and sections out from the text
54 purpose,sections,order = self._get_help_parts(doc)
55
56=== modified file 'bzrlib/tests/test_commands.py'
57--- bzrlib/tests/test_commands.py 2010-05-11 11:05:49 +0000
58+++ bzrlib/tests/test_commands.py 2010-05-27 21:20:50 +0000
59@@ -16,6 +16,7 @@
60
61 from cStringIO import StringIO
62 import errno
63+import inspect
64 import sys
65
66 from bzrlib import (
67@@ -33,6 +34,17 @@
68
69 class TestCommands(tests.TestCase):
70
71+ def test_all_commands_have_help(self):
72+ commands._register_builtin_commands()
73+ commands_without_help = set()
74+ base_doc = inspect.getdoc(commands.Command)
75+ for cmd_name in commands.all_command_names():
76+ cmd = commands.get_cmd_object(cmd_name)
77+ cmd_help = cmd.help()
78+ if not cmd_help or cmd_help == base_doc:
79+ commands_without_help.append(cmd_name)
80+ self.assertLength(0, commands_without_help)
81+
82 def test_display_command(self):
83 """EPIPE message is selectively suppressed"""
84 def pipe_thrower():
85@@ -79,11 +91,6 @@
86 c = self.get_command([option.Option('foo', hidden=False)])
87 self.assertContainsRe(c.get_help_text(), '--foo')
88
89- def test_no_help_init_failure(self):
90- class cmd_foo(commands.Command):
91- pass
92- self.assertRaises(ValueError, cmd_foo)
93-
94
95 class TestGetAlias(tests.TestCase):
96