~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-26 15:40:02 UTC
  • mto: This revision was merged to the branch mainline in revision 6178.
  • Revision ID: v.ladeuil+lp@free.fr-20110926154002-exguk3psfpc4b2uw
Allow config options to be overridden from the command line

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
            __doc__ = """A sample command."""
46
46
            _see_also = ['foo', 'bar']
47
47
        self.assertCmdHelp('''\
48
 
            Purpose: A sample command.
49
 
            Usage:   bzr WithSeeAlso
50
 
            
51
 
            Options:
52
 
              --usage        Show usage message and options.
53
 
              -v, --verbose  Display more information.
54
 
              -q, --quiet    Only display errors and warnings.
55
 
              -h, --help     Show help message.
56
 
            
57
 
            See also: bar, foo
58
 
            ''',
 
48
Purpose: A sample command.
 
49
Usage:   bzr WithSeeAlso
 
50
 
 
51
Options:
 
52
  -O ARG, --override-config=ARG
 
53
                        Override a configuration option value, e.g.
 
54
                        -Oname=value
 
55
  --usage               Show usage message and options.
 
56
  -q, --quiet           Only display errors and warnings.
 
57
  -v, --verbose         Display more information.
 
58
  -h, --help            Show help message.
 
59
 
 
60
See also: bar, foo
 
61
''',
59
62
                           cmd_WithSeeAlso())
60
63
 
61
64
    def test_get_help_text(self):
63
66
        class cmd_Demo(commands.Command):
64
67
            __doc__ = """A sample command."""
65
68
        self.assertCmdHelp('''\
66
 
            Purpose: A sample command.
67
 
            Usage:   bzr Demo
68
 
            
69
 
            Options:
70
 
              --usage        Show usage message and options.
71
 
              -v, --verbose  Display more information.
72
 
              -q, --quiet    Only display errors and warnings.
73
 
              -h, --help     Show help message.
74
 
 
75
 
            ''',
 
69
Purpose: A sample command.
 
70
Usage:   bzr Demo
 
71
 
 
72
Options:
 
73
  -O ARG, --override-config=ARG
 
74
                        Override a configuration option value, e.g.
 
75
                        -Oname=value
 
76
  --usage               Show usage message and options.
 
77
  -q, --quiet           Only display errors and warnings.
 
78
  -v, --verbose         Display more information.
 
79
  -h, --help            Show help message.
 
80
 
 
81
''',
76
82
                           cmd_Demo())
77
83
        cmd = cmd_Demo()
78
84
        helptext = cmd.get_help_text()
80
86
            'Purpose: A sample command.\n'
81
87
            'Usage:   bzr Demo')
82
88
        self.assertEndsWith(helptext,
83
 
            '  -h, --help     Show help message.\n\n')
 
89
            '  -h, --help            Show help message.\n\n')
84
90
 
85
91
    def test_command_with_additional_see_also(self):
86
92
        class cmd_WithSeeAlso(commands.Command):
90
96
        helptext = cmd.get_help_text(['gam'])
91
97
        self.assertEndsWith(
92
98
            helptext,
93
 
            '  -v, --verbose  Display more information.\n'
94
 
            '  -q, --quiet    Only display errors and warnings.\n'
95
 
            '  -h, --help     Show help message.\n'
 
99
            '  -q, --quiet           Only display errors and warnings.\n'
 
100
            '  -v, --verbose         Display more information.\n'
 
101
            '  -h, --help            Show help message.\n'
96
102
            '\n'
97
103
            'See also: bar, foo, gam\n')
98
104
 
103
109
        helptext = cmd.get_help_text(['gam'])
104
110
        self.assertEndsWith(
105
111
            helptext,
106
 
            '  -v, --verbose  Display more information.\n'
107
 
            '  -q, --quiet    Only display errors and warnings.\n'
108
 
            '  -h, --help     Show help message.\n'
 
112
            '  -q, --quiet           Only display errors and warnings.\n'
 
113
            '  -v, --verbose         Display more information.\n'
 
114
            '  -h, --help            Show help message.\n'
109
115
            '\n'
110
116
            'See also: gam\n')
