13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Unit tests for the bzrlib.help module."""
32
class TestHelp(tests.TestCase):
35
tests.TestCase.setUp(self)
36
commands.install_bzr_command_hooks()
32
39
class TestCommandHelp(tests.TestCase):
33
40
"""Tests for help on commands."""
35
42
def test_command_help_includes_see_also(self):
36
43
class cmd_WithSeeAlso(commands.Command):
37
"""A sample command."""
44
__doc__ = """A sample command."""
38
45
_see_also = ['foo', 'bar']
39
46
cmd = cmd_WithSeeAlso()
40
47
helptext = cmd.get_help_text()
41
48
self.assertEndsWith(
43
' -h, --help Show help message.\n'
50
' -v, --verbose Display more information.\n'
51
' -q, --quiet Only display errors and warnings.\n'
52
' -h, --help Show help message.\n'
45
54
'See also: bar, foo\n')
47
56
def test_get_help_text(self):
48
57
"""Commands have a get_help_text method which returns their help."""
49
58
class cmd_Demo(commands.Command):
50
"""A sample command."""
59
__doc__ = """A sample command."""
52
61
helptext = cmd.get_help_text()
53
62
self.assertStartsWith(helptext,
54
63
'Purpose: A sample command.\n'
56
self.assertEndsWith(helptext, 'Show help message.\n\n')
65
self.assertEndsWith(helptext,
66
' -h, --help Show help message.\n\n')
58
68
def test_command_with_additional_see_also(self):
59
69
class cmd_WithSeeAlso(commands.Command):
60
"""A sample command."""
70
__doc__ = """A sample command."""
61
71
_see_also = ['foo', 'bar']
62
72
cmd = cmd_WithSeeAlso()
63
73
helptext = cmd.get_help_text(['gam'])
64
74
self.assertEndsWith(
66
' -h, --help Show help message.\n'
76
' -v, --verbose Display more information.\n'
77
' -q, --quiet Only display errors and warnings.\n'
78
' -h, --help Show help message.\n'
68
80
'See also: bar, foo, gam\n')
70
82
def test_command_only_additional_see_also(self):
71
83
class cmd_WithSeeAlso(commands.Command):
72
"""A sample command."""
84
__doc__ = """A sample command."""
73
85
cmd = cmd_WithSeeAlso()
74
86
helptext = cmd.get_help_text(['gam'])
75
87
self.assertEndsWith(
77
' -h, --help Show help message.\n'
89
' -v, --verbose Display more information.\n'
90
' -q, --quiet Only display errors and warnings.\n'
91
' -h, --help Show help message.\n'
81
95
def test_get_help_topic(self):
82
96
"""The help topic for a Command is its name()."""
83
97
class cmd_foo_bar(commands.Command):
84
"""A sample command."""
98
__doc__ = """A sample command."""
85
99
cmd = cmd_foo_bar()
86
100
self.assertEqual(cmd.name(), cmd.get_help_topic())
88
102
def test_formatted_help_text(self):
89
103
"""Help text should be plain text by default."""
90
104
class cmd_Demo(commands.Command):
105
__doc__ = """A sample command.
116
A code block follows.
103
123
helptext = cmd.get_help_text()
168
' A code block follows.\n'
172
' bzr Demo something\n'
175
def test_concise_help_text(self):
176
"""Concise help text excludes the descriptive sections."""
177
class cmd_Demo(commands.Command):
178
__doc__ = """A sample command.
188
helptext = cmd.get_help_text()
189
self.assertEqualDiff(
191
'Purpose: A sample command.\n'
195
' --usage Show usage message and options.\n'
196
' -v, --verbose Display more information.\n'
197
' -q, --quiet Only display errors and warnings.\n'
198
' -h, --help Show help message.\n'
208
helptext = cmd.get_help_text(verbose=False)
209
self.assertEquals(helptext,
210
'Purpose: A sample command.\n'
214
' --usage Show usage message and options.\n'
215
' -v, --verbose Display more information.\n'
216
' -q, --quiet Only display errors and warnings.\n'
217
' -h, --help Show help message.\n'
219
'See bzr help Demo for more details and examples.\n'
222
def test_help_custom_section_ordering(self):
223
"""Custom descriptive sections should remain in the order given."""
224
class cmd_Demo(commands.Command):
225
__doc__ = """A sample command.
230
Interesting stuff about formats.
238
Clever things to keep in mind.
241
helptext = cmd.get_help_text()
242
self.assertEqualDiff(
244
'Purpose: A sample command.\n'
248
' --usage Show usage message and options.\n'
249
' -v, --verbose Display more information.\n'
250
' -q, --quiet Only display errors and warnings.\n'
251
' -h, --help Show help message.\n'
257
' Interesting stuff about formats.\n'
265
' Clever things to keep in mind.\n'
139
268
def test_help_text_custom_usage(self):
140
269
"""Help text may contain a custom usage section."""
141
270
class cmd_Demo(commands.Command):
271
__doc__ = """A sample command.
145
274
cmd Demo [opts] args
162
' -h, --help Show help message.\n'
291
' --usage Show usage message and options.\n'
292
' -v, --verbose Display more information.\n'
293
' -q, --quiet Only display errors and warnings.\n'
294
' -h, --help Show help message.\n'
165
297
' Blah blah blah.\n\n')
168
class TestRegisteredTopic(tests.TestCase):
300
class TestRegisteredTopic(TestHelp):
169
301
"""Tests for the RegisteredTopic class."""
171
303
def test_contruct(self):
172
304
"""Construction takes the help topic name for the registered item."""
174
306
self.assertTrue('basic' in help_topics.topic_registry)
175
307
topic = help_topics.RegisteredTopic('basic')
176
308
self.assertEqual('basic', topic.topic)
189
321
'See also: bar, foo\n')
323
def test_get_help_text_loaded_from_file(self):
324
# Pick a known topic stored in an external file
325
topic = help_topics.RegisteredTopic('authentication')
326
self.assertStartsWith(topic.get_help_text(),
327
'Authentication Settings\n'
328
'=======================\n'
191
331
def test_get_help_topic(self):
192
332
"""The help topic for a RegisteredTopic is its topic from construction."""
193
333
topic = help_topics.RegisteredTopic('foobar')