/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

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2012, 2016 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Unit tests for the breezy.help module."""
18
 
 
19
 
import textwrap
20
 
 
21
 
from .. import (
 
17
"""Unit tests for the bzrlib.help module."""
 
18
 
 
19
from cStringIO import StringIO
 
20
 
 
21
from bzrlib import (
22
22
    builtins,
23
23
    commands,
24
 
    config,
25
24
    errors,
26
25
    help,
27
26
    help_topics,
28
 
    i18n,
29
27
    plugin,
30
28
    tests,
31
29
    )
32
30
 
33
 
from .test_i18n import ZzzTranslations
34
 
import re
35
 
 
36
 
 
37
 
class TestErrors(tests.TestCase):
38
 
 
39
 
    def test_no_help_topic(self):
40
 
        error = help.NoHelpTopic("topic")
41
 
        self.assertEqualDiff("No help could be found for 'topic'. "
42
 
                             "Please use 'brz help topics' to obtain a list of topics.",
43
 
                             str(error))
 
31
 
 
32
class TestHelp(tests.TestCase):
 
33
 
 
34
    def setUp(self):
 
35
        tests.TestCase.setUp(self)
 
36
        commands.install_bzr_command_hooks()
44
37
 
45
38
 
46
39
class TestCommandHelp(tests.TestCase):
47
40
    """Tests for help on commands."""
48
41
 
49
 
    def assertCmdHelp(self, expected, cmd):
50
 
        self.assertEqualDiff(textwrap.dedent(expected), cmd.get_help_text())
51
 
 
52
42
    def test_command_help_includes_see_also(self):
53
43
        class cmd_WithSeeAlso(commands.Command):
54
44
            __doc__ = """A sample command."""
55
45
            _see_also = ['foo', 'bar']
56
 
        self.assertCmdHelp('''\
57
 
Purpose: A sample command.
58
 
Usage:   brz WithSeeAlso
59
 
 
60
 
Options:
61
 
  -h, --help     Show help message.
62
 
  -q, --quiet    Only display errors and warnings.
63
 
  --usage        Show usage message and options.
64
 
  -v, --verbose  Display more information.
65
 
 
66
 
See also: bar, foo
67
 
''',
68
 
                           cmd_WithSeeAlso())
 
46
        cmd = cmd_WithSeeAlso()
 
47
        helptext = cmd.get_help_text()
 
48
        self.assertEndsWith(
 
49
            helptext,
 
50
            '  -v, --verbose  Display more information.\n'
 
51
            '  -q, --quiet    Only display errors and warnings.\n'
 
52
            '  -h, --help     Show help message.\n'
 
53
            '\n'
 
54
            'See also: bar, foo\n')
69
55
 
70
56
    def test_get_help_text(self):
71
57
        """Commands have a get_help_text method which returns their help."""
72
58
        class cmd_Demo(commands.Command):
73
59
            __doc__ = """A sample command."""
74
 
        self.assertCmdHelp('''\
75
 
Purpose: A sample command.
76
 
Usage:   brz Demo
77
 
 
78
 
Options:
79
 
  -h, --help     Show help message.
80
 
  -q, --quiet    Only display errors and warnings.
81
 
  --usage        Show usage message and options.
82
 
  -v, --verbose  Display more information.
83
 
 
84
 
''',
85
 
                           cmd_Demo())
86
60
        cmd = cmd_Demo()
87
61
        helptext = cmd.get_help_text()
88
62
        self.assertStartsWith(helptext,
89
 
                              'Purpose: A sample command.\n'
90
 
                              'Usage:   brz Demo')
 
63
            'Purpose: A sample command.\n'
 
64
            'Usage:   bzr Demo')
91
65
        self.assertEndsWith(helptext,
92
 
                            '  -v, --verbose  Display more information.\n\n')
 
66
            '  -h, --help     Show help message.\n\n')
93
67
 
94
68
    def test_command_with_additional_see_also(self):
95
69
        class cmd_WithSeeAlso(commands.Command):
99
73
        helptext = cmd.get_help_text(['gam'])
100
74
        self.assertEndsWith(
101
75
            helptext,
 
76
            '  -v, --verbose  Display more information.\n'
 
77
            '  -q, --quiet    Only display errors and warnings.\n'
102
78
            '  -h, --help     Show help message.\n'
103
 
            '  -q, --quiet    Only display errors and warnings.\n'
104
 
            '  --usage        Show usage message and options.\n'
105
 
            '  -v, --verbose  Display more information.\n'
106
79
            '\n'
107
80
            'See also: bar, foo, gam\n')
108
81
 
114
87
        self.assertEndsWith(
115
88
            helptext,
116
89
            '  -v, --verbose  Display more information.\n'
 
90
            '  -q, --quiet    Only display errors and warnings.\n'
 
91
            '  -h, --help     Show help message.\n'
117
92
            '\n'
118
93
            'See also: gam\n')
119
94
 
137
112
                Example 2::
138
113
 
139
114
                    cmd arg2
140
 
 
141
 
                A code block follows.
142
 
 
143
 
                ::
144
 
 
145
 
                    brz Demo something
146
115
            """