111
117
 
138
144
            """
139
145
        cmd = cmd_Demo()
140
146
        helptext = cmd.get_help_text()
141
 
        self.assertEquals(
142
 
            helptext,
143
 
            'Purpose: A sample command.\n'
144
 
            'Usage:   bzr Demo\n'
145
 
            '\n'
146
 
            'Options:\n'
147
 
            '  --usage        Show usage message and options.\n'
148
 
            '  -v, --verbose  Display more information.\n'
149
 
            '  -q, --quiet    Only display errors and warnings.\n'
150
 
            '  -h, --help     Show help message.\n'
151
 
            '\n'
152
 
            'Examples:\n'
153
 
            '    Example 1:\n'
154
 
            '\n'
155
 
            '        cmd arg1\n'
156
 
            '\n'
157
 
            '    Example 2:\n'
158
 
            '\n'
159
 
            '        cmd arg2\n'
160
 
            '\n'
161
 
            '    A code block follows.\n'
162
 
            '\n'
163
 
            '        bzr Demo something\n'
164
 
            '\n')
 
147
        self.assertEqualDiff('''\
 
148
Purpose: A sample command.
 
149
Usage:   bzr Demo
 
150
 
 
151
Options:
 
152
  -O ARG, --override-config=ARG
 
153
                        Override a configuration option value, e.g.
 
154
                        -Oname=value
 
155
  --usage               Show usage message and options.
 
156
  -q, --quiet           Only display errors and warnings.
 
157
  -v, --verbose         Display more information.
 
158
  -h, --help            Show help message.
 
159
 
 
160
Examples:
 
161
    Example 1:
 
162
 
 
163
        cmd arg1
 
164
 
 
165
    Example 2:
 
166
 
 
167
        cmd arg2
 
168
 
 
169
    A code block follows.
 
170
 
 
171
        bzr Demo something
 
172
 
 
173
''',
 
174
                                         helptext)
165
175
        helptext = cmd.get_help_text(plain=False)
166
 
        self.assertEquals(helptext,
167
 
            ':Purpose: A sample command.\n'
168
 
            ':Usage:   bzr Demo\n'
169
 
            '\n'
170
 
            ':Options:\n'
171
 
            '  --usage        Show usage message and options.\n'
172
 
            '  -v, --verbose  Display more information.\n'
173
 
            '  -q, --quiet    Only display errors and warnings.\n'
174
 
            '  -h, --help     Show help message.\n'
175
 
            '\n'
176
 
            ':Examples:\n'
177
 
            '    Example 1::\n'
178
 
            '\n'
179
 
            '        cmd arg1\n'
180
 
            '\n'
181
 
            '    Example 2::\n'
182
 
            '\n'
183
 
            '        cmd arg2\n'
184
 
            '\n'
185
 
            '    A code block follows.\n'
186
 
            '\n'
187
 
            '    ::\n'
188
 
            '\n'
189
 
            '        bzr Demo something\n'
190
 
            '\n')
 
176
        self.assertEqualDiff('''\
 
177
:Purpose: A sample command.
 
178
:Usage:   bzr Demo
 
179
 
 
180
:Options:
 
181
  -O ARG, --override-config=ARG
 
182
                        Override a configuration option value, e.g.
 
183
                        -Oname=value
 
184
  --usage               Show usage message and options.
 
185
  -q, --quiet           Only display errors and warnings.
 
186
  -v, --verbose         Display more information.
 
187
  -h, --help            Show help message.
 
188
 
 
189
:Examples:
 
190
    Example 1::
 
191
 
 
192
        cmd arg1
 
193
 
 
194
    Example 2::
 
195
 
 
196
        cmd arg2
 
197
 
 
198
    A code block follows.
 
199
 
 
200
    ::
 
201
 
 
202
        bzr Demo something
 
203
 
 
204
''',
 
205
                             helptext)
191
206
 
192
207
    def test_concise_help_text(self):
193
208
        """Concise help text excludes the descriptive sections."""
203
218
            """
204
219
        cmd = cmd_Demo()
