/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-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

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):
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))
44
 
 
45
 
 
46
37
class TestCommandHelp(tests.TestCase):
47
38
    """Tests for help on commands."""
48
39
 
58
49
Usage:   brz WithSeeAlso
59
50
 
60
51
Options:
61
 
  -h, --help     Show help message.
 
52
  --usage        Show usage message and options.
62
53
  -q, --quiet    Only display errors and warnings.
63
 
  --usage        Show usage message and options.
64
54
  -v, --verbose  Display more information.
 
55
  -h, --help     Show help message.
65
56
 
66
57
See also: bar, foo
67
58
''',
76
67
Usage:   brz Demo
77
68
 
78
69
Options:
79
 
  -h, --help     Show help message.
 
70
  --usage        Show usage message and options.
80
71
  -q, --quiet    Only display errors and warnings.
81
 
  --usage        Show usage message and options.
82
72
  -v, --verbose  Display more information.
 
73
  -h, --help     Show help message.
83
74
 
84
75
''',
85
76
                           cmd_Demo())
86
77
        cmd = cmd_Demo()
87
78
        helptext = cmd.get_help_text()
88
79
        self.assertStartsWith(helptext,
89
 
                              'Purpose: A sample command.\n'
90
 
                              'Usage:   brz Demo')
 
80
            'Purpose: A sample command.\n'
 
81
            'Usage:   brz Demo')
91
82
        self.assertEndsWith(helptext,
92
 
                            '  -v, --verbose  Display more information.\n\n')
 
83
            '  -h, --help     Show help message.\n\n')
93
84
 
94
85
    def test_command_with_additional_see_also(self):
95
86
        class cmd_WithSeeAlso(commands.Command):
99
90
        helptext = cmd.get_help_text(['gam'])
100
91
        self.assertEndsWith(
101
92
            helptext,
102
 
            '  -h, --help     Show help message.\n'
103
93
            '  -q, --quiet    Only display errors and warnings.\n'
104
 
            '  --usage        Show usage message and options.\n'
105
94
            '  -v, --verbose  Display more information.\n'
 
95
            '  -h, --help     Show help message.\n'
106
96
            '\n'
107
97
            'See also: bar, foo, gam\n')
108
98
 
113
103
        helptext = cmd.get_help_text(['gam'])
114
104
        self.assertEndsWith(
115
105
            helptext,
 
106
            '  -q, --quiet    Only display errors and warnings.\n'
116
107
            '  -v, --verbose  Display more information.\n'
 
108
            '  -h, --help     Show help message.\n'
117
109
            '\n'
118
110
            'See also: gam\n')
119
111
 
151
143
Usage:   brz Demo
152
144
 
153
145
Options:
154
 
  -h, --help     Show help message.
 
146
  --usage        Show usage message and options.
155
147
  -q, --quiet    Only display errors and warnings.
156
 
  --usage        Show usage message and options.
157
148
  -v, --verbose  Display more information.
 
149
  -h, --help     Show help message.
158
150
 
159
151
Examples:
160
152
    Example 1:
170
162
        brz Demo something
171
163
 
172
164
''',
173
 
                             helptext)
 
165
                                         helptext)
174
166
        helptext = cmd.get_help_text(plain=False)
175
167
        self.assertEqualDiff('''\
176
168
:Purpose: A sample command.
177
169
:Usage:   brz Demo
178
170
 
179
171
:Options:
180
 
  -h, --help     Show help message.
 
172
  --usage        Show usage message and options.
181
173
  -q, --quiet    Only display errors and warnings.
182
 
  --usage        Show usage message and options.
183
174
  -v, --verbose  Display more information.
 
175
  -h, --help     Show help message.
184
176
 
185
177
:Examples:
186
178
    Example 1::
204
196
        """Concise help text excludes the descriptive sections."""
205
197
        class cmd_Demo(commands.Command):
206
198
            __doc__ = """A sample command.
207
 
 
 
199
 
208
200
            Blah blah blah.
209
201
 
210
202
            :Examples:
211
203
                Example 1::
212
 
 
 
204
 
213
205
                    cmd arg1
214
206
            """
215
207
        cmd = cmd_Demo()
219
211
Usage:   brz Demo
220
212
 
221
213
Options:
222
 
  -h, --help     Show help message.
 
214
  --usage        Show usage message and options.
223
215
  -q, --quiet    Only display errors and warnings.
