~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-07-07 21:30:06 UTC
  • mfrom: (5333.1.2 better_pyqt_include)
  • Revision ID: pqm@pqm.ubuntu.com-20100707213006-lriphkkbzwwrl7ne
(jameinel) Use a better list of PyQt includes and excludes. (Gary van der
 Merwe)

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