/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007 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
12
12
#
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Unit tests for the bzrlib.help module."""
18
18
 
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
 
 
39
32
class TestCommandHelp(tests.TestCase):
40
33
    """Tests for help on commands."""
41
34
 
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
39
        cmd = cmd_WithSeeAlso()
47
40
        helptext = cmd.get_help_text()
48
41
        self.assertEndsWith(
49
42
            helptext,
50
 
            '  -v, --verbose  Display more information.\n'
51
 
            '  -q, --quiet    Only display errors and warnings.\n'
52
 
            '  -h, --help     Show help message.\n'
 
43
            '  -h, --help  Show help message.\n'
53
44
            '\n'
54
45
            'See also: bar, foo\n')
55
46
 
56
47
    def test_get_help_text(self):
57
48
        """Commands have a get_help_text method which returns their help."""
58
49
        class cmd_Demo(commands.Command):
59
 
            __doc__ = """A sample command."""
 
50
            """A sample command."""
60
51
        cmd = cmd_Demo()
61
52
        helptext = cmd.get_help_text()
62
53
        self.assertStartsWith(helptext,
63
54
            'Purpose: A sample command.\n'
64
55
            'Usage:   bzr Demo')
65
 
        self.assertEndsWith(helptext,
66
 
            '  -h, --help     Show help message.\n\n')
 
56
        self.assertEndsWith(helptext, 'Show help message.\n\n')
67
57
 
68
58
    def test_command_with_additional_see_also(self):
69
59
        class cmd_WithSeeAlso(commands.Command):
70
 
            __doc__ = """A sample command."""
 
60
            """A sample command."""
71
61
            _see_also = ['foo', 'bar']
72
62
        cmd = cmd_WithSeeAlso()
73
63
        helptext = cmd.get_help_text(['gam'])
74
64
        self.assertEndsWith(
75
65
            helptext,
76
 
            '  -v, --verbose  Display more information.\n'
77
 
            '  -q, --quiet    Only display errors and warnings.\n'
78
 
            '  -h, --help     Show help message.\n'
 
66
            '  -h, --help  Show help message.\n'
79
67
            '\n'
80
68
            'See also: bar, foo, gam\n')
81
69
 
82
70
    def test_command_only_additional_see_also(self):
83
71
        class cmd_WithSeeAlso(commands.Command):
84
 
            __doc__ = """A sample command."""
 
72
            """A sample command."""
85
73
        cmd = cmd_WithSeeAlso()
86
74
        helptext = cmd.get_help_text(['gam'])
87
75
        self.assertEndsWith(
88
76
            helptext,
89
 
            '  -v, --verbose  Display more information.\n'
90
 
            '  -q, --quiet    Only display errors and warnings.\n'
91
 
            '  -h, --help     Show help message.\n'
 
77
            '  -h, --help  Show help message.\n'
92
78
            '\n'
93
79
            'See also: gam\n')
94
80
 
95
81
    def test_get_help_topic(self):
96
82
        """The help topic for a Command is its name()."""
97
83
        class cmd_foo_bar(commands.Command):
98
 
            __doc__ = """A sample command."""
 
84
            """A sample command."""
99
85
        cmd = cmd_foo_bar()
100
86
        self.assertEqual(cmd.name(), cmd.get_help_topic())
101
87
 
102
88
    def test_formatted_help_text(self):
103
89
        """Help text should be plain text by default."""
104
90
        class cmd_Demo(commands.Command):
105
 
            __doc__ = """A sample command.
106
 
 
 
91
            """A sample command.
 
92
 
107
93
            :Examples:
108
94
                Example 1::
109
 
 
 
95
 
110
96
                    cmd arg1
111
 
 
 
97
 
112
98
                Example 2::
113
 
 
 
99
 
114
100
                    cmd arg2
115
101
            """
116
102
        cmd = cmd_Demo()
121
107
            'Usage:   bzr Demo\n'
122
108
            '\n'
123
109
            'Options:\n'
124
 
            '  --usage        Show usage message and options.\n'
