/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: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

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