205
220
        helptext = cmd.get_help_text()
206
 
        self.assertEqualDiff(
207
 
            helptext,
208
 
            'Purpose: A sample command.\n'
209
 
            'Usage:   bzr Demo\n'
210
 
            '\n'
211
 
            'Options:\n'
212
 
            '  --usage        Show usage message and options.\n'
213
 
            '  -v, --verbose  Display more information.\n'
214
 
            '  -q, --quiet    Only display errors and warnings.\n'
215
 
            '  -h, --help     Show help message.\n'
216
 
            '\n'
217
 
            'Description:\n'
218
 
            '  Blah blah blah.\n'
219
 
            '\n'
220
 
            'Examples:\n'
221
 
            '    Example 1:\n'
222
 
            '\n'
223
 
            '        cmd arg1\n'
224
 
            '\n')
 
221
        self.assertEqualDiff('''\
 
222
Purpose: A sample command.
 
223
Usage:   bzr Demo
 
224
 
 
225
Options:
 
226
  -O ARG, --override-config=ARG
 
227
                        Override a configuration option value, e.g.
 
228
                        -Oname=value
 
229
  --usage               Show usage message and options.
 
230
  -q, --quiet           Only display errors and warnings.
 
231
  -v, --verbose         Display more information.
 
232
  -h, --help            Show help message.
 
233
 
 
234
Description:
 
235
  Blah blah blah.
 
236
 
 
237
Examples:
 
238
    Example 1:
 
239
 
 
240
        cmd arg1
 
241
 
 
242
''',
 
243
                             helptext)
225
244
        helptext = cmd.get_help_text(verbose=False)
226
 
        self.assertEquals(helptext,
227
 
            'Purpose: A sample command.\n'
228
 
            'Usage:   bzr Demo\n'
229
 
            '\n'
230
 
            'Options:\n'
231
 
            '  --usage        Show usage message and options.\n'
232
 
            '  -v, --verbose  Display more information.\n'
233
 
            '  -q, --quiet    Only display errors and warnings.\n'
234
 
            '  -h, --help     Show help message.\n'
235
 
            '\n'
236
 
            'See bzr help Demo for more details and examples.\n'
237
 
            '\n')
 
245
        self.assertEqualDiff('''\
 
246
Purpose: A sample command.
 
247
Usage:   bzr Demo
 
248
 
 
249
Options:
 
250
  -O ARG, --override-config=ARG
 
251
                        Override a configuration option value, e.g.
 
252
                        -Oname=value
 
253
  --usage               Show usage message and options.
 
254
  -q, --quiet           Only display errors and warnings.
 
255
  -v, --verbose         Display more information.
 
256
  -h, --help            Show help message.
 
257
 
 
258
See bzr help Demo for more details and examples.
 
259
 
 
260
''',
 
261
                             helptext)
238
262
 
239
263
    def test_help_custom_section_ordering(self):
240
264
        """Custom descriptive sections should remain in the order given."""
241
265
        class cmd_Demo(commands.Command):
242
 
            __doc__ = """A sample command.
243
 
 
244
 
            Blah blah blah.
245
 
 
246
 
            :Formats:
247
 
              Interesting stuff about formats.
248
 
 
249
 
            :Examples:
250
 
              Example 1::
251
 
 
252
 
                cmd arg1
253
 
 
254
 
            :Tips:
255
 
              Clever things to keep in mind.
256
 
            """
 
266
            __doc__ = """\
 
267
A sample command.
 
268
 
 
269
Blah blah blah.
 
270
 
 
271
:Formats:
 
272
  Interesting stuff about formats.
 
273
 
 
274
:Examples:
 
275
  Example 1::
 
276
 
 
277
    cmd arg1
 
278
 
 
279
:Tips:
 
280
  Clever things to keep in mind.
 
281
"""
257
282
        cmd = cmd_Demo()
258
283
        helptext = cmd.get_help_text()