147
116
        cmd = cmd_Demo()
148
117
        helptext = cmd.get_help_text()
149
 
        self.assertEqualDiff('''\
150
 
Purpose: A sample command.
151
 
Usage:   brz Demo
152
 
 
153
 
Options:
154
 
  -h, --help     Show help message.
155
 
  -q, --quiet    Only display errors and warnings.
156
 
  --usage        Show usage message and options.
157
 
  -v, --verbose  Display more information.
158
 
 
159
 
Examples:
160
 
    Example 1:
161
 
 
162
 
        cmd arg1
163
 
 
164
 
    Example 2:
165
 
 
166
 
        cmd arg2
167
 
 
168
 
    A code block follows.
169
 
 
170
 
        brz Demo something
171
 
 
172
 
''',
173
 
                             helptext)
 
118
        self.assertEquals(
 
119
            helptext,
 
120
            'Purpose: A sample command.\n'
 
121
            'Usage:   bzr Demo\n'
 
122
            '\n'
 
123
            'Options:\n'
 
124
            '  --usage        Show usage message and options.\n'
 
125
            '  -v, --verbose  Display more information.\n'
 
126
            '  -q, --quiet    Only display errors and warnings.\n'
 
127
            '  -h, --help     Show help message.\n'
 
128
            '\n'
 
129
            'Examples:\n'
 
130
            '    Example 1:\n'
 
131
            '\n'
 
132
            '        cmd arg1\n'
 
133
            '\n'
 
134
            '    Example 2:\n'
 
135
            '\n'
 
136
            '        cmd arg2\n'
 
137
            '\n')
174
138
        helptext = cmd.get_help_text(plain=False)
175
 
        self.assertEqualDiff('''\
176
 
:Purpose: A sample command.
177
 
:Usage:   brz Demo
178
 
 
179
 
:Options:
180
 
  -h, --help     Show help message.
181
 
  -q, --quiet    Only display errors and warnings.
182
 
  --usage        Show usage message and options.
183
 
  -v, --verbose  Display more information.
184
 
 
185
 
:Examples:
186
 
    Example 1::
187
 
 
188
 
        cmd arg1
189
 
 
190
 
    Example 2::
191
 
 
192
 
        cmd arg2
193
 
 
194
 
    A code block follows.
195
 
 
196
 
    ::
197
 
 
198
 
        brz Demo something
199
 
 
200
 
''',
201
 
                             helptext)
 
139
        self.assertEquals(helptext,
 
140
            ':Purpose: A sample command.\n'
 
141
            ':Usage:   bzr Demo\n'
 
142
            '\n'
 
143
            ':Options:\n'
 
144
            '  --usage        Show usage message and options.\n'
 
145
            '  -v, --verbose  Display more information.\n'
 
146
            '  -q, --quiet    Only display errors and warnings.\n'
 
147
            '  -h, --help     Show help message.\n'
 
148
            '\n'
 
149
            ':Examples:\n'
 
150
            '    Example 1::\n'
 
151
            '\n'
 
152
            '        cmd arg1\n'
 
153
            '\n'
 
154
            '    Example 2::\n'
 
155
            '\n'
 
156
            '        cmd arg2\n'
 
157
            '\n')