224
 
  --usage        Show usage message and options.
225
216
  -v, --verbose  Display more information.
 
217
  -h, --help     Show help message.
226
218
 
227
219
Description:
228
220
  Blah blah blah.
240
232
Usage:   brz Demo
241
233
 
242
234
Options:
243
 
  -h, --help     Show help message.
 
235
  --usage        Show usage message and options.
244
236
  -q, --quiet    Only display errors and warnings.
245
 
  --usage        Show usage message and options.
246
237
  -v, --verbose  Display more information.
 
238
  -h, --help     Show help message.
247
239
 
248
240
See brz help Demo for more details and examples.
249
241
 
276
268
Usage:   brz Demo
277
269
 
278
270
Options:
279
 
  -h, --help     Show help message.
 
271
  --usage        Show usage message and options.
280
272
  -q, --quiet    Only display errors and warnings.
281
 
  --usage        Show usage message and options.
282
273
  -v, --verbose  Display more information.
 
274
  -h, --help     Show help message.
283
275
 
284
276
Description:
285
277
  Blah blah blah.
321
313
 
322
314
 
323
315
Options:
324
 
  -h, --help     Show help message.
 
316
  --usage        Show usage message and options.
325
317
  -q, --quiet    Only display errors and warnings.
326
 
  --usage        Show usage message and options.
327
318
  -v, --verbose  Display more information.
 
319
  -h, --help     Show help message.
328
320
 
329
321
Description:
330
322
  Blah blah blah.
335
327
 
336
328
class ZzzTranslationsForDoc(ZzzTranslations):
337
329
 
338
 
    _section_pat = re.compile(':\\w+:\\n\\s+')
 
330
    _section_pat = re.compile(':\w+:\\n\\s+')
339
331
    _indent_pat = re.compile('\\s+')
340
332
 
341
333
    def zzz(self, s):
366
358
}}zz{{:Usage:   brz WithSeeAlso
367
359
}}
368
360
zz{{:Options:
369
 
  -h, --help     zz{{Show help message.}}
 
361
  --usage        zz{{Show usage message and options.}}
370
362
  -q, --quiet    zz{{Only display errors and warnings.}}
371
 
  --usage        zz{{Show usage message and options.}}
372
363
  -v, --verbose  zz{{Display more information.}}
 
364
  -h, --help     zz{{Show help message.}}
373
365
}}
374
366
zz{{:See also: bar, foo}}
375
367
''',
384
376
}}zz{{:Usage:   brz Demo
385
377
}}
386
378
zz{{:Options:
387
 
  -h, --help     zz{{Show help message.}}
 
379
  --usage        zz{{Show usage message and options.}}
388
380
  -q, --quiet    zz{{Only display errors and warnings.}}
389
 
  --usage        zz{{Show usage message and options.}}
390
381
  -v, --verbose  zz{{Display more information.}}
 
382
  -h, --help     zz{{Show help message.}}
391
383
}}
392
384
''',
393
385
                           cmd_Demo())
399
391
        cmd = cmd_WithSeeAlso()
400
392
        helptext = cmd.get_help_text(['gam'])
401
393
        self.assertEndsWith(
402
 
            helptext, '''\
403
 
  -h, --help     zz{{Show help message.}}
 
394
            helptext,'''\
404
395
  -q, --quiet    zz{{Only display errors and warnings.}}
405
 
  --usage        zz{{Show usage message and options.}}
406
396
  -v, --verbose  zz{{Display more information.}}
 
397
  -h, --help     zz{{Show help message.}}
407
398
}}
408
399
zz{{:See also: bar, foo, gam}}
409
400
''')
416
407
        self.assertEndsWith(
417
408
            helptext, '''\