259
 
        self.assertEqualDiff(
260
 
            helptext,
261
 
            'Purpose: A sample command.\n'
262
 
            'Usage:   bzr Demo\n'
263
 
            '\n'
264
 
            'Options:\n'
265
 
            '  --usage        Show usage message and options.\n'
266
 
            '  -v, --verbose  Display more information.\n'
267
 
            '  -q, --quiet    Only display errors and warnings.\n'
268
 
            '  -h, --help     Show help message.\n'
269
 
            '\n'
270
 
            'Description:\n'
271
 
            '  Blah blah blah.\n'
272
 
            '\n'
273
 
            'Formats:\n'
274
 
            '  Interesting stuff about formats.\n'
275
 
            '\n'
276
 
            'Examples:\n'
277
 
            '  Example 1:\n'
278
 
            '\n'
279
 
            '    cmd arg1\n'
280
 
            '\n'
281
 
            'Tips:\n'
282
 
            '  Clever things to keep in mind.\n'
283
 
            '\n')
 
284
        self.assertEqualDiff('''\
 
285
Purpose: A sample command.
 
286
Usage:   bzr Demo
 
287
 
 
288
Options:
 
289
  -O ARG, --override-config=ARG
 
290
                        Override a configuration option value, e.g.
 
291
                        -Oname=value
 
292
  --usage               Show usage message and options.
 
293
  -q, --quiet           Only display errors and warnings.
 
294
  -v, --verbose         Display more information.
 
295
  -h, --help            Show help message.
 
296
 
 
297
Description:
 
298
  Blah blah blah.
 
299
 
 
300
Formats:
 
301
  Interesting stuff about formats.
 
302
 
 
303
Examples:
 
304
  Example 1:
 
305
 
 
306
    cmd arg1
 
307
 
 
308
Tips:
 
309
  Clever things to keep in mind.
 
310
 
 
311
''',
 
312
                             helptext)
284
313
 
285
314
    def test_help_text_custom_usage(self):
286
315
        """Help text may contain a custom usage section."""