202
158
 
203
159
    def test_concise_help_text(self):
204
160
        """Concise help text excludes the descriptive sections."""
205
161
        class cmd_Demo(commands.Command):
206
162
            __doc__ = """A sample command.
207
 
 
 
163
 
208
164
            Blah blah blah.
209
165
 
210
166
            :Examples:
211
167
                Example 1::
212
 
 
 
168
 
213
169
                    cmd arg1
214
170
            """
215
171
        cmd = cmd_Demo()
216
172
        helptext = cmd.get_help_text()
217
 
        self.assertEqualDiff('''\
218
 
Purpose: A sample command.
219
 
Usage:   brz Demo
220
 
 
221
 
Options:
222
 
  -h, --help     Show help message.
223
 
  -q, --quiet    Only display errors and warnings.
224
 
  --usage        Show usage message and options.
225
 
  -v, --verbose  Display more information.
226
 
 
227
 
Description:
228
 
  Blah blah blah.
229
 
 
230
 
Examples:
231
 
    Example 1:
232
 
 
233
 
        cmd arg1
234
 
 
235
 
''',
236
 
                             helptext)
 
173
        self.assertEqualDiff(
 
174
            helptext,
 
175
            'Purpose: A sample command.\n'
 
176
            'Usage:   bzr Demo\n'
 
177
            '\n'
 
178
            'Options:\n'
 
179
            '  --usage        Show usage message and options.\n'
 
180
            '  -v, --verbose  Display more information.\n'
 
181
            '  -q, --quiet    Only display errors and warnings.\n'
 
182
            '  -h, --help     Show help message.\n'
 
183
            '\n'
 
184
            'Description:\n'
 
185
            '  Blah blah blah.\n'
 
186
            '\n'
 
187
            'Examples:\n'
 
188
            '    Example 1:\n'
 
189
            '\n'
 
190
            '        cmd arg1\n'
 
191
            '\n')
237
192
        helptext = cmd.get_help_text(verbose=False)
238
 
        self.assertEqualDiff('''\
239
 
Purpose: A sample command.
240
 
Usage:   brz Demo
241
 
 
242
 
Options:
243
 
  -h, --help     Show help message.
244
 
  -q, --quiet    Only display errors and warnings.
245
 
  --usage        Show usage message and options.
246
 
  -v, --verbose  Display more information.
247
 
 
248
 
See brz help Demo for more details and examples.
249
 
 
250
 
''',
251
 
                             helptext)
252
 
 
253
 
    def test_help_custom_section_ordering(self):
254
 
        """Custom descriptive sections should remain in the order given."""
255
 
        class cmd_Demo(commands.Command):
256
 
            __doc__ = """\
257
 
A sample command.
258
 
 
259
 
Blah blah blah.
260
 
 
261
 
:Formats:
262
 
  Interesting stuff about formats.
263
 
 
264
 
:Examples:
265
 
  Example 1::
266
 
 
267
 
    cmd arg1
268
 
 
269
 
:Tips:
270
 
  Clever things to keep in mind.
271
 
"""
272
 
        cmd = cmd_Demo()
273
 
        helptext = cmd.get_help_text()
274
 
        self.assertEqualDiff('''\
275
 
Purpose: A sample command.
276
 
Usage:   brz Demo
277
 
 
278
 
Options:
279
 
  -h, --help     Show help message.
280
 
  -q, --quiet    Only display errors and warnings.
281
 
  --usage        Show usage message and options.
282
 
  -v, --verbose  Display more information.
283
 
 
284
 
Description:
285
 
  Blah blah blah.
286
 
 
287
 
Formats:
288
 
  Interesting stuff about formats.
289
 
 
290
 
Examples:
291
 
  Example 1:
292
 
 
293
 
    cmd arg1
294
 
 
295
 
Tips:
296
 
  Clever things to keep in mind.
297
 
 
298
 
''',
299
 
                             helptext)
300
 
 
301
 
    def test_help_text_custom_usage(self):
302
 
        """Help text may contain a custom usage section."""
303
 
        class cmd_Demo(commands.Command):