418
409
zz{{:Options:
419
 
  -h, --help     zz{{Show help message.}}
 
410
  --usage        zz{{Show usage message and options.}}
420
411
  -q, --quiet    zz{{Only display errors and warnings.}}
421
 
  --usage        zz{{Show usage message and options.}}
422
412
  -v, --verbose  zz{{Display more information.}}
 
413
  -h, --help     zz{{Show help message.}}
423
414
}}
424
415
zz{{:See also: gam}}
425
416
''')
426
417
 
 
418
 
427
419
    def test_help_custom_section_ordering(self):
428
420
        """Custom descriptive sections should remain in the order given."""
429
421
        # The help formatter expect the class name to start with 'cmd_'
430
422
        class cmd_Demo(commands.Command):
431
423
            __doc__ = """A sample command.
432
 
 
 
424
 
433
425
            Blah blah blah.
434
426
 
435
427
            :Formats:
437
429
 
438
430
            :Examples:
439
431
              Example 1::
440
 
 
 
432
 
441
433
                cmd arg1
442
434
 
443
435
            :Tips:
448
440
}}zz{{:Usage:   brz Demo
449
441
}}
450
442
zz{{:Options:
451
 
  -h, --help     zz{{Show help message.}}
 
443
  --usage        zz{{Show usage message and options.}}
452
444
  -q, --quiet    zz{{Only display errors and warnings.}}
453
 
  --usage        zz{{Show usage message and options.}}
454
445
  -v, --verbose  zz{{Display more information.}}
 
446
  -h, --help     zz{{Show help message.}}
455
447
}}
456
448
Description:
457
449
  zz{{zz{{Blah blah blah.}}
458
 
 
 
450
 
459
451
}}:Formats:
460
452
  zz{{Interesting stuff about formats.}}
461
 
 
 
453
 
462
454
Examples:
463
455
  zz{{Example 1::}}
464
 
 
 
456
 
465
457
    zz{{cmd arg1}}
466
 
 
 
458
 
467
459
Tips:
468
460
  zz{{Clever things to keep in mind.}}
469
 
 
 
461
 
470
462
''',
471
463
                           cmd_Demo())
472
464
 
491
483
 
492
484
}}
493
485
zz{{:Options:
494
 
  -h, --help     zz{{Show help message.}}
 
486
  --usage        zz{{Show usage message and options.}}
495
487
  -q, --quiet    zz{{Only display errors and warnings.}}
496
 
  --usage        zz{{Show usage message and options.}}
497
488
  -v, --verbose  zz{{Display more information.}}
 
489
  -h, --help     zz{{Show help message.}}
498
490
}}
499
491
Description:
500
492
  zz{{zz{{Blah blah blah.}}
538
530
        # Pick a known topic stored in an external file
539
531
        topic = help_topics.RegisteredTopic('authentication')
540
532
        self.assertStartsWith(topic.get_help_text(),
541
 
                              'Authentication Settings\n'
542
 
                              '=======================\n'
543
 
                              '\n')
 
533
            'Authentication Settings\n'
 
534
            '=======================\n'
 
535
            '\n')
544
536
 
545
537
    def test_get_help_topic(self):
546
538
        """The help topic for RegisteredTopic is its topic from construction."""
668
660
        """Searching for an unknown topic should raise NoHelpTopic."""
669
661
        indices = help.HelpIndices()
670
662
        indices.search_path = []
671
 
        error = self.assertRaises(help.NoHelpTopic, indices.search, 'foo')
 
663
        error = self.assertRaises(errors.NoHelpTopic, indices.search, 'foo')
672
664
        self.assertEqual('foo', error.topic)
673
665
 
674
666
    def test_search_calls_get_topic(self):
675
667
        """Searching should call get_topics in all indexes in order."""
676
668
        calls = []
677
 
 
678
669
        class RecordingIndex(object):
679
670
            def __init__(self, name):
680
671
                self.prefix = name
681
 
 
682
672
            def get_topics(self, topic):
683
673
                calls.append(('get_topics', self.prefix, topic))
684
674
                return ['something']
706
696
            def __init__(self, prefix, search_result):
707
697
                self.prefix = prefix
708
698
                self.result = search_result
709
 
 
710
699
            def get_topics(self, topic):
711
700
                return self.result
712
701
        index = help.HelpIndices()
714
703
        index_two = CannedIndex('2', ['b', 'c'])
715
704
        index.search_path = [index_one, index_two]
716
705
        self.assertEqual([(index_one, 'a'), (index_two, 'b'), (index_two, 'c')],
717
 
                         index.search(None))
 
706
            index.search(None))
718
707
 
719
708
    def test_search_checks_for_duplicate_prefixes(self):
720
709
        """Its an error when there are multiple indices with the same prefix."""
721
710
        indices = help.HelpIndices()
722
711
        indices.search_path = [help_topics.HelpTopicIndex(),
723
 
                               help_topics.HelpTopicIndex()]
 
712
            help_topics.HelpTopicIndex()]
724
713
        self.assertRaises(errors.DuplicateHelpPrefix, indices.search, None)