296
325
            """
297
326
        cmd = cmd_Demo()
298
327
        helptext = cmd.get_help_text()
299
 
        self.assertEquals(helptext,
300
 
            'Purpose: A sample command.\n'
301
 
            'Usage:\n'
302
 
            '    cmd Demo [opts] args\n'
303
 
            '\n'
304
 
            '    cmd Demo -h\n'
305
 
            '\n'
306
 
            '\n'
307
 
            'Options:\n'
308
 
            '  --usage        Show usage message and options.\n'
309
 
            '  -v, --verbose  Display more information.\n'
310
 
            '  -q, --quiet    Only display errors and warnings.\n'
311
 
            '  -h, --help     Show help message.\n'
312
 
            '\n'
313
 
            'Description:\n'
314
 
            '  Blah blah blah.\n\n')
 
328
        self.assertEqualDiff('''\
 
329
Purpose: A sample command.
 
330
Usage:
 
331
    cmd Demo [opts] args
 
332
 
 
333
    cmd Demo -h
 
334
 
 
335
 
 
336
Options:
 
337
  -O ARG, --override-config=ARG
 
338
                        Override a configuration option value, e.g.
 
339
                        -Oname=value
 
340
  --usage               Show usage message and options.
 
341
  -q, --quiet           Only display errors and warnings.
 
342
  -v, --verbose         Display more information.
 
343
  -h, --help            Show help message.
 
344
 
 
345
Description:
 
346
  Blah blah blah.
 
347
 
 
348
''',
 
349
                             helptext)
315
350
 
316
351
 
317
352
class ZzzTranslationsForDoc(ZzzTranslations):
343
378
            __doc__ = """A sample command."""
344
379
            _see_also = ['foo', 'bar']
345
380
        self.assertCmdHelp('''\
346
 
            zz{{:Purpose: zz{{A sample command.}}
347
 
            }}zz{{:Usage:   bzr WithSeeAlso
348
 
            }}
349
 
            zz{{:Options:
350
 
              --usage        zz{{Show usage message and options.}}
351
 
              -v, --verbose  zz{{Display more information.}}
352
 
              -q, --quiet    zz{{Only display errors and warnings.}}
353
 
              -h, --help     zz{{Show help message.}}
354
 
            }}
355
 
            zz{{:See also: bar, foo}}
356
 
            ''',
 
381
zz{{:Purpose: zz{{A sample command.}}
 
382
}}zz{{:Usage:   bzr WithSeeAlso
 
383
}}
 
384
zz{{:Options:
 
385
  -O ARG, --override-config=ARG
 
386
                        zz{{Override a configuration option value, e.g.
 
387
                        -Oname=value}}
 
388
  --usage               zz{{Show usage message and options.}}
 
389
  -q, --quiet           zz{{Only display errors and warnings.}}
 
390
  -v, --verbose         zz{{Display more information.}}
 
391
  -h, --help            zz{{Show help message.}}
 
392
}}
 
393
zz{{:See also: bar, foo}}
 
394
''',
357
395
                           cmd_WithSeeAlso())
358
396
 
359
397
    def test_get_help_text(self):
361
399
        class cmd_Demo(commands.Command):
362
400
            __doc__ = """A sample command."""
363
401
        self.assertCmdHelp('''\
364
 
            zz{{:Purpose: zz{{A sample command.}}
365
 
            }}zz{{:Usage:   bzr Demo
366
 
            }}
367
 
            zz{{:Options:
368
 
              --usage        zz{{Show usage message and options.}}
369
 
              -v, --verbose  zz{{Display more information.}}
370
 
              -q, --quiet    zz{{Only display errors and warnings.}}
371
 
              -h, --help     zz{{Show help message.}}
372
 
            }}
373
 
            ''',
 
402
zz{{:Purpose: zz{{A sample command.}}
 
403
}}zz{{:Usage:   bzr Demo
 
404
}}
 
405
zz{{:Options:
 
406
  -O ARG, --override-config=ARG
 
407
                        zz{{Override a configuration option value, e.g.
 
408
                        -Oname=value}}
 
409
  --usage               zz{{Show usage message and options.}}
 
410
  -q, --quiet           zz{{Only display errors and warnings.}}
 
411
  -v, --verbose         zz{{Display more information.}}
 
412
  -h, --help            zz{{Show help message.}}
 
413
}}
 
414
''',
374
415
                           cmd_Demo())
375
416
 
376
417
    def test_command_with_additional_see_also(self):
380
421
        cmd = cmd_WithSeeAlso()
381
422
        helptext = cmd.get_help_text(['gam'])
382
423
        self.assertEndsWith(
383
 
            helptext,
384
 
            '  -v, --verbose  zz{{Display more information.}}\n'
385
 
            '  -q, --quiet    zz{{Only display errors and warnings.}}\n'
386
 
            '  -h, --help     zz{{Show help message.}}\n'
387
 
            '}}\n'
388
 
            'zz{{:See also: bar, foo, gam}}\n')
 
424
            helptext,'''\
 
425
  -q, --quiet           zz{{Only display errors and warnings.}}
 
426
  -v, --verbose         zz{{Display more information.}}
 
427
  -h, --help            zz{{Show help message.}}
 
428
}}
 
429
zz{{:See also: bar, foo, gam}}
 
430
''')
389
431
 
390
432
    def test_command_only_additional_see_also(self):
391
433
        class cmd_WithSeeAlso(commands.Command):
393
435
        cmd = cmd_WithSeeAlso()
394
436
        helptext = cmd.get_help_text(['gam'])
395
437
        self.assertEndsWith(
396
 
            helptext,
397
 
            'zz{{:Options:\n'
398
 
            '  --usage        zz{{Show usage message and options.}}\n'
399
 
            '  -v, --verbose  zz{{Display more information.}}\n'
400
 
            '  -q, --quiet    zz{{Only display errors and warnings.}}\n'
401
 
            '  -h, --help     zz{{Show help message.}}\n'
402
 
            '}}\n'
403
 
            'zz{{:See also: gam}}\n')
 
438
            helptext, '''\
 
439
zz{{:Options:
 
440
  -O ARG, --override-config=ARG
 
441
                        zz{{Override a configuration option value, e.g.
 
442
                        -Oname=value}}
 
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.}}
 
447
}}
 
448
zz{{:See also: gam}}
 
449
''')
404
450
 
405
451
 
406
452
    def test_help_custom_section_ordering(self):
423
469
              Clever things to keep in mind.
424
470
            """