304
 
            __doc__ = """A sample command.
305
 
 
306
 
            :Usage:
307
 
                cmd Demo [opts] args
308
 
 
309
 
                cmd Demo -h
310
 
 
311
 
            Blah blah blah.
312
 
            """
313
 
        cmd = cmd_Demo()
314
 
        helptext = cmd.get_help_text()
315
 
        self.assertEqualDiff('''\
316
 
Purpose: A sample command.
317
 
Usage:
318
 
    cmd Demo [opts] args
319
 
 
320
 
    cmd Demo -h
321
 
 
322
 
 
323
 
Options:
324
 
  -h, --help     Show help message.
325
 
  -q, --quiet    Only display errors and warnings.
326
 
  --usage        Show usage message and options.
327
 
  -v, --verbose  Display more information.
328
 
 
329
 
Description:
330
 
  Blah blah blah.
331
 
 
332
 
''',
333
 
                             helptext)
334
 
 
335
 
 
336
 
class ZzzTranslationsForDoc(ZzzTranslations):
337
 
 
338
 
    _section_pat = re.compile(':\\w+:\\n\\s+')
339
 
    _indent_pat = re.compile('\\s+')
340
 
 
341
 
    def zzz(self, s):
342
 
        m = self._section_pat.match(s)
343
 
        if m is None:
344
 
            m = self._indent_pat.match(s)
345
 
        if m:
346
 
            return u'%szz{{%s}}' % (m.group(0), s[m.end():])
347
 
        return u'zz{{%s}}' % s
348
 
 
349
 
 
350
 
class TestCommandHelpI18n(tests.TestCase):
351
 
    """Tests for help on translated commands."""
352
 
 
353
 
    def setUp(self):
354
 
        super(TestCommandHelpI18n, self).setUp()
355
 
        self.overrideAttr(i18n, '_translations', ZzzTranslationsForDoc())
356
 
 
357
 
    def assertCmdHelp(self, expected, cmd):
358
 
        self.assertEqualDiff(textwrap.dedent(expected), cmd.get_help_text())
359
 
 
360
 
    def test_command_help_includes_see_also(self):
361
 
        class cmd_WithSeeAlso(commands.Command):
362
 
            __doc__ = """A sample command."""
363
 
            _see_also = ['foo', 'bar']
364
 
        self.assertCmdHelp('''\
365
 
zz{{:Purpose: zz{{A sample command.}}
366
 
}}zz{{:Usage:   brz WithSeeAlso
367
 
}}
368
 
zz{{:Options:
369
 
  -h, --help     zz{{Show help message.}}
370
 
  -q, --quiet    zz{{Only display errors and warnings.}}
371
 
  --usage        zz{{Show usage message and options.}}
372
 
  -v, --verbose  zz{{Display more information.}}
373
 
}}
374
 
zz{{:See also: bar, foo}}
375
 
''',
376
 
                           cmd_WithSeeAlso())
377
 
 
378
 
    def test_get_help_text(self):
379
 
        """Commands have a get_help_text method which returns their help."""
380
 
        class cmd_Demo(commands.Command):
381
 
            __doc__ = """A sample command."""
382
 
        self.assertCmdHelp('''\
383
 
zz{{:Purpose: zz{{A sample command.}}
384
 
}}zz{{:Usage:   brz Demo
385
 
}}
386
 
zz{{:Options:
387
 
  -h, --help     zz{{Show help message.}}
388
 
  -q, --quiet    zz{{Only display errors and warnings.}}
389
 
  --usage        zz{{Show usage message and options.}}
390
 
  -v, --verbose  zz{{Display more information.}}
391
 
}}
392
 
''',
393
 
                           cmd_Demo())
394
 
 
395
 
    def test_command_with_additional_see_also(self):
396
 
        class cmd_WithSeeAlso(commands.Command):
397
 
            __doc__ = """A sample command."""
398
 
            _see_also = ['foo', 'bar']
399
 
        cmd = cmd_WithSeeAlso()
400
 
        helptext = cmd.get_help_text(['gam'])
