~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Vincent Ladeuil
  • Date: 2011-06-27 15:36:58 UTC
  • mto: (5993.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5994.
  • Revision ID: v.ladeuil+lp@free.fr-20110627153658-gr83h2ebsccaf5co
Tweak test_help some more.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import re
34
34
 
35
35
 
36
 
class TestHelp(tests.TestCase):
37
 
 
38
 
    def setUp(self):
39
 
        tests.TestCase.setUp(self)
40
 
        commands.install_bzr_command_hooks()
41
 
 
42
 
 
43
36
class TestCommandHelp(tests.TestCase):
44
37
    """Tests for help on commands."""
45
38
 
 
39
    def assertCmdHelp(self, expected, cmd):
 
40
        self.assertEqualDiff(textwrap.dedent(expected), cmd.get_help_text())
 
41
 
46
42
    def test_command_help_includes_see_also(self):
47
43
        class cmd_WithSeeAlso(commands.Command):
48
44
            __doc__ = """A sample command."""
49
45
            _see_also = ['foo', 'bar']
50
 
        cmd = cmd_WithSeeAlso()
51
 
        helptext = cmd.get_help_text()
52
 
        self.assertEndsWith(
53
 
            helptext,
54
 
            '  -v, --verbose  Display more information.\n'
55
 
            '  -q, --quiet    Only display errors and warnings.\n'
56
 
            '  -h, --help     Show help message.\n'
57
 
            '\n'
58
 
            'See also: bar, foo\n')
 
46
        self.assertCmdHelp('''\
 
47
            Purpose: A sample command.
 
48
            Usage:   bzr WithSeeAlso
 
49
            
 
50
            Options:
 
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.
 
55
            
 
56
            See also: bar, foo
 
57
            ''',
 
58
                           cmd_WithSeeAlso())
59
59
 
60
60
    def test_get_help_text(self):
61
61
        """Commands have a get_help_text method which returns their help."""
62
62
        class cmd_Demo(commands.Command):
63
63
            __doc__ = """A sample command."""
 
64
        self.assertCmdHelp('''\
 
65
            Purpose: A sample command.
 
66
            Usage:   bzr Demo
 
67
            
 
68
            Options:
 
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.
 
73
 
 
74
            ''',
 
75
                           cmd_Demo())
64
76
        cmd = cmd_Demo()
65
77
        helptext = cmd.get_help_text()
66
78
        self.assertStartsWith(helptext,
470
482
                           cmd_Demo())
471
483
 
472
484
 
 
485
class TestHelp(tests.TestCase):
 
486
 
 
487
    def setUp(self):
 
488
        tests.TestCase.setUp(self)
 
489
        commands.install_bzr_command_hooks()
 
490
 
 
491
 
473
492
class TestRegisteredTopic(TestHelp):
474
493
    """Tests for the RegisteredTopic class."""
475
494
 
481
500
        self.assertEqual('basic', topic.topic)
482
501
 
483
502
    def test_get_help_text(self):
484
 
        """A RegisteredTopic returns the get_detail results for get_help_text."""
 
503
        """RegisteredTopic returns the get_detail results for get_help_text."""
485
504
        topic = help_topics.RegisteredTopic('commands')
486
505
        self.assertEqual(help_topics.topic_registry.get_detail('commands'),
487
 
            topic.get_help_text())
 
506
                         topic.get_help_text())
488
507
 
489
508
    def test_get_help_text_with_additional_see_also(self):
490
509
        topic = help_topics.RegisteredTopic('commands')
502
521
            '\n')
503
522
 
504
523
    def test_get_help_topic(self):
505
 
        """The help topic for a RegisteredTopic is its topic from construction."""
 
524
        """The help topic for RegisteredTopic is its topic from construction."""
506
525
        topic = help_topics.RegisteredTopic('foobar')
507
526
        self.assertEqual('foobar', topic.get_help_topic())
508
527
        topic = help_topics.RegisteredTopic('baz')