/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 breezy/tests/test_help.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
    def test_no_help_topic(self):
40
40
        error = help.NoHelpTopic("topic")
41
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))
 
42
                             "Please use 'brz help topics' to obtain a list of topics.",
 
43
                             str(error))
44
44
 
45
45
 
46
46
class TestCommandHelp(tests.TestCase):
58
58
Usage:   brz WithSeeAlso
59
59
 
60
60
Options:
 
61
  -h, --help     Show help message.
 
62
  -q, --quiet    Only display errors and warnings.
61
63
  --usage        Show usage message and options.
62
 
  -q, --quiet    Only display errors and warnings.
63
64
  -v, --verbose  Display more information.
64
 
  -h, --help     Show help message.
65
65
 
66
66
See also: bar, foo
67
67
''',
76
76
Usage:   brz Demo
77
77
 
78
78
Options:
 
79
  -h, --help     Show help message.
 
80
  -q, --quiet    Only display errors and warnings.
79
81
  --usage        Show usage message and options.
80
 
  -q, --quiet    Only display errors and warnings.
81
82
  -v, --verbose  Display more information.
82
 
  -h, --help     Show help message.
83
83
 
84
84
''',
85
85
                           cmd_Demo())
86
86
        cmd = cmd_Demo()
87
87
        helptext = cmd.get_help_text()
88
88
        self.assertStartsWith(helptext,
89
 
            'Purpose: A sample command.\n'
90
 
            'Usage:   brz Demo')
 
89
                              'Purpose: A sample command.\n'
 
90
                              'Usage:   brz Demo')
91
91
        self.assertEndsWith(helptext,
92
 
            '  -h, --help     Show help message.\n\n')
 
92
                            '  -v, --verbose  Display more information.\n\n')
93
93
 
94
94
    def test_command_with_additional_see_also(self):
95
95
        class cmd_WithSeeAlso(commands.Command):
99
99
        helptext = cmd.get_help_text(['gam'])
100
100
        self.assertEndsWith(
101
101
            helptext,
 
102
            '  -h, --help     Show help message.\n'
102
103
            '  -q, --quiet    Only display errors and warnings.\n'
 
104
            '  --usage        Show usage message and options.\n'
103
105
            '  -v, --verbose  Display more information.\n'
104
 
            '  -h, --help     Show help message.\n'
105
106
            '\n'
106
107
            'See also: bar, foo, gam\n')
107
108
 
112
113
        helptext = cmd.get_help_text(['gam'])
113
114
        self.assertEndsWith(
114
115
            helptext,
115
 
            '  -q, --quiet    Only display errors and warnings.\n'
116
116
            '  -v, --verbose  Display more information.\n'
117
 
            '  -h, --help     Show help message.\n'
118
117
            '\n'
119
118
            'See also: gam\n')
120
119
 
152
151
Usage:   brz Demo
153
152
 
154
153
Options:
 
154
  -h, --help     Show help message.
 
155
  -q, --quiet    Only display errors and warnings.
155
156
  --usage        Show usage message and options.
156
 
  -q, --quiet    Only display errors and warnings.
157
157
  -v, --verbose  Display more information.
158
 
  -h, --help     Show help message.
159
158
 
160
159
Examples:
161
160
    Example 1:
171
170
        brz Demo something
172
171
 
173
172
''',
174
 
                                         helptext)
 
173
                             helptext)
175
174
        helptext = cmd.get_help_text(plain=False)
176
175
        self.assertEqualDiff('''\
177
176
:Purpose: A sample command.
178
177
:Usage:   brz Demo
179
178
 
180
179
:Options:
 
180
  -h, --help     Show help message.
 
181
  -q, --quiet    Only display errors and warnings.
181
182
  --usage        Show usage message and options.
182
 
  -q, --quiet    Only display errors and warnings.
183
183
  -v, --verbose  Display more information.
184
 
  -h, --help     Show help message.
185
184
 
186
185
:Examples:
187
186
    Example 1::
205
204
        """Concise help text excludes the descriptive sections."""
206
205
        class cmd_Demo(commands.Command):
207
206
            __doc__ = """A sample command.
208
 
 
 
207
 
209
208
            Blah blah blah.
210
209
 
211
210
            :Examples:
212
211
                Example 1::
213
 
 
 
212
 
214
213
                    cmd arg1
215
214
            """