401
 
        self.assertEndsWith(
402
 
            helptext, '''\
403
 
  -h, --help     zz{{Show help message.}}
404
 
  -q, --quiet    zz{{Only display errors and warnings.}}
405
 
  --usage        zz{{Show usage message and options.}}
406
 
  -v, --verbose  zz{{Display more information.}}
407
 
}}
408
 
zz{{:See also: bar, foo, gam}}
409
 
''')
410
 
 
411
 
    def test_command_only_additional_see_also(self):
412
 
        class cmd_WithSeeAlso(commands.Command):
413
 
            __doc__ = """A sample command."""
414
 
        cmd = cmd_WithSeeAlso()
415
 
        helptext = cmd.get_help_text(['gam'])
416
 
        self.assertEndsWith(
417
 
            helptext, '''\
418
 
zz{{:Options:
419
 
  -h, --help     zz{{Show help message.}}
420
 
  -q, --quiet    zz{{Only display errors and warnings.}}
421
 
  --usage        zz{{Show usage message and options.}}
422
 
  -v, --verbose  zz{{Display more information.}}
423
 
}}
424
 
zz{{:See also: gam}}
425
 
''')
426
 
 
427
 
    def test_help_custom_section_ordering(self):
428
 
        """Custom descriptive sections should remain in the order given."""
429
 
        # The help formatter expect the class name to start with 'cmd_'
430
 
        class cmd_Demo(commands.Command):
431
 
            __doc__ = """A sample command.
432
 
 
 
193
        self.assertEquals(helptext,
 
194
            'Purpose: A sample command.\n'
 
195
            'Usage:   bzr Demo\n'
 
196
            '\n'
 
197
            'Options:\n'
 
198
            '  --usage        Show usage message and options.\n'
 
199
            '  -v, --verbose  Display more information.\n'
 
200
            '  -q, --quiet    Only display errors and warnings.\n'
 
201
            '  -h, --help     Show help message.\n'
 
202
            '\n'
 
203
            'See bzr help Demo for more details and examples.\n'
 
204
            '\n')
 
205
 
 
206
    def test_help_custom_section_ordering(self):
 
207
        """Custom descriptive sections should remain in the order given."""
 
208
        class cmd_Demo(commands.Command):
 
209
            __doc__ = """A sample command.
 
210
 
433
211
            Blah blah blah.
434
212
 
435
213
            :Formats:
437
215
 
438
216
            :Examples:
439
217
              Example 1::
440
 
 
 
218
 
441
219
                cmd arg1
442
220
 
443
221
            :Tips:
444
222
              Clever things to keep in mind.
445
223
            """
446
 
        self.assertCmdHelp('''\
447
 
zz{{:Purpose: zz{{A sample command.}}
448
 
}}zz{{:Usage:   brz Demo
449
 
}}
450
 
zz{{:Options:
451
 
  -h, --help     zz{{Show help message.}}
452
 
  -q, --quiet    zz{{Only display errors and warnings.}}
453
 
  --usage        zz{{Show usage message and options.}}
454
 
  -v, --verbose  zz{{Display more information.}}
455
 
}}
456
 
Description:
457
 
  zz{{zz{{Blah blah blah.}}
458
 
 
459
 
}}:Formats:
460
 
  zz{{Interesting stuff about formats.}}
461
 
 
462
 
Examples:
463
 
  zz{{Example 1::}}
464
 
 
465
 
    zz{{cmd arg1}}
466
 
 
467
 
Tips:
468
 
  zz{{Clever things to keep in mind.}}
469
 
 
470
 
''',
471
 
                           cmd_Demo())
 
224
        cmd = cmd_Demo()
 
225
        helptext = cmd.get_help_text()
 
226
        self.assertEqualDiff(
 
227
            helptext,
 
228
            'Purpose: A sample command.\n'
 
229
            'Usage:   bzr Demo\n'
 
230
            '\n'
 
231
            'Options:\n'
 
232
            '  --usage        Show usage message and options.\n'
 
233
            '  -v, --verbose  Display more information.\n'
 
234
            '  -q, --quiet    Only display errors and warnings.\n'
 
235
            '  -h, --help     Show help message.\n'
 
236
            '\n'
 
237
            'Description:\n'
 
238
            '  Blah blah blah.\n'
 
239
            '\n'
 
240
            'Formats:\n'
 
241
            '  Interesting stuff about formats.\n'
 
242
            '\n'
 
243
            'Examples:\n'
 
244
            '  Example 1:\n'
 
245
            '\n'
 
246
            '    cmd arg1\n'
 
247
            '\n'
 
248
            'Tips:\n'
 
249
            '  Clever things to keep in mind.\n'
 
250
            '\n')
472
251
 
473
252
    def test_help_text_custom_usage(self):
474
253
        """Help text may contain a custom usage section."""
482
261
 
483
262
            Blah blah blah.
484
263
            """
