32
from bzrlib.tests.test_i18n import ZzzTranslations
32
class TestHelp(tests.TestCase):
35
tests.TestCase.setUp(self)
36
commands.install_bzr_command_hooks()
36
39
class TestCommandHelp(tests.TestCase):
37
40
"""Tests for help on commands."""
39
def assertCmdHelp(self, expected, cmd):
40
self.assertEqualDiff(textwrap.dedent(expected), cmd.get_help_text())
42
42
def test_command_help_includes_see_also(self):
43
43
class cmd_WithSeeAlso(commands.Command):
44
44
__doc__ = """A sample command."""
45
45
_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.
46
cmd = cmd_WithSeeAlso()
47
helptext = cmd.get_help_text()
50
' -v, --verbose Display more information.\n'
51
' -q, --quiet Only display errors and warnings.\n'
52
' -h, --help Show help message.\n'
54
'See also: bar, foo\n')
60
56
def test_get_help_text(self):
61
57
"""Commands have a get_help_text method which returns their help."""
62
58
class cmd_Demo(commands.Command):
63
59
__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.
77
61
helptext = cmd.get_help_text()
78
62
self.assertStartsWith(helptext,
313
297
' 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
300
class TestRegisteredTopic(TestHelp):
493
301
"""Tests for the RegisteredTopic class."""