44
45
__doc__ = """A sample command."""
45
46
_see_also = ['foo', 'bar']
46
47
self.assertCmdHelp('''\
47
Purpose: A sample command.
48
Usage: bzr WithSeeAlso
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.
48
Purpose: A sample command.
49
Usage: bzr WithSeeAlso
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.
60
61
def test_get_help_text(self):
62
63
class cmd_Demo(commands.Command):
63
64
__doc__ = """A sample command."""
64
65
self.assertCmdHelp('''\
65
Purpose: A sample command.
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.
66
Purpose: A sample command.
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.
77
78
helptext = cmd.get_help_text()
139
140
helptext = cmd.get_help_text()
142
'Purpose: A sample command.\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'
160
' A code block follows.\n'
162
' bzr Demo something\n'
141
self.assertEqualDiff('''\
142
Purpose: A sample command.
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.
160
A code block follows.
164
166
helptext = cmd.get_help_text(plain=False)
165
self.assertEquals(helptext,
166
':Purpose: A sample command.\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'
184
' A code block follows.\n'
188
' bzr Demo something\n'
167
self.assertEqualDiff('''\
168
:Purpose: A sample command.
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.
186
A code block follows.
191
195
def test_concise_help_text(self):
192
196
"""Concise help text excludes the descriptive sections."""
204
208
helptext = cmd.get_help_text()
205
self.assertEqualDiff(
207
'Purpose: A sample command.\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'
209
self.assertEqualDiff('''\
210
Purpose: A sample command.
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.
224
229
helptext = cmd.get_help_text(verbose=False)
225
self.assertEquals(helptext,
226
'Purpose: A sample command.\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'
235
'See bzr help Demo for more details and examples.\n'
230
self.assertEqualDiff('''\
231
Purpose: A sample command.
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.
240
See bzr help Demo for more details and examples.
238
245
def test_help_custom_section_ordering(self):
239
246
"""Custom descriptive sections should remain in the order given."""
240
247
class cmd_Demo(commands.Command):
241
__doc__ = """A sample command.
246
Interesting stuff about formats.
254
Clever things to keep in mind.
254
Interesting stuff about formats.
262
Clever things to keep in mind.
257
265
helptext = cmd.get_help_text()
258
self.assertEqualDiff(
260
'Purpose: A sample command.\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'
273
' Interesting stuff about formats.\n'
281
' Clever things to keep in mind.\n'
266
self.assertEqualDiff('''\
267
Purpose: A sample command.
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.
280
Interesting stuff about formats.
288
Clever things to keep in mind.
284
293
def test_help_text_custom_usage(self):
285
294
"""Help text may contain a custom usage section."""
297
306
helptext = cmd.get_help_text()
298
self.assertEquals(helptext,
299
'Purpose: A sample command.\n'
301
' cmd Demo [opts] args\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'
313
' Blah blah blah.\n\n')
307
self.assertEqualDiff('''\
308
Purpose: A sample command.
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.
316
328
class ZzzTranslationsForDoc(ZzzTranslations):
342
354
__doc__ = """A sample command."""
343
355
_see_also = ['foo', 'bar']
344
356
self.assertCmdHelp('''\
345
zz{{:Purpose: zz{{A sample command.}}
346
}}zz{{:Usage: bzr WithSeeAlso
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.
354
zz{{:See also: bar, foo}}
357
zz{{:Purpose: zz{{A sample command.}}
358
}}zz{{:Usage: bzr WithSeeAlso
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.}}
366
zz{{:See also: bar, foo}}
356
368
cmd_WithSeeAlso())
358
370
def test_get_help_text(self):
360
372
class cmd_Demo(commands.Command):
361
373
__doc__ = """A sample command."""
362
374
self.assertCmdHelp('''\
363
zz{{:Purpose: zz{{A sample command.}}
364
}}zz{{:Usage: bzr Demo
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.
375
zz{{:Purpose: zz{{A sample command.}}
376
}}zz{{:Usage: bzr Demo
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.}}
375
387
def test_command_with_additional_see_also(self):
379
391
cmd = cmd_WithSeeAlso()
380
392
helptext = cmd.get_help_text(['gam'])
381
393
self.assertEndsWith(
383
' -v, --verbose Display more information.\n'
384
' -q, --quiet Only display errors and warnings.\n'
385
' -h, --help Show help message.\n'
387
'zz{{:See also: bar, foo, gam}}\n')
395
-q, --quiet zz{{Only display errors and warnings.}}
396
-v, --verbose zz{{Display more information.}}
397
-h, --help zz{{Show help message.}}
399
zz{{:See also: bar, foo, gam}}
389
402
def test_command_only_additional_see_also(self):
390
403
class cmd_WithSeeAlso(commands.Command):
392
405
cmd = cmd_WithSeeAlso()
393
406
helptext = cmd.get_help_text(['gam'])
394
407
self.assertEndsWith(
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'
402
'zz{{:See also: gam}}\n')
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.}}
405
419
def test_help_custom_section_ordering(self):
422
436
Clever things to keep in mind.
424
438
self.assertCmdHelp('''\
425
zz{{:Purpose: zz{{A sample command.}}
426
}}zz{{:Usage: bzr Demo
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.
435
zz{{zz{{Blah blah blah.}}
438
zz{{Interesting stuff about formats.}}
446
zz{{Clever things to keep in mind.}}
439
zz{{:Purpose: zz{{A sample command.}}
440
}}zz{{:Usage: bzr Demo
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.}}
449
zz{{zz{{Blah blah blah.}}
452
zz{{Interesting stuff about formats.}}
460
zz{{Clever things to keep in mind.}}
451
465
def test_help_text_custom_usage(self):
463
477
self.assertCmdHelp('''\
464
zz{{:Purpose: zz{{A sample command.}}
466
zz{{cmd Demo [opts] args}}
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.
478
zz{{zz{{Blah blah blah.}}
478
zz{{:Purpose: zz{{A sample command.}}
480
zz{{cmd Demo [opts] args}}
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.}}
492
zz{{zz{{Blah blah blah.}}
561
575
self.assertEqual('', index.prefix)
578
class TestConfigOptionIndex(TestHelp):
579
"""Tests for the HelpCommandIndex class."""
582
super(TestConfigOptionIndex, self).setUp()
583
self.index = help_topics.ConfigOptionHelpIndex()
585
def test_get_topics_None(self):
586
"""Searching for None returns an empty list."""
587
self.assertEqual([], self.index.get_topics(None))
589
def test_get_topics_no_topic(self):
590
self.assertEqual([], self.index.get_topics('nothing by this name'))
592
def test_prefix(self):
593
self.assertEqual('configuration/', self.index.prefix)
595
def test_get_topic_with_prefix(self):
596
topics = self.index.get_topics('configuration/default_format')
597
self.assertLength(1, topics)
599
self.assertIsInstance(opt, config.Option)
600
self.assertEquals('default_format', opt.name)
564
603
class TestCommandIndex(TestHelp):
565
604
"""Tests for the HelpCommandIndex class."""
603
642
def test_default_search_path(self):
604
643
"""The default search path should include internal indexs."""
605
644
indices = help.HelpIndices()
606
self.assertEqual(3, len(indices.search_path))
645
self.assertEqual(4, len(indices.search_path))
607
646
# help topics should be searched in first.
608
647
self.assertIsInstance(indices.search_path[0],
609
help_topics.HelpTopicIndex)
648
help_topics.HelpTopicIndex)
610
649
# with commands being search second.
611
650
self.assertIsInstance(indices.search_path[1],
612
commands.HelpCommandIndex)
613
# and plugins are a third index.
651
commands.HelpCommandIndex)
652
# plugins are a third index.
614
653
self.assertIsInstance(indices.search_path[2],
615
plugin.PluginsHelpIndex)
654
plugin.PluginsHelpIndex)
655
# config options are a fourth index
656
self.assertIsInstance(indices.search_path[3],
657
help_topics.ConfigOptionHelpIndex)
617
659
def test_search_for_unknown_topic_raises(self):
618
660
"""Searching for an unknown topic should raise NoHelpTopic."""