216
215
        cmd = cmd_Demo()
220
219
Usage:   brz Demo
221
220
 
222
221
Options:
 
222
  -h, --help     Show help message.
 
223
  -q, --quiet    Only display errors and warnings.
223
224
  --usage        Show usage message and options.
224
 
  -q, --quiet    Only display errors and warnings.
225
225
  -v, --verbose  Display more information.
226
 
  -h, --help     Show help message.
227
226
 
228
227
Description:
229
228
  Blah blah blah.
241
240
Usage:   brz Demo
242
241
 
243
242
Options:
 
243
  -h, --help     Show help message.
 
244
  -q, --quiet    Only display errors and warnings.
244
245
  --usage        Show usage message and options.
245
 
  -q, --quiet    Only display errors and warnings.
246
246
  -v, --verbose  Display more information.
247
 
  -h, --help     Show help message.
248
247
 
249
248
See brz help Demo for more details and examples.
250
249
 
277
276
Usage:   brz Demo
278
277
 
279
278
Options:
 
279
  -h, --help     Show help message.
 
280
  -q, --quiet    Only display errors and warnings.
280
281
  --usage        Show usage message and options.
281
 
  -q, --quiet    Only display errors and warnings.
282
282
  -v, --verbose  Display more information.
283
 
  -h, --help     Show help message.
284
283
 
285
284
Description:
286
285
  Blah blah blah.
322
321
 
323
322
 
324
323
Options:
 
324
  -h, --help     Show help message.
 
325
  -q, --quiet    Only display errors and warnings.
325
326
  --usage        Show usage message and options.
326
 
  -q, --quiet    Only display errors and warnings.
327
327
  -v, --verbose  Display more information.
328
 
  -h, --help     Show help message.
329
328
 
330
329
Description:
331
330
  Blah blah blah.
367
366
}}zz{{:Usage:   brz WithSeeAlso
368
367
}}
369
368
zz{{:Options:
 
369
  -h, --help     zz{{Show help message.}}
 
370
  -q, --quiet    zz{{Only display errors and warnings.}}
370
371
  --usage        zz{{Show usage message and options.}}
371
 
  -q, --quiet    zz{{Only display errors and warnings.}}
372
372
  -v, --verbose  zz{{Display more information.}}
373
 
  -h, --help     zz{{Show help message.}}
374
373
}}
375
374
zz{{:See also: bar, foo}}
376
375
''',
385
384
}}zz{{:Usage:   brz Demo
386
385
}}
387
386
zz{{:Options:
 
387
  -h, --help     zz{{Show help message.}}
 
388
  -q, --quiet    zz{{Only display errors and warnings.}}
388
389
  --usage        zz{{Show usage message and options.}}
389
 
  -q, --quiet    zz{{Only display errors and warnings.}}
390
390
  -v, --verbose  zz{{Display more information.}}
391
 
  -h, --help     zz{{Show help message.}}
392
391
}}
393
392
''',
394
393
                           cmd_Demo())
401
400
        helptext = cmd.get_help_text(['gam'])
402
401
        self.assertEndsWith(
403
402
            helptext, '''\
 
403
  -h, --help     zz{{Show help message.}}
404
404
  -q, --quiet    zz{{Only display errors and warnings.}}
 
405
  --usage        zz{{Show usage message and options.}}
405
406
  -v, --verbose  zz{{Display more information.}}
406
 
  -h, --help     zz{{Show help message.}}
407
407
}}
408
408
zz{{:See also: bar, foo, gam}}
409
409
''')
416
416
        self.assertEndsWith(
417
417
            helptext, '''\
418
418
zz{{:Options:
 
419
  -h, --help     zz{{Show help message.}}
 
420
  -q, --quiet    zz{{Only display errors and warnings.}}
419
421
  --usage        zz{{Show usage message and options.}}
420
 
  -q, --quiet    zz{{Only display errors and warnings.}}
421
422
  -v, --verbose  zz{{Display more information.}}
422
 
  -h, --help     zz{{Show help message.}}
423
423
}}
424
424
zz{{:See also: gam}}
425
425
''')
426
426
 
