32
from bzrlib.tests.test_i18n import ZzzTranslations
36
32
class TestCommandHelp(tests.TestCase):
37
33
"""Tests for help on commands."""
39
def assertCmdHelp(self, expected, cmd):
40
self.assertEqualDiff(textwrap.dedent(expected), cmd.get_help_text())
42
35
def test_command_help_includes_see_also(self):
43
36
class cmd_WithSeeAlso(commands.Command):
44
__doc__ = """A sample command."""
37
"""A sample command."""
45
38
_see_also = ['foo', 'bar']
46
self.assertCmdHelp('''\
47
Purpose: A sample command.
48
Usage: bzr WithSeeAlso
51
--usage Show usage message and options.
52
-v, --verbose Display more information.
53
-q, --quiet Only display errors and warnings.
54
-h, --help Show help message.
39
cmd = cmd_WithSeeAlso()
40
helptext = cmd.get_help_text()
43
' -h, --help Show help message.\n'
45
'See also: bar, foo\n')
60
47
def test_get_help_text(self):
61
48
"""Commands have a get_help_text method which returns their help."""
62
49
class cmd_Demo(commands.Command):
63
__doc__ = """A sample command."""
64
self.assertCmdHelp('''\
65
Purpose: A sample command.
69
--usage Show usage message and options.
70
-v, --verbose Display more information.
71
-q, --quiet Only display errors and warnings.
72
-h, --help Show help message.
50
"""A sample command."""
77
52
helptext = cmd.get_help_text()
78
53
self.assertStartsWith(helptext,
79
54
'Purpose: A sample command.\n'
81
self.assertEndsWith(helptext,
82
' -h, --help Show help message.\n\n')
56
self.assertEndsWith(helptext, 'Show help message.\n\n')
84
58
def test_command_with_additional_see_also(self):
85
59
class cmd_WithSeeAlso(commands.Command):
86
__doc__ = """A sample command."""
60
"""A sample command."""
87
61
_see_also = ['foo', 'bar']
88
62
cmd = cmd_WithSeeAlso()
89
63
helptext = cmd.get_help_text(['gam'])
90
64
self.assertEndsWith(
92
' -v, --verbose Display more information.\n'
93
' -q, --quiet Only display errors and warnings.\n'
94
' -h, --help Show help message.\n'
66
' -h, --help Show help message.\n'
96
68
'See also: bar, foo, gam\n')
98
70
def test_command_only_additional_see_also(self):
99
71
class cmd_WithSeeAlso(commands.Command):
100
__doc__ = """A sample command."""
72
"""A sample command."""
101
73
cmd = cmd_WithSeeAlso()
102
74
helptext = cmd.get_help_text(['gam'])
103
75
self.assertEndsWith(
105
' -v, --verbose Display more information.\n'
106
' -q, --quiet Only display errors and warnings.\n'
107
' -h, --help Show help message.\n'
77
' -h, --help Show help message.\n'
109
79
'See also: gam\n')
111
81
def test_get_help_topic(self):
112
82
"""The help topic for a Command is its name()."""
113
83
class cmd_foo_bar(commands.Command):
114
__doc__ = """A sample command."""
84
"""A sample command."""
115
85
cmd = cmd_foo_bar()
116
86
self.assertEqual(cmd.name(), cmd.get_help_topic())
118
88
def test_formatted_help_text(self):
119
89
"""Help text should be plain text by default."""
120
90
class cmd_Demo(commands.Command):
121
__doc__ = """A sample command.
132
A code block follows.
139
103
helptext = cmd.get_help_text()
184
' A code block follows.\n'
188
' bzr Demo something\n'
191
def test_concise_help_text(self):
192
"""Concise help text excludes the descriptive sections."""
193
class cmd_Demo(commands.Command):
194
__doc__ = """A sample command.
204
helptext = cmd.get_help_text()
205
self.assertEqualDiff(
207
'Purpose: A sample command.\n'
211
' --usage Show usage message and options.\n'
212
' -v, --verbose Display more information.\n'
213
' -q, --quiet Only display errors and warnings.\n'
214
' -h, --help Show help message.\n'
224
helptext = cmd.get_help_text(verbose=False)
225
self.assertEquals(helptext,
226
'Purpose: A sample command.\n'
230
' --usage Show usage message and options.\n'
231
' -v, --verbose Display more information.\n'
232
' -q, --quiet Only display errors and warnings.\n'
233
' -h, --help Show help message.\n'
235
'See bzr help Demo for more details and examples.\n'
238
def test_help_custom_section_ordering(self):
239
"""Custom descriptive sections should remain in the order given."""
240
class cmd_Demo(commands.Command):
241
__doc__ = """A sample command.
246
Interesting stuff about formats.
254
Clever things to keep in mind.
257
helptext = cmd.get_help_text()
258
self.assertEqualDiff(
260
'Purpose: A sample command.\n'
264
' --usage Show usage message and options.\n'
265
' -v, --verbose Display more information.\n'
266
' -q, --quiet Only display errors and warnings.\n'
267
' -h, --help Show help message.\n'
273
' Interesting stuff about formats.\n'
281
' Clever things to keep in mind.\n'
284
139
def test_help_text_custom_usage(self):
285
140
"""Help text may contain a custom usage section."""
286
141
class cmd_Demo(commands.Command):
287
__doc__ = """A sample command.
290
145
cmd Demo [opts] args
307
' --usage Show usage message and options.\n'
308
' -v, --verbose Display more information.\n'
309
' -q, --quiet Only display errors and warnings.\n'
310
' -h, --help Show help message.\n'
162
' -h, --help Show help message.\n'
313
165
' Blah blah blah.\n\n')
316
class ZzzTranslationsForDoc(ZzzTranslations):
318
_section_pat = re.compile(':\w+:\\n\\s+')
319
_indent_pat = re.compile('\\s+')
322
m = self._section_pat.match(s)
324
m = self._indent_pat.match(s)
326
return u'%szz{{%s}}' % (m.group(0), s[m.end():])
327
return u'zz{{%s}}' % s
330
class TestCommandHelpI18n(tests.TestCase):
331
"""Tests for help on translated commands."""
334
super(TestCommandHelpI18n, self).setUp()
335
self.overrideAttr(i18n, '_translations', ZzzTranslationsForDoc())
337
def assertCmdHelp(self, expected, cmd):
338
self.assertEqualDiff(textwrap.dedent(expected), cmd.get_help_text())
340
def test_command_help_includes_see_also(self):
341
class cmd_WithSeeAlso(commands.Command):
342
__doc__ = """A sample command."""
343
_see_also = ['foo', 'bar']
344
self.assertCmdHelp('''\
345
zz{{:Purpose: zz{{A sample command.}}
346
}}zz{{:Usage: bzr WithSeeAlso
349
--usage Show usage message and options.
350
-v, --verbose Display more information.
351
-q, --quiet Only display errors and warnings.
352
-h, --help Show help message.
354
zz{{:See also: bar, foo}}
358
def test_get_help_text(self):
359
"""Commands have a get_help_text method which returns their help."""
360
class cmd_Demo(commands.Command):
361
__doc__ = """A sample command."""
362
self.assertCmdHelp('''\
363
zz{{:Purpose: zz{{A sample command.}}
364
}}zz{{:Usage: bzr Demo
367
--usage Show usage message and options.
368
-v, --verbose Display more information.
369
-q, --quiet Only display errors and warnings.
370
-h, --help Show help message.
375
def test_command_with_additional_see_also(self):
376
class cmd_WithSeeAlso(commands.Command):
377
__doc__ = """A sample command."""
378
_see_also = ['foo', 'bar']
379
cmd = cmd_WithSeeAlso()
380
helptext = cmd.get_help_text(['gam'])
383
' -v, --verbose Display more information.\n'
384
' -q, --quiet Only display errors and warnings.\n'
385
' -h, --help Show help message.\n'
387
'zz{{:See also: bar, foo, gam}}\n')
389
def test_command_only_additional_see_also(self):
390
class cmd_WithSeeAlso(commands.Command):
391
__doc__ = """A sample command."""
392
cmd = cmd_WithSeeAlso()
393
helptext = cmd.get_help_text(['gam'])
397
' --usage Show usage message and options.\n'
398
' -v, --verbose Display more information.\n'
399
' -q, --quiet Only display errors and warnings.\n'
400
' -h, --help Show help message.\n'
402
'zz{{:See also: gam}}\n')
405
def test_help_custom_section_ordering(self):
406
"""Custom descriptive sections should remain in the order given."""
407
# The help formatter expect the class name to start with 'cmd_'
408
class cmd_Demo(commands.Command):
409
__doc__ = """A sample command.
414
Interesting stuff about formats.
422
Clever things to keep in mind.
424
self.assertCmdHelp('''\
425
zz{{:Purpose: zz{{A sample command.}}
426
}}zz{{:Usage: bzr Demo
429
--usage Show usage message and options.
430
-v, --verbose Display more information.
431
-q, --quiet Only display errors and warnings.
432
-h, --help Show help message.
435
zz{{zz{{Blah blah blah.}}
438
zz{{Interesting stuff about formats.}}
446
zz{{Clever things to keep in mind.}}
451
def test_help_text_custom_usage(self):
452
"""Help text may contain a custom usage section."""
453
class cmd_Demo(commands.Command):
454
__doc__ = """A sample command.
463
self.assertCmdHelp('''\
464
zz{{:Purpose: zz{{A sample command.}}
466
zz{{cmd Demo [opts] args}}
472
--usage Show usage message and options.
473
-v, --verbose Display more information.
474
-q, --quiet Only display errors and warnings.
475
-h, --help Show help message.
478
zz{{zz{{Blah blah blah.}}
485
class TestHelp(tests.TestCase):
488
tests.TestCase.setUp(self)
489
commands.install_bzr_command_hooks()
492
class TestRegisteredTopic(TestHelp):
168
class TestRegisteredTopic(tests.TestCase):
493
169
"""Tests for the RegisteredTopic class."""
495
171
def test_contruct(self):
496
172
"""Construction takes the help topic name for the registered item."""
498
174
self.assertTrue('basic' in help_topics.topic_registry)
499
175
topic = help_topics.RegisteredTopic('basic')
500
176
self.assertEqual('basic', topic.topic)
502
178
def test_get_help_text(self):
503
"""RegisteredTopic returns the get_detail results for get_help_text."""
179
"""A RegisteredTopic returns the get_detail results for get_help_text."""
504
180
topic = help_topics.RegisteredTopic('commands')
505
181
self.assertEqual(help_topics.topic_registry.get_detail('commands'),
506
topic.get_help_text())
182
topic.get_help_text())
508
184
def test_get_help_text_with_additional_see_also(self):
509
185
topic = help_topics.RegisteredTopic('commands')