~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:42:09 UTC
  • mfrom: (5993 +trunk)
  • mto: (5993.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5994.
  • Revision ID: v.ladeuil+lp@free.fr-20110627154209-azubuhbuxsz109hq
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib import (
22
22
    builtins,
23
23
    commands,
24
 
    config,
25
24
    errors,
26
25
    help,
27
26
    help_topics,
45
44
            __doc__ = """A sample command."""
46
45
            _see_also = ['foo', 'bar']
47
46
        self.assertCmdHelp('''\
48
 
Purpose: A sample command.
49
 
Usage:   bzr WithSeeAlso
50
 
 
51
 
Options:
52
 
  --usage        Show usage message and options.
53
 
  -q, --quiet    Only display errors and warnings.
54
 
  -v, --verbose  Display more information.
55
 
  -h, --help     Show help message.
56
 
 
57
 
See also: bar, foo
58
 
''',
 
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
            ''',
59
58
                           cmd_WithSeeAlso())
60
59
 
61
60
    def test_get_help_text(self):
63
62
        class cmd_Demo(commands.Command):
64
63
            __doc__ = """A sample command."""
65
64
        self.assertCmdHelp('''\
66
 
Purpose: A sample command.
67
 
Usage:   bzr Demo
68
 
 
69
 
Options:
70
 
  --usage        Show usage message and options.
71
 
  -q, --quiet    Only display errors and warnings.
72
 
  -v, --verbose  Display more information.
73
 
  -h, --help     Show help message.
74
 
 
75
 
''',
 
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
            ''',
76
75
                           cmd_Demo())
77
76
        cmd = cmd_Demo()
78
77
        helptext = cmd.get_help_text()
90
89
        helptext = cmd.get_help_text(['gam'])
91
90
        self.assertEndsWith(
92
91
            helptext,
 
92
            '  -v, --verbose  Display more information.\n'
93
93
            '  -q, --quiet    Only display errors and warnings.\n'
94
 
            '  -v, --verbose  Display more information.\n'
95
94
            '  -h, --help     Show help message.\n'
96
95
            '\n'
97
96
            'See also: bar, foo, gam\n')
103
102
        helptext = cmd.get_help_text(['gam'])
104
103
        self.assertEndsWith(
105
104
            helptext,
 
105
            '  -v, --verbose  Display more information.\n'
106
106
            '  -q, --quiet    Only display errors and warnings.\n'
107
 
            '  -v, --verbose  Display more information.\n'
108
107
            '  -h, --help     Show help message.\n'
109
108
            '\n'
110
109
            'See also: gam\n')
138
137
            """
139
138
        cmd = cmd_Demo()
140
139
        helptext = cmd.get_help_text()
141
 
        self.assertEqualDiff('''\
142
 
Purpose: A sample command.
143
 
Usage:   bzr Demo
144
 
 
145
 
Options:
146
 
  --usage        Show usage message and options.
147
 
  -q, --quiet    Only display errors and warnings.
148
 
  -v, --verbose  Display more information.
149
 
  -h, --help     Show help message.
150
 
 
151
 
Examples:
152
 
    Example 1:
153
 
 
154
 
        cmd arg1
155
 
 
156
 
    Example 2:
157
 
 
158
 
        cmd arg2
159
 
 
160
 
    A code block follows.
161
 
 
162
 
        bzr Demo something
163
 
 
164
 
''',
165
 
                                         helptext)
 
140
        self.assertEquals(
 
141
            helptext,
 
142
            'Purpose: A sample command.\n'
 
143
            'Usage:   bzr Demo\n'
 
144
            '\n'
 
145
            'Options:\n'
 
146
            '  --usage        Show usage message and options.\n'
 
147
            '  -v, --verbose  Display more information.\n'
 
148
            '  -q, --quiet    Only display errors and warnings.\n'
 
149
            '  -h, --help     Show help message.\n'
 
150
            '\n'
 
151
            'Examples:\n'
 
152
            '    Example 1:\n'
 
153
            '\n'
 
154
            '        cmd arg1\n'
 
155
            '\n'
 
156
            '    Example 2:\n'
 
157
            '\n'
 
158
            '        cmd arg2\n'
 
159
            '\n'
 
160
            '    A code block follows.\n'
 
161
            '\n'
 
162
            '        bzr Demo something\n'
 
163
            '\n')
166
164
        helptext = cmd.get_help_text(plain=False)
167
 
        self.assertEqualDiff('''\
168
 
:Purpose: A sample command.
169
 
:Usage:   bzr Demo
170
 
 
171
 
:Options:
172
 
  --usage        Show usage message and options.
173
 
  -q, --quiet    Only display errors and warnings.
174
 
  -v, --verbose  Display more information.
175
 
  -h, --help     Show help message.
176
 
 
177
 
:Examples:
178
 
    Example 1::
179
 
 
180
 
        cmd arg1
181
 
 
182
 
    Example 2::
183
 
 
184
 
        cmd arg2
185
 
 
186
 
    A code block follows.
187
 
 
188
 
    ::
189
 
 
190
 
        bzr Demo something
191
 
 
192
 
''',
193
 
                             helptext)
 
165
        self.assertEquals(helptext,
 
166
            ':Purpose: A sample command.\n'
 
167
            ':Usage:   bzr Demo\n'
 
168
            '\n'
 
169
            ':Options:\n'
 
170
            '  --usage        Show usage message and options.\n'
 
171
            '  -v, --verbose  Display more information.\n'
 
172
            '  -q, --quiet    Only display errors and warnings.\n'
 
173
            '  -h, --help     Show help message.\n'
 
174
            '\n'
 
175
            ':Examples:\n'
 
176
            '    Example 1::\n'
 
177
            '\n'
 
178
            '        cmd arg1\n'
 
179
            '\n'
 
180
            '    Example 2::\n'
 
181
            '\n'
 
182
            '        cmd arg2\n'
 
183
            '\n'
 
184
            '    A code block follows.\n'
 
185
            '\n'
 
186
            '    ::\n'
 
187
            '\n'
 
188
            '        bzr Demo something\n'
 
189
            '\n')
194
190
 
195
191
    def test_concise_help_text(self):
196
192
        """Concise help text excludes the descriptive sections."""
206
202
            """
207
203
        cmd = cmd_Demo()
208
204
        helptext = cmd.get_help_text()
209
 
        self.assertEqualDiff('''\
210
 
Purpose: A sample command.
211
 
Usage:   bzr Demo
212
 
 
213
 
Options:
214
 
  --usage        Show usage message and options.
215
 
  -q, --quiet    Only display errors and warnings.
216
 
  -v, --verbose  Display more information.
217
 
  -h, --help     Show help message.
218
 
 
219
 
Description:
220
 
  Blah blah blah.
221
 
 
222
 
Examples:
223
 
    Example 1:
224
 
 
225
 
        cmd arg1
226
 
 
227
 
''',
228
 
                             helptext)
 
205
        self.assertEqualDiff(
 
206
            helptext,
 
207
            'Purpose: A sample command.\n'
 
208
            'Usage:   bzr Demo\n'
 
209
            '\n'
 
210
            'Options:\n'
 
211
            '  --usage        Show usage message and options.\n'
 
212
            '  -v, --verbose  Display more information.\n'
 
213
            '  -q, --quiet    Only display errors and warnings.\n'
 
214
            '  -h, --help     Show help message.\n'
 
215
            '\n'
 
216
            'Description:\n'
 
217
            '  Blah blah blah.\n'
 
218
            '\n'
 
219
            'Examples:\n'
 
220
            '    Example 1:\n'
 
221
            '\n'
 
222
            '        cmd arg1\n'
 
223
            '\n')
229
224
        helptext = cmd.get_help_text(verbose=False)
230
 
        self.assertEqualDiff('''\
231
 
Purpose: A sample command.
232
 
Usage:   bzr Demo
233
 
 
234
 
Options:
235
 
  --usage        Show usage message and options.
236
 
  -q, --quiet    Only display errors and warnings.
237
 
  -v, --verbose  Display more information.
238
 
  -h, --help     Show help message.
239
 
 
240
 
See bzr help Demo for more details and examples.
241
 
 
242
 
''',
243
 
                             helptext)
 
225
        self.assertEquals(helptext,
 
226
            'Purpose: A sample command.\n'
 
227
            'Usage:   bzr Demo\n'
 
228
            '\n'
 
229
            'Options:\n'
 
230
            '  --usage        Show usage message and options.\n'
 
231
            '  -v, --verbose  Display more information.\n'
 
232
            '  -q, --quiet    Only display errors and warnings.\n'
 
233
            '  -h, --help     Show help message.\n'
 
234
            '\n'
 
235
            'See bzr help Demo for more details and examples.\n'
 
236
            '\n')
244
237
 
245
238
    def test_help_custom_section_ordering(self):
246
239
        """Custom descriptive sections should remain in the order given."""
247
240
        class cmd_Demo(commands.Command):
248
 
            __doc__ = """\
249
 
A sample command.
250
 
 
251
 
Blah blah blah.
252
 
 
253
 
:Formats:
254
 
  Interesting stuff about formats.
255
 
 
256
 
:Examples:
257
 
  Example 1::
258
 
 
259
 
    cmd arg1
260
 
 
261
 
:Tips:
262
 
  Clever things to keep in mind.
263
 
"""
 
241
            __doc__ = """A sample command.
 
242
 
 
243
            Blah blah blah.
 
244
 
 
245
            :Formats:
 
246
              Interesting stuff about formats.
 
247
 
 
248
            :Examples:
 
249
              Example 1::
 
250
 
 
251
                cmd arg1
 
252
 
 
253
            :Tips:
 
254
              Clever things to keep in mind.
 
255
            """
264
256
        cmd = cmd_Demo()
265
257
        helptext = cmd.get_help_text()
266
 
        self.assertEqualDiff('''\
267
 
Purpose: A sample command.
268
 
Usage:   bzr Demo
269
 
 
270
 
Options:
271
 
  --usage        Show usage message and options.
272
 
  -q, --quiet    Only display errors and warnings.
273
 
  -v, --verbose  Display more information.
274
 
  -h, --help     Show help message.
275
 
 
276
 
Description:
277
 
  Blah blah blah.
278
 
 
279
 
Formats:
280
 
  Interesting stuff about formats.
281
 
 
282
 
Examples:
283
 
  Example 1:
284
 
 
285
 
    cmd arg1
286
 
 
287
 
Tips:
288
 
  Clever things to keep in mind.
289
 
 
290
 
''',
291
 
                             helptext)
 
258
        self.assertEqualDiff(
 
259
            helptext,
 
260
            'Purpose: A sample command.\n'
 
261
            'Usage:   bzr Demo\n'
 
262
            '\n'
 
263
            'Options:\n'
 
264
            '  --usage        Show usage message and options.\n'
 
265
            '  -v, --verbose  Display more information.\n'
 
266
            '  -q, --quiet    Only display errors and warnings.\n'
 
267
            '  -h, --help     Show help message.\n'
 
268
            '\n'
 
269
            'Description:\n'
 
270
            '  Blah blah blah.\n'
 
271
            '\n'
 
272
            'Formats:\n'
 
273
            '  Interesting stuff about formats.\n'
 
274
            '\n'
 
275
            'Examples:\n'
 
276
            '  Example 1:\n'
 
277
            '\n'
 
278
            '    cmd arg1\n'
 
279
            '\n'
 
280
            'Tips:\n'
 
281
            '  Clever things to keep in mind.\n'
 
282
            '\n')
292
283
 
293
284
    def test_help_text_custom_usage(self):
294
285
        """Help text may contain a custom usage section."""
304
295
            """
305
296
        cmd = cmd_Demo()
306
297
        helptext = cmd.get_help_text()
307
 
        self.assertEqualDiff('''\
308
 
Purpose: A sample command.
309
 
Usage:
310
 
    cmd Demo [opts] args
311
 
 
312
 
    cmd Demo -h
313
 
 
314
 
 
315
 
Options:
316
 
  --usage        Show usage message and options.
317
 
  -q, --quiet    Only display errors and warnings.
318
 
  -v, --verbose  Display more information.
319
 
  -h, --help     Show help message.
320
 
 
321
 
Description:
322
 
  Blah blah blah.
323
 
 
324
 
''',
325
 
                             helptext)
 
298
        self.assertEquals(helptext,
 
299
            'Purpose: A sample command.\n'
 
300
            'Usage:\n'
 
301
            '    cmd Demo [opts] args\n'
 
302
            '\n'
 
303
            '    cmd Demo -h\n'
 
304
            '\n'
 
305
            '\n'
 
306
            'Options:\n'
 
307
            '  --usage        Show usage message and options.\n'
 
308
            '  -v, --verbose  Display more information.\n'
 
309
            '  -q, --quiet    Only display errors and warnings.\n'
 
310
            '  -h, --help     Show help message.\n'
 
311
            '\n'
 
312
            'Description:\n'
 
313
            '  Blah blah blah.\n\n')
326
314
 
327
315
 
328
316
class ZzzTranslationsForDoc(ZzzTranslations):
354
342
            __doc__ = """A sample command."""
355
343
            _see_also = ['foo', 'bar']
356
344
        self.assertCmdHelp('''\
357
 
zz{{:Purpose: zz{{A sample command.}}
358
 
}}zz{{:Usage:   bzr WithSeeAlso
359
 
}}
360
 
zz{{:Options:
361
 
  --usage        zz{{Show usage message and options.}}
362
 
  -q, --quiet    zz{{Only display errors and warnings.}}
363
 
  -v, --verbose  zz{{Display more information.}}
364
 
  -h, --help     zz{{Show help message.}}
365
 
}}
366
 
zz{{:See also: bar, foo}}
367
 
''',
 
345
            zz{{:Purpose: zz{{A sample command.}}
 
346
            }}zz{{:Usage:   bzr WithSeeAlso
 
347
            }}
 
348
            zz{{:Options:
 
349
              --usage        Show usage message and options.
 
350
              -v, --verbose  Display more information.
 
351
              -q, --quiet    Only display errors and warnings.
 
352
              -h, --help     Show help message.
 
353
            }}
 
354
            zz{{:See also: bar, foo}}
 
355
            ''',
368
356
                           cmd_WithSeeAlso())
369
357
 
370
358
    def test_get_help_text(self):
372
360
        class cmd_Demo(commands.Command):
373
361
            __doc__ = """A sample command."""
374
362
        self.assertCmdHelp('''\
375
 
zz{{:Purpose: zz{{A sample command.}}
376
 
}}zz{{:Usage:   bzr Demo
377
 
}}
378
 
zz{{:Options:
379
 
  --usage        zz{{Show usage message and options.}}
380
 
  -q, --quiet    zz{{Only display errors and warnings.}}
381
 
  -v, --verbose  zz{{Display more information.}}
382
 
  -h, --help     zz{{Show help message.}}
383
 
}}
384
 
''',
 
363
            zz{{:Purpose: zz{{A sample command.}}
 
364
            }}zz{{:Usage:   bzr Demo
 
365
            }}
 
366
            zz{{:Options:
 
367
              --usage        Show usage message and options.
 
368
              -v, --verbose  Display more information.
 
369
              -q, --quiet    Only display errors and warnings.
 
370
              -h, --help     Show help message.
 
371
            }}
 
372
            ''',
385
373
                           cmd_Demo())
386
374
 
387
375
    def test_command_with_additional_see_also(self):
391
379
        cmd = cmd_WithSeeAlso()
392
380
        helptext = cmd.get_help_text(['gam'])
393
381
        self.assertEndsWith(
394
 
            helptext,'''\
395
 
  -q, --quiet    zz{{Only display errors and warnings.}}
396
 
  -v, --verbose  zz{{Display more information.}}
397
 
  -h, --help     zz{{Show help message.}}
398
 
}}
399
 
zz{{:See also: bar, foo, gam}}
400
 
''')
 
382
            helptext,
 
383
            '  -v, --verbose  Display more information.\n'
 
384
            '  -q, --quiet    Only display errors and warnings.\n'
 
385
            '  -h, --help     Show help message.\n'
 
386
            '}}\n'
 
387
            'zz{{:See also: bar, foo, gam}}\n')
401
388
 
402
389
    def test_command_only_additional_see_also(self):
403
390
        class cmd_WithSeeAlso(commands.Command):
405
392
        cmd = cmd_WithSeeAlso()
406
393
        helptext = cmd.get_help_text(['gam'])
407
394
        self.assertEndsWith(
408
 
            helptext, '''\
409
 
zz{{:Options:
410
 
  --usage        zz{{Show usage message and options.}}
411
 
  -q, --quiet    zz{{Only display errors and warnings.}}
412
 
  -v, --verbose  zz{{Display more information.}}
413
 
  -h, --help     zz{{Show help message.}}
414
 
}}
415
 
zz{{:See also: gam}}
416
 
''')
 
395
            helptext,
 
396
            'zz{{:Options:\n'
 
397
            '  --usage        Show usage message and options.\n'
 
398
            '  -v, --verbose  Display more information.\n'
 
399
            '  -q, --quiet    Only display errors and warnings.\n'
 
400
            '  -h, --help     Show help message.\n'
 
401
            '}}\n'
 
402
            'zz{{:See also: gam}}\n')
417
403
 
418
404
 
419
405
    def test_help_custom_section_ordering(self):
436
422
              Clever things to keep in mind.
437
423
            """
438
424
        self.assertCmdHelp('''\
439
 
zz{{:Purpose: zz{{A sample command.}}
440
 
}}zz{{:Usage:   bzr Demo
441
 
}}
442
 
zz{{:Options:
443
 
  --usage        zz{{Show usage message and options.}}
444
 
  -q, --quiet    zz{{Only display errors and warnings.}}
445
 
  -v, --verbose  zz{{Display more information.}}
446
 
  -h, --help     zz{{Show help message.}}
447
 
}}
448
 
Description:
449
 
  zz{{zz{{Blah blah blah.}}
450
 
 
451
 
}}:Formats:
452
 
  zz{{Interesting stuff about formats.}}
453
 
 
454
 
Examples:
455
 
  zz{{Example 1::}}
456
 
 
457
 
    zz{{cmd arg1}}
458
 
 
459
 
Tips:
460
 
  zz{{Clever things to keep in mind.}}
461
 
 
462
 
''',
 
425
            zz{{:Purpose: zz{{A sample command.}}
 
426
            }}zz{{:Usage:   bzr Demo
 
427
            }}
 
428
            zz{{:Options:
 
429
              --usage        Show usage message and options.
 
430
              -v, --verbose  Display more information.
 
431
              -q, --quiet    Only display errors and warnings.
 
432
              -h, --help     Show help message.
 
433
            }}
 
434
            Description:
 
435
              zz{{zz{{Blah blah blah.}}
 
436
            
 
437
            }}:Formats:
 
438
              zz{{Interesting stuff about formats.}}
 
439
            
 
440
            Examples:
 
441
              zz{{Example 1::}}
 
442
            
 
443
                zz{{cmd arg1}}
 
444
            
 
445
            Tips:
 
446
              zz{{Clever things to keep in mind.}}
 
447
 
 
448
            ''',
463
449
                           cmd_Demo())
464
450
 
465
451
    def test_help_text_custom_usage(self):
475
461
            Blah blah blah.
476
462
            """
477
463
        self.assertCmdHelp('''\
478
 
zz{{:Purpose: zz{{A sample command.}}
479
 
}}zz{{:Usage:
480
 
    zz{{cmd Demo [opts] args}}
481
 
 
482
 
    zz{{cmd Demo -h}}
483
 
 
484
 
}}
485
 
zz{{:Options:
486
 
  --usage        zz{{Show usage message and options.}}
487
 
  -q, --quiet    zz{{Only display errors and warnings.}}
488
 
  -v, --verbose  zz{{Display more information.}}
489
 
  -h, --help     zz{{Show help message.}}
490
 
}}
491
 
Description:
492
 
  zz{{zz{{Blah blah blah.}}
493
 
 
494
 
}}
495
 
''',
 
464
            zz{{:Purpose: zz{{A sample command.}}
 
465
            }}zz{{:Usage:
 
466
                zz{{cmd Demo [opts] args}}
 
467
            
 
468
                zz{{cmd Demo -h}}
 
469
 
 
470
            }}
 
471
            zz{{:Options:
 
472
              --usage        Show usage message and options.
 
473
              -v, --verbose  Display more information.
 
474
              -q, --quiet    Only display errors and warnings.
 
475
              -h, --help     Show help message.
 
476
            }}
 
477
            Description:
 
478
              zz{{zz{{Blah blah blah.}}
 
479
 
 
480
            }}
 
481
            ''',
496
482
                           cmd_Demo())
497
483
 
498
484
 
575
561
        self.assertEqual('', index.prefix)
576
562
 
577
563
 
578
 
class TestConfigOptionIndex(TestHelp):
579
 
    """Tests for the HelpCommandIndex class."""
580
 
 
581
 
    def setUp(self):
582
 
        super(TestConfigOptionIndex, self).setUp()
583
 
        self.index = help_topics.ConfigOptionHelpIndex()
584
 
 
585
 
    def test_get_topics_None(self):
586
 
        """Searching for None returns an empty list."""
587
 
        self.assertEqual([], self.index.get_topics(None))
588
 
 
589
 
    def test_get_topics_no_topic(self):
590
 
        self.assertEqual([], self.index.get_topics('nothing by this name'))
591
 
 
592
 
    def test_prefix(self):
593
 
        self.assertEqual('configuration/', self.index.prefix)
594
 
 
595
 
    def test_get_topic_with_prefix(self):
596
 
        topics = self.index.get_topics('configuration/default_format')
597
 
        self.assertLength(1, topics)
598
 
        opt = topics[0]
599
 
        self.assertIsInstance(opt, config.Option)
600
 
        self.assertEquals('default_format', opt.name)
601
 
 
602
 
 
603
564
class TestCommandIndex(TestHelp):
604
565
    """Tests for the HelpCommandIndex class."""
605
566
 
642
603
    def test_default_search_path(self):
643
604
        """The default search path should include internal indexs."""
644
605
        indices = help.HelpIndices()
645
 
        self.assertEqual(4, len(indices.search_path))
 
606
        self.assertEqual(3, len(indices.search_path))
646
607
        # help topics should be searched in first.
647
608
        self.assertIsInstance(indices.search_path[0],
648
 
                              help_topics.HelpTopicIndex)
 
609
            help_topics.HelpTopicIndex)
649
610
        # with commands being search second.
650
611
        self.assertIsInstance(indices.search_path[1],
651
 
                              commands.HelpCommandIndex)
652
 
        # plugins are a third index.
 
612
            commands.HelpCommandIndex)
 
613
        # and plugins are a third index.
653
614
        self.assertIsInstance(indices.search_path[2],
654
 
                              plugin.PluginsHelpIndex)
655
 
        # config options are a fourth index
656
 
        self.assertIsInstance(indices.search_path[3],
657
 
                              help_topics.ConfigOptionHelpIndex)
 
615
            plugin.PluginsHelpIndex)
658
616
 
659
617
    def test_search_for_unknown_topic_raises(self):
660
618
        """Searching for an unknown topic should raise NoHelpTopic."""