~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Robert Collins
  • Date: 2010-06-25 20:34:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5324.
  • Revision ID: robertc@robertcollins.net-20100625203405-c74lxd3enklhaqf9
``bzrlib.osutils.get_terminal_encoding`` will now only mutter its
selection when explicitly requested; this avoids many duplicate calls
being logged when helpers, wrappers and older code that manually calls
it are executed it is now logged deliberately by the ui setup code.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
    )
30
30
 
31
31
 
 
32
class TestHelp(tests.TestCase):
 
33
 
 
34
    def setUp(self):
 
35
        tests.TestCase.setUp(self)
 
36
        commands.install_bzr_command_hooks()
 
37
 
 
38
 
32
39
class TestCommandHelp(tests.TestCase):
33
40
    """Tests for help on commands."""
34
41
 
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()
49
56
    def test_get_help_text(self):
50
57
        """Commands have a get_help_text method which returns their help."""
51
58
        class cmd_Demo(commands.Command):
52
 
            """A sample command."""
 
59
            __doc__ = """A sample command."""
53
60
        cmd = cmd_Demo()
54
61
        helptext = cmd.get_help_text()
55
62
        self.assertStartsWith(helptext,
60
67
 
61
68
    def test_command_with_additional_see_also(self):
62
69
        class cmd_WithSeeAlso(commands.Command):
63
 
            """A sample command."""
 
70
            __doc__ = """A sample command."""
64
71
            _see_also = ['foo', 'bar']
65
72
        cmd = cmd_WithSeeAlso()
66
73
        helptext = cmd.get_help_text(['gam'])
74
81
 
75
82
    def test_command_only_additional_see_also(self):
76
83
        class cmd_WithSeeAlso(commands.Command):
77
 
            """A sample command."""
 
84
            __doc__ = """A sample command."""
78
85
        cmd = cmd_WithSeeAlso()
79
86
        helptext = cmd.get_help_text(['gam'])
80
87
        self.assertEndsWith(
88
95
    def test_get_help_topic(self):
89
96
        """The help topic for a Command is its name()."""
90
97
        class cmd_foo_bar(commands.Command):
91
 
            """A sample command."""
 
98
            __doc__ = """A sample command."""
92
99
        cmd = cmd_foo_bar()
93
100
        self.assertEqual(cmd.name(), cmd.get_help_topic())
94
101
 
95
102
    def test_formatted_help_text(self):
96
103
        """Help text should be plain text by default."""
97
104
        class cmd_Demo(commands.Command):
98
 
            """A sample command.
 
105
            __doc__ = """A sample command.
99
106
 
100
107
            :Examples:
101
108
                Example 1::
105
112
                Example 2::
106
113
 
107
114
                    cmd arg2
 
115
 
 
116
                A code block follows.
 
117
 
 
118
                ::
 
119
 
 
120
                    bzr Demo something
108
121
            """
109
122
        cmd = cmd_Demo()
110
123
        helptext = cmd.get_help_text()
127
140
            '    Example 2:\n'
128
141
            '\n'
129
142
            '        cmd arg2\n'
 
143
            '\n'
 
144
            '    A code block follows.\n'
 
145
            '\n'
 
146
            '        bzr Demo something\n'
130
147
            '\n')
131
148
        helptext = cmd.get_help_text(plain=False)
132
149
        self.assertEquals(helptext,
147
164
            '    Example 2::\n'
148
165
            '\n'
149
166
            '        cmd arg2\n'
 
167
            '\n'
 
168
            '    A code block follows.\n'
 
169
            '\n'
 
170
            '    ::\n'
 
171
            '\n'
 
172
            '        bzr Demo something\n'
150
173
            '\n')
151
174
 
152
175
    def test_concise_help_text(self):
153
176
        """Concise help text excludes the descriptive sections."""
154
177
        class cmd_Demo(commands.Command):
155
 
            """A sample command.
 
178
            __doc__ = """A sample command.
156
179
 
157
180
            Blah blah blah.
158
181
 
199
222
    def test_help_custom_section_ordering(self):
200
223
        """Custom descriptive sections should remain in the order given."""
201
224
        class cmd_Demo(commands.Command):
202
 
            """A sample command.
 
225
            __doc__ = """A sample command.
203
226
 
204
227
            Blah blah blah.
205
228
 
245
268
    def test_help_text_custom_usage(self):
246
269
        """Help text may contain a custom usage section."""
247
270
        class cmd_Demo(commands.Command):
248
 
            """A sample command.
 
271
            __doc__ = """A sample command.
249
272
 
250
273
            :Usage:
251
274
                cmd Demo [opts] args
274
297
            '  Blah blah blah.\n\n')
275
298
 
276
299
 
277
 
class TestRegisteredTopic(tests.TestCase):
 
300
class TestRegisteredTopic(TestHelp):
278
301
    """Tests for the RegisteredTopic class."""
279
302
 
280
303
    def test_contruct(self):
313
336
        self.assertEqual('baz', topic.get_help_topic())
314
337
 
315
338
 
316
 
class TestTopicIndex(tests.TestCase):
 
339
class TestTopicIndex(TestHelp):
317
340
    """Tests for the HelpTopicIndex class."""
318
341
 
319
342
    def test_default_constructable(self):
346
369
        self.assertEqual('', index.prefix)
347
370
 
348
371
 
349
 
class TestCommandIndex(tests.TestCase):
 
372
class TestCommandIndex(TestHelp):
350
373
    """Tests for the HelpCommandIndex class."""
351
374
 
352
375
    def test_default_constructable(self):