425
471
        self.assertCmdHelp('''\
426
 
            zz{{:Purpose: zz{{A sample command.}}
427
 
            }}zz{{:Usage:   bzr Demo
428
 
            }}
429
 
            zz{{:Options:
430
 
              --usage        zz{{Show usage message and options.}}
431
 
              -v, --verbose  zz{{Display more information.}}
432
 
              -q, --quiet    zz{{Only display errors and warnings.}}
433
 
              -h, --help     zz{{Show help message.}}
434
 
            }}
435
 
            Description:
436
 
              zz{{zz{{Blah blah blah.}}
437
 
            
438
 
            }}:Formats:
439
 
              zz{{Interesting stuff about formats.}}
440
 
            
441
 
            Examples:
442
 
              zz{{Example 1::}}
443
 
            
444
 
                zz{{cmd arg1}}
445
 
            
446
 
            Tips:
447
 
              zz{{Clever things to keep in mind.}}
448
 
 
449
 
            ''',
 
472
zz{{:Purpose: zz{{A sample command.}}
 
473
}}zz{{:Usage:   bzr Demo
 
474
}}
 
475
zz{{:Options:
 
476
  -O ARG, --override-config=ARG
 
477
                        zz{{Override a configuration option value, e.g.
 
478
                        -Oname=value}}
 
479
  --usage               zz{{Show usage message and options.}}
 
480
  -q, --quiet           zz{{Only display errors and warnings.}}
 
481
  -v, --verbose         zz{{Display more information.}}
 
482
  -h, --help            zz{{Show help message.}}
 
483
}}
 
484
Description:
 
485
  zz{{zz{{Blah blah blah.}}
 
486
 
 
487
}}:Formats:
 
488
  zz{{Interesting stuff about formats.}}
 
489
 
 
490
Examples:
 
491
  zz{{Example 1::}}
 
492
 
 
493
    zz{{cmd arg1}}
 
494
 
 
495
Tips:
 
496
  zz{{Clever things to keep in mind.}}
 
497
 
 
498
''',
450
499
                           cmd_Demo())
451
500
 
452
501
    def test_help_text_custom_usage(self):
462
511
            Blah blah blah.
463
512
            """
464
513
        self.assertCmdHelp('''\
465
 
            zz{{:Purpose: zz{{A sample command.}}
466
 
            }}zz{{:Usage:
467
 
                zz{{cmd Demo [opts] args}}
468
 
            
469
 
                zz{{cmd Demo -h}}
470
 
 
471
 
            }}
472
 
            zz{{:Options:
473
 
              --usage        zz{{Show usage message and options.}}
474
 
              -v, --verbose  zz{{Display more information.}}
475
 
              -q, --quiet    zz{{Only display errors and warnings.}}
476
 
              -h, --help     zz{{Show help message.}}
477
 
            }}
478
 
            Description:
479
 
              zz{{zz{{Blah blah blah.}}
480
 
 
481
 
            }}
482
 
            ''',
 
514
zz{{:Purpose: zz{{A sample command.}}
 
515
}}zz{{:Usage:
 
516
    zz{{cmd Demo [opts] args}}
 
517
 
 
518
    zz{{cmd Demo -h}}
 
519
 
 
520
}}
 
521
zz{{:Options:
 
522
  -O ARG, --override-config=ARG
 
523
                        zz{{Override a configuration option value, e.g.
 
524
                        -Oname=value}}
 
525
  --usage               zz{{Show usage message and options.}}
 
526
  -q, --quiet           zz{{Only display errors and warnings.}}
 
527
  -v, --verbose         zz{{Display more information.}}
 
528
  -h, --help            zz{{Show help message.}}
 
529
}}
 
530
Description:
 
531
  zz{{zz{{Blah blah blah.}}
 
532
 
 
533
}}
 
534
''',
483
535
                           cmd_Demo())
484
536
 
485
537