125
 
            '  -0, --null     Use an ASCII NUL (\\0) separator rather than a newline.\n'
126
 
            '  -v, --verbose  Display more information.\n'
127
 
            '  -q, --quiet    Only display errors and warnings.\n'
128
 
            '  -h, --help     Show help message.\n'
 
110
            '  -h, --help  Show help message.\n'
129
111
            '\n'
130
112
            'Examples:\n'
131
113
            '    Example 1:\n'
142
124
            ':Usage:   bzr Demo\n'
143
125
            '\n'
144
126
            ':Options:\n'
145
 
            '  --usage        Show usage message and options.\n'
146
 
            '  -0, --null     Use an ASCII NUL (\\0) separator rather than a newline.\n'
147
 
            '  -v, --verbose  Display more information.\n'
148
 
            '  -q, --quiet    Only display errors and warnings.\n'
149
 
            '  -h, --help     Show help message.\n'
 
127
            '  -h, --help  Show help message.\n'
150
128
            '\n'
151
129
            ':Examples:\n'
152
130
            '    Example 1::\n'
158
136
            '        cmd arg2\n'
159
137
            '\n')
160
138
 
161
 
    def test_concise_help_text(self):
162
 
        """Concise help text excludes the descriptive sections."""
163
 
        class cmd_Demo(commands.Command):
164
 
            __doc__ = """A sample command.
165
 
 
166
 
            Blah blah blah.
167
 
 
168
 
            :Examples:
169
 
                Example 1::
170
 
 
171
 
                    cmd arg1
172
 
            """
173
 
        cmd = cmd_Demo()
174
 
        helptext = cmd.get_help_text()
175
 
        self.assertEqualDiff(
176
 
            helptext,
177
 
            'Purpose: A sample command.\n'
178
 
            'Usage:   bzr Demo\n'
179
 
            '\n'
180
 
            'Options:\n'
181
 
            '  --usage        Show usage message and options.\n'
182
 
            '  -0, --null     Use an ASCII NUL (\\0) separator rather than a newline.\n'
183
 
            '  -v, --verbose  Display more information.\n'
184
 
            '  -q, --quiet    Only display errors and warnings.\n'
185
 
            '  -h, --help     Show help message.\n'
186
 
            '\n'
187
 
            'Description:\n'
188
 
            '  Blah blah blah.\n'
189
 
            '\n'
190
 
            'Examples:\n'
191
 
            '    Example 1:\n'
192
 
            '\n'
193
 
            '        cmd arg1\n'
194
 
            '\n')
195
 
        helptext = cmd.get_help_text(verbose=False)
196
 
        self.assertEquals(helptext,
197
 
            'Purpose: A sample command.\n'
198
 
            'Usage:   bzr Demo\n'
199
 
            '\n'
200
 
            'Options:\n'
201
 
            '  --usage        Show usage message and options.\n'
202
 
            '  -0, --null     Use an ASCII NUL (\\0) separator rather than a newline.\n'
203
 
            '  -v, --verbose  Display more information.\n'
204
 
            '  -q, --quiet    Only display errors and warnings.\n'
205
 
            '  -h, --help     Show help message.\n'
206
 
            '\n'
207
 
            'See bzr help Demo for more details and examples.\n'
208
 
            '\n')
209
 
 
210
 
    def test_help_custom_section_ordering(self):
211
 
        """Custom descriptive sections should remain in the order given."""
212
 
        class cmd_Demo(commands.Command):
213
 
            __doc__ = """A sample command.
214
 
 
215
 
            Blah blah blah.
216
 
 
217
 
            :Formats:
218
 
              Interesting stuff about formats.
219
 
 
220
 
            :Examples:
221
 
              Example 1::
222
 
 
223
 
                cmd arg1
224
 
 
225
 
            :Tips:
226
 
              Clever things to keep in mind.
227
 
            """
228
 
        cmd = cmd_Demo()
229
 
        helptext = cmd.get_help_text()