485
 
        self.assertCmdHelp('''\
486
 
zz{{:Purpose: zz{{A sample command.}}
487
 
}}zz{{:Usage:
488
 
    zz{{cmd Demo [opts] args}}
489
 
 
490
 
    zz{{cmd Demo -h}}
491
 
 
492
 
}}
493
 
zz{{:Options:
494
 
  -h, --help     zz{{Show help message.}}
495
 
  -q, --quiet    zz{{Only display errors and warnings.}}
496
 
  --usage        zz{{Show usage message and options.}}
497
 
  -v, --verbose  zz{{Display more information.}}
498
 
}}
499
 
Description:
500
 
  zz{{zz{{Blah blah blah.}}
501
 
 
502
 
}}
503
 
''',
504
 
                           cmd_Demo())
505
 
 
506
 
 
507
 
class TestHelp(tests.TestCase):
508
 
 
509
 
    def setUp(self):
510
 
        super(TestHelp, self).setUp()
511
 
        commands.install_bzr_command_hooks()
 
264
        cmd = cmd_Demo()
 
265
        helptext = cmd.get_help_text()
 
266
        self.assertEquals(helptext,
 
267
            'Purpose: A sample command.\n'
 
268
            'Usage:\n'
 
269
            '    cmd Demo [opts] args\n'
 
270
            '\n'
 
271
            '    cmd Demo -h\n'
 
272
            '\n'
 
273
            '\n'
 
274
            'Options:\n'
 
275
            '  --usage        Show usage message and options.\n'
 
276
            '  -v, --verbose  Display more information.\n'
 
277
            '  -q, --quiet    Only display errors and warnings.\n'
 
278
            '  -h, --help     Show help message.\n'
 
279
            '\n'
 
280
            'Description:\n'
 
281
            '  Blah blah blah.\n\n')
512
282
 
513
283
 
514
284
class TestRegisteredTopic(TestHelp):
522
292
        self.assertEqual('basic', topic.topic)
523
293
 
524
294
    def test_get_help_text(self):
525
 
        """RegisteredTopic returns the get_detail results for get_help_text."""
 
295
        """A RegisteredTopic returns the get_detail results for get_help_text."""
526
296
        topic = help_topics.RegisteredTopic('commands')
527
297
        self.assertEqual(help_topics.topic_registry.get_detail('commands'),
528
 
                         topic.get_help_text())
 
298
            topic.get_help_text())
529
299
 
530
300
    def test_get_help_text_with_additional_see_also(self):
531
301
        topic = help_topics.RegisteredTopic('commands')
538
308
        # Pick a known topic stored in an external file
539
309
        topic = help_topics.RegisteredTopic('authentication')
540
310
        self.assertStartsWith(topic.get_help_text(),
541
 
                              'Authentication Settings\n'
542
 
                              '=======================\n'
543
 
                              '\n')
 
311
            'Authentication Settings\n'
 
312
            '=======================\n'
 
313
            '\n')
544
314
 
545
315
    def test_get_help_topic(self):
546
 
        """The help topic for RegisteredTopic is its topic from construction."""
 
316
        """The help topic for a RegisteredTopic is its topic from construction."""
547
317
        topic = help_topics.RegisteredTopic('foobar')
548
318
        self.assertEqual('foobar', topic.get_help_topic())
549
319
        topic = help_topics.RegisteredTopic('baz')
583
353
        self.assertEqual('', index.prefix)
584
354
 
585
355
 
586
 
class TestConfigOptionIndex(TestHelp):
587
 
    """Tests for the HelpCommandIndex class."""
588
 
 
589
 
    def setUp(self):
590
 
        super(TestConfigOptionIndex, self).setUp()
591
 
        self.index = help_topics.ConfigOptionHelpIndex()
592
 
 
593
 
    def test_get_topics_None(self):
594
 
        """Searching for None returns an empty list."""
595
 
        self.assertEqual([], self.index.get_topics(None))
596
 
 
597
 
    def test_get_topics_no_topic(self):
598
 
        self.assertEqual([], self.index.get_topics('nothing by this name'))
599
 
 
600
 
    def test_prefix(self):
601
 
        self.assertEqual('configuration/', self.index.prefix)
602
 
 
603
 
    def test_get_topic_with_prefix(self):
604
 
        topics = self.index.get_topics('configuration/default_format')
605
 
        self.assertLength(1, topics)
606
 
        opt = topics[0]
607
 
        self.assertIsInstance(opt, config.Option)
608
 
        self.assertEqual('default_format', opt.name)
609
 
 
610
 
 
611
356
class TestCommandIndex(TestHelp):
612
357
    """Tests for the HelpCommandIndex class."""
613
358
 
650
395
    def test_default_search_path(self):
651
396
        """The default search path should include internal indexs."""
652
397
        indices = help.HelpIndices()
653
 
        self.assertEqual(4, len(indices.search_path))
 
398
        self.assertEqual(3, len(indices.search_path))
654
399
        # help topics should be searched in first.
655
400
        self.assertIsInstance(indices.search_path[0],
656
 
                              help_topics.HelpTopicIndex)
 
401
            help_topics.HelpTopicIndex)
657
402
        # with commands being search second.
658
403
        self.assertIsInstance(indices.search_path[1],
659
 
                              commands.HelpCommandIndex)
660
 
        # plugins are a third index.
 
404
            commands.HelpCommandIndex)
 
405
        # and plugins are a third index.
661
406
        self.assertIsInstance(indices.search_path[2],
662
 
                              plugin.PluginsHelpIndex)
663
 
        # config options are a fourth index
664
 
        self.assertIsInstance(indices.search_path[3],
665
 
                              help_topics.ConfigOptionHelpIndex)
 
407
            plugin.PluginsHelpIndex)
666
408
 
667
409
    def test_search_for_unknown_topic_raises(self):
668
410
        """Searching for an unknown topic should raise NoHelpTopic."""
669
411
        indices = help.HelpIndices()
670
412
        indices.search_path = []
671
 
        error = self.assertRaises(help.NoHelpTopic, indices.search, 'foo')
 
413
        error = self.assertRaises(errors.NoHelpTopic, indices.search, 'foo')
672
414
        self.assertEqual('foo', error.topic)
673
415
 
674
416
    def test_search_calls_get_topic(self):
675
417
        """Searching should call get_topics in all indexes in order."""
676
418
        calls = []
677
 
 
678
419
        class RecordingIndex(object):
679
420
            def __init__(self, name):
680
421
                self.prefix = name
681
 
 
682
422
            def get_topics(self, topic):
683
423
                calls.append(('get_topics', self.prefix, topic))
684
424
                return ['something']
706
446
            def __init__(self, prefix, search_result):
707
447
                self.prefix = prefix
708
448
                self.result = search_result
709
 
 
710
449
            def get_topics(self, topic):
711
450
                return self.result
712
451
        index = help.HelpIndices()
714
453
        index_two = CannedIndex('2', ['b', 'c'])
715
454
        index.search_path = [index_one, index_two]
716
455
        self.assertEqual([(index_one, 'a'), (index_two, 'b'), (index_two, 'c')],
717
 
                         index.search(None))
 
456
            index.search(None))
718
457
 
719
458
    def test_search_checks_for_duplicate_prefixes(self):
720
459
        """Its an error when there are multiple indices with the same prefix."""
721
460
        indices = help.HelpIndices()
722
461
        indices.search_path = [help_topics.HelpTopicIndex(),
723
 
                               help_topics.HelpTopicIndex()]
 
462
            help_topics.HelpTopicIndex()]
724
463
        self.assertRaises(errors.DuplicateHelpPrefix, indices.search, None)