427
 
 
428
427
    def test_help_custom_section_ordering(self):
429
428
        """Custom descriptive sections should remain in the order given."""
430
429
        # The help formatter expect the class name to start with 'cmd_'
431
430
        class cmd_Demo(commands.Command):
432
431
            __doc__ = """A sample command.
433
 
 
 
432
 
434
433
            Blah blah blah.
435
434
 
436
435
            :Formats:
438
437
 
439
438
            :Examples:
440
439
              Example 1::
441
 
 
 
440
 
442
441
                cmd arg1
443
442
 
444
443
            :Tips:
449
448
}}zz{{:Usage:   brz Demo
450
449
}}
451
450
zz{{:Options:
 
451
  -h, --help     zz{{Show help message.}}
 
452
  -q, --quiet    zz{{Only display errors and warnings.}}
452
453
  --usage        zz{{Show usage message and options.}}
453
 
  -q, --quiet    zz{{Only display errors and warnings.}}
454
454
  -v, --verbose  zz{{Display more information.}}
455
 
  -h, --help     zz{{Show help message.}}
456
455
}}
457
456
Description:
458
457
  zz{{zz{{Blah blah blah.}}
459
 
 
 
458
 
460
459
}}:Formats:
461
460
  zz{{Interesting stuff about formats.}}
462
 
 
 
461
 
463
462
Examples:
464
463
  zz{{Example 1::}}
465
 
 
 
464
 
466
465
    zz{{cmd arg1}}
467
 
 
 
466
 
468
467
Tips:
469
468
  zz{{Clever things to keep in mind.}}
470
 
 
 
469
 
471
470
''',
472
471
                           cmd_Demo())
473
472
 
492
491
 
493
492
}}
494
493
zz{{:Options:
 
494
  -h, --help     zz{{Show help message.}}
 
495
  -q, --quiet    zz{{Only display errors and warnings.}}
495
496
  --usage        zz{{Show usage message and options.}}
496
 
  -q, --quiet    zz{{Only display errors and warnings.}}
497
497
  -v, --verbose  zz{{Display more information.}}
498
 
  -h, --help     zz{{Show help message.}}
499
498
}}
500
499
Description:
501
500
  zz{{zz{{Blah blah blah.}}
539
538
        # Pick a known topic stored in an external file
540
539
        topic = help_topics.RegisteredTopic('authentication')
541
540
        self.assertStartsWith(topic.get_help_text(),
542
 
            'Authentication Settings\n'
543
 
            '=======================\n'
544
 
            '\n')
 
541
                              'Authentication Settings\n'
 
542
                              '=======================\n'
 
543
                              '\n')
545
544
 
546
545
    def test_get_help_topic(self):
547
546
        """The help topic for RegisteredTopic is its topic from construction."""
675
674
    def test_search_calls_get_topic(self):
676
675
        """Searching should call get_topics in all indexes in order."""
677
676
        calls = []
 
677
 
678
678
        class RecordingIndex(object):
679
679
            def __init__(self, name):
680
680
                self.prefix = name
 
681
 
681
682
            def get_topics(self, topic):
682
683
                calls.append(('get_topics', self.prefix, topic))
683
684
                return ['something']
705
706
            def __init__(self, prefix, search_result):
706
707
                self.prefix = prefix
707
708
                self.result = search_result
 
709
 
708
710
            def get_topics(self, topic):
709
711
                return self.result
710
712
        index = help.HelpIndices()
712
714
        index_two = CannedIndex('2', ['b', 'c'])
713
715
        index.search_path = [index_one, index_two]
714
716
        self.assertEqual([(index_one, 'a'), (index_two, 'b'), (index_two, 'c')],
715
 
            index.search(None))
 
717
                         index.search(None))
716
718
 
717
719
    def test_search_checks_for_duplicate_prefixes(self):
718
720
        """Its an error when there are multiple indices with the same prefix."""
719
721
        indices = help.HelpIndices()
720
722
        indices.search_path = [help_topics.HelpTopicIndex(),
721
 
            help_topics.HelpTopicIndex()]
 
723
                               help_topics.HelpTopicIndex()]
722
724
        self.assertRaises(errors.DuplicateHelpPrefix, indices.search, None)