230
 
        self.assertEqualDiff(
231
 
            helptext,
232
 
            'Purpose: A sample command.\n'
233
 
            'Usage:   bzr Demo\n'
234
 
            '\n'
235
 
            'Options:\n'
236
 
            '  --usage        Show usage message and options.\n'
237
 
            '  -0, --null     Use an ASCII NUL (\\0) separator rather than a newline.\n'
238
 
            '  -v, --verbose  Display more information.\n'
239
 
            '  -q, --quiet    Only display errors and warnings.\n'
240
 
            '  -h, --help     Show help message.\n'
241
 
            '\n'
242
 
            'Description:\n'
243
 
            '  Blah blah blah.\n'
244
 
            '\n'
245
 
            'Formats:\n'
246
 
            '  Interesting stuff about formats.\n'
247
 
            '\n'
248
 
            'Examples:\n'
249
 
            '  Example 1:\n'
250
 
            '\n'
251
 
            '    cmd arg1\n'
252
 
            '\n'
253
 
            'Tips:\n'
254
 
            '  Clever things to keep in mind.\n'
255
 
            '\n')
256
 
 
257
139
    def test_help_text_custom_usage(self):
258
140
        """Help text may contain a custom usage section."""
259
141
        class cmd_Demo(commands.Command):
260
 
            __doc__ = """A sample command.
261
 
 
 
142
            """A sample command.
 
143
 
262
144
            :Usage:
263
145
                cmd Demo [opts] args
264
 
 
 
146
 
265
147
                cmd Demo -h
266
 
 
 
148
 
267
149
            Blah blah blah.
268
150
            """
269
151
        cmd = cmd_Demo()
277
159
            '\n'
278
160
            '\n'
279
161
            'Options:\n'
280
 
            '  --usage        Show usage message and options.\n'
281
 
            '  -0, --null     Use an ASCII NUL (\\0) separator rather than a newline.\n'
282
 
            '  -v, --verbose  Display more information.\n'
283
 
            '  -q, --quiet    Only display errors and warnings.\n'
284
 
            '  -h, --help     Show help message.\n'
 
162
            '  -h, --help  Show help message.\n'
285
163
            '\n'
286
164
            'Description:\n'
287
165
            '  Blah blah blah.\n\n')
288
166
 
289
167
 
290
 
class TestRegisteredTopic(TestHelp):
 
168
class TestRegisteredTopic(tests.TestCase):
291
169
    """Tests for the RegisteredTopic class."""
292
170
 
293
171
    def test_contruct(self):
294
172
        """Construction takes the help topic name for the registered item."""
295
 
        # validate our test
 
173
        # validate our test 
296
174
        self.assertTrue('basic' in help_topics.topic_registry)
297
175
        topic = help_topics.RegisteredTopic('basic')
298
176
        self.assertEqual('basic', topic.topic)
310
188
            '\n'
311
189
            'See also: bar, foo\n')
312
190
 
313
 
    def test_get_help_text_loaded_from_file(self):
314
 
        # Pick a known topic stored in an external file
315
 
        topic = help_topics.RegisteredTopic('authentication')
316
 
        self.assertStartsWith(topic.get_help_text(),
317
 
            'Authentication Settings\n'
318
 
            '=======================\n'
319
 
            '\n')
320
 
 
321
191
    def test_get_help_topic(self):
322
192
        """The help topic for a RegisteredTopic is its topic from construction."""
323
193
        topic = help_topics.RegisteredTopic('foobar')
326
196
        self.assertEqual('baz', topic.get_help_topic())
327
197
 
328
198
 
329
 
class TestTopicIndex(TestHelp):
 
199
class TestTopicIndex(tests.TestCase):
330
200
    """Tests for the HelpTopicIndex class."""
331
201
 
332
202
    def test_default_constructable(self):
359
229
        self.assertEqual('', index.prefix)
360
230
 
361
231
 
362
 
class TestCommandIndex(TestHelp):
 
232
class TestCommandIndex(tests.TestCase):
363
233
    """Tests for the HelpCommandIndex class."""
364
234
 
365
235
    def test_default_constructable(self):