/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: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

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