~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_help.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

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
  --usage        Show usage message and options.
 
53
  -q, --quiet    Only display errors and warnings.
 
54
  -v, --verbose  Display more information.
 
55
  -h, --help     Show help message.
 
56
 
 
57
See also: bar, foo
 
58
''',
59
59
                           cmd_WithSeeAlso())
60
60
 
61
61
    def test_get_help_text(self):
63
63
        class cmd_Demo(commands.Command):
64
64
            __doc__ = """A sample command."""
65
65
        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
 
            ''',
 
66
Purpose: A sample command.
 
67
Usage:   bzr Demo
 
68
 
 
69
Options:
 
70
  --usage        Show usage message and options.
 
71
  -q, --quiet    Only display errors and warnings.
 
72
  -v, --verbose  Display more information.
 
73
  -h, --help     Show help message.
 
74
 
 
75
''',
76
76
                           cmd_Demo())
77
77
        cmd = cmd_Demo()
78
78
        helptext = cmd.get_help_text()
90
90
        helptext = cmd.get_help_text(['gam'])
91
91
        self.assertEndsWith(
92
92
            helptext,
 
93
            '  -q, --quiet    Only display errors and warnings.\n'
93
94
            '  -v, --verbose  Display more information.\n'
94
 
            '  -q, --quiet    Only display errors and warnings.\n'
95
95
            '  -h, --help     Show help message.\n'
96
96
            '\n'
97
97
            'See also: bar, foo, gam\n')
103
103
        helptext = cmd.get_help_text(['gam'])
104
104
        self.assertEndsWith(
105
105
            helptext,
 
106
            '  -q, --quiet    Only display errors and warnings.\n'
106
107
            '  -v, --verbose  Display more information.\n'
107
 
            '  -q, --quiet    Only display errors and warnings.\n'
108
108
            '  -h, --help     Show help message.\n'
109
109
            '\n'
110
110
            'See also: gam\n')
138
138
            """
139
139
        cmd = cmd_Demo()
140
140
        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')
 
141
        self.assertEqualDiff('''\
 
142
Purpose: A sample command.
 
143
Usage:   bzr Demo
 
144
 
 
145
Options:
 
146
  --usage        Show usage message and options.
 
147
  -q, --quiet    Only display errors and warnings.
 
148
  -v, --verbose  Display more information.
 
149
  -h, --help     Show help message.
 
150
 
 
151
Examples:
 
152
    Example 1:
 
153
 
 
154
        cmd arg1
 
155
 
 
156
    Example 2:
 
157
 
 
158
        cmd arg2
 
159
 
 
160
    A code block follows.
 
161
 
 
162
        bzr Demo something
 
163
 
 
164
''',
 
165
                                         helptext)
165
166
        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')
 
167
        self.assertEqualDiff('''\
 
168
:Purpose: A sample command.
 
169
:Usage:   bzr Demo
 
170
 
 
171
:Options:
 
172
  --usage        Show usage message and options.
 
173
  -q, --quiet    Only display errors and warnings.
 
174
  -v, --verbose  Display more information.
 
175
  -h, --help     Show help message.
 
176
 
 
177
:Examples:
 
178
    Example 1::
 
179
 
 
180
        cmd arg1
 
181
 
 
182
    Example 2::
 
183
 
 
184
        cmd arg2
 
185
 
 
186
    A code block follows.
 
187
 
 
188
    ::
 
189
 
 
190
        bzr Demo something
 
191
 
 
192
''',
 
193
                             helptext)
191
194
 
192
195
    def test_concise_help_text(self):
193
196
        """Concise help text excludes the descriptive sections."""
203
206
            """
204
207
        cmd = cmd_Demo()
205
208
        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')
 
209
        self.assertEqualDiff('''\
 
210
Purpose: A sample command.
 
211
Usage:   bzr Demo
 
212
 
 
213
Options:
 
214
  --usage        Show usage message and options.
 
215
  -q, --quiet    Only display errors and warnings.
 
216
  -v, --verbose  Display more information.
 
217
  -h, --help     Show help message.
 
218
 
 
219
Description:
 
220
  Blah blah blah.
 
221
 
 
222
Examples:
 
223
    Example 1:
 
224
 
 
225
        cmd arg1
 
226
 
 
227
''',
 
228
                             helptext)
225
229
        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')
 
230
        self.assertEqualDiff('''\
 
231
Purpose: A sample command.
 
232
Usage:   bzr Demo
 
233
 
 
234
Options:
 
235
  --usage        Show usage message and options.
 
236
  -q, --quiet    Only display errors and warnings.
 
237
  -v, --verbose  Display more information.
 
238
  -h, --help     Show help message.
 
239
 
 
240
See bzr help Demo for more details and examples.
 
241
 
 
242
''',
 
243
                             helptext)
238
244
 
239
245
    def test_help_custom_section_ordering(self):
240
246
        """Custom descriptive sections should remain in the order given."""
241
247
        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
 
            """
 
248
            __doc__ = """\
 
249
A sample command.
 
250
 
 
251
Blah blah blah.
 
252
 
 
253
:Formats:
 
254
  Interesting stuff about formats.
 
255
 
 
256
:Examples:
 
257
  Example 1::
 
258
 
 
259
    cmd arg1
 
260
 
 
261
:Tips:
 
262
  Clever things to keep in mind.
 
263
"""
257
264
        cmd = cmd_Demo()
258
265
        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')
 
266
        self.assertEqualDiff('''\
 
267
Purpose: A sample command.
 
268
Usage:   bzr Demo
 
269
 
 
270
Options:
 
271
  --usage        Show usage message and options.
 
272
  -q, --quiet    Only display errors and warnings.
 
273
  -v, --verbose  Display more information.
 
274
  -h, --help     Show help message.
 
275
 
 
276
Description:
 
277
  Blah blah blah.
 
278
 
 
279
Formats:
 
280
  Interesting stuff about formats.
 
281
 
 
282
Examples:
 
283
  Example 1:
 
284
 
 
285
    cmd arg1
 
286
 
 
287
Tips:
 
288
  Clever things to keep in mind.
 
289
 
 
290
''',
 
291
                             helptext)
284
292
 
285
293
    def test_help_text_custom_usage(self):
286
294
        """Help text may contain a custom usage section."""
296
304
            """
297
305
        cmd = cmd_Demo()
298
306
        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')
 
307
        self.assertEqualDiff('''\
 
308
Purpose: A sample command.
 
309
Usage:
 
310
    cmd Demo [opts] args
 
311
 
 
312
    cmd Demo -h
 
313
 
 
314
 
 
315
Options:
 
316
  --usage        Show usage message and options.
 
317
  -q, --quiet    Only display errors and warnings.
 
318
  -v, --verbose  Display more information.
 
319
  -h, --help     Show help message.
 
320
 
 
321
Description:
 
322
  Blah blah blah.
 
323
 
 
324
''',
 
325
                             helptext)
315
326
 
316
327
 
317
328
class ZzzTranslationsForDoc(ZzzTranslations):
343
354
            __doc__ = """A sample command."""
344
355
            _see_also = ['foo', 'bar']
345
356
        self.assertCmdHelp('''\
346
 
            zz{{:Purpose: zz{{A sample command.}}
347
 
            }}zz{{:Usage:   bzr WithSeeAlso
348
 
            }}
349
 
            zz{{:Options:
350
 
              --usage        Show usage message and options.
351
 
              -v, --verbose  Display more information.
352
 
              -q, --quiet    Only display errors and warnings.
353
 
              -h, --help     Show help message.
354
 
            }}
355
 
            zz{{:See also: bar, foo}}
356
 
            ''',
 
357
zz{{:Purpose: zz{{A sample command.}}
 
358
}}zz{{:Usage:   bzr WithSeeAlso
 
359
}}
 
360
zz{{:Options:
 
361
  --usage        zz{{Show usage message and options.}}
 
362
  -q, --quiet    zz{{Only display errors and warnings.}}
 
363
  -v, --verbose  zz{{Display more information.}}
 
364
  -h, --help     zz{{Show help message.}}
 
365
}}
 
366
zz{{:See also: bar, foo}}
 
367
''',
357
368
                           cmd_WithSeeAlso())
358
369
 
359
370
    def test_get_help_text(self):
361
372
        class cmd_Demo(commands.Command):
362
373
            __doc__ = """A sample command."""
363
374
        self.assertCmdHelp('''\
364
 
            zz{{:Purpose: zz{{A sample command.}}
365
 
            }}zz{{:Usage:   bzr Demo
366
 
            }}
367
 
            zz{{:Options:
368
 
              --usage        Show usage message and options.
369
 
              -v, --verbose  Display more information.
370
 
              -q, --quiet    Only display errors and warnings.
371
 
              -h, --help     Show help message.
372
 
            }}
373
 
            ''',
 
375
zz{{:Purpose: zz{{A sample command.}}
 
376
}}zz{{:Usage:   bzr Demo
 
377
}}
 
378
zz{{:Options:
 
379
  --usage        zz{{Show usage message and options.}}
 
380
  -q, --quiet    zz{{Only display errors and warnings.}}
 
381
  -v, --verbose  zz{{Display more information.}}
 
382
  -h, --help     zz{{Show help message.}}
 
383
}}
 
384
''',
374
385
                           cmd_Demo())
375
386
 
376
387
    def test_command_with_additional_see_also(self):
380
391
        cmd = cmd_WithSeeAlso()
381
392
        helptext = cmd.get_help_text(['gam'])
382
393
        self.assertEndsWith(
383
 
            helptext,
384
 
            '  -v, --verbose  Display more information.\n'
385
 
            '  -q, --quiet    Only display errors and warnings.\n'
386
 
            '  -h, --help     Show help message.\n'
387
 
            '}}\n'
388
 
            'zz{{:See also: bar, foo, gam}}\n')
 
394
            helptext,'''\
 
395
  -q, --quiet    zz{{Only display errors and warnings.}}
 
396
  -v, --verbose  zz{{Display more information.}}
 
397
  -h, --help     zz{{Show help message.}}
 
398
}}
 
399
zz{{:See also: bar, foo, gam}}
 
400
''')
389
401
 
390
402
    def test_command_only_additional_see_also(self):
391
403
        class cmd_WithSeeAlso(commands.Command):
393
405
        cmd = cmd_WithSeeAlso()
394
406
        helptext = cmd.get_help_text(['gam'])
395
407
        self.assertEndsWith(
396
 
            helptext,
397
 
            'zz{{:Options:\n'
398
 
            '  --usage        Show usage message and options.\n'
399
 
            '  -v, --verbose  Display more information.\n'
400
 
            '  -q, --quiet    Only display errors and warnings.\n'
401
 
            '  -h, --help     Show help message.\n'
402
 
            '}}\n'
403
 
            'zz{{:See also: gam}}\n')
 
408
            helptext, '''\
 
409
zz{{:Options:
 
410
  --usage        zz{{Show usage message and options.}}
 
411
  -q, --quiet    zz{{Only display errors and warnings.}}
 
412
  -v, --verbose  zz{{Display more information.}}
 
413
  -h, --help     zz{{Show help message.}}
 
414
}}
 
415
zz{{:See also: gam}}
 
416
''')
404
417
 
405
418
 
406
419
    def test_help_custom_section_ordering(self):
423
436
              Clever things to keep in mind.
424
437
            """
425
438
        self.assertCmdHelp('''\
426
 
            zz{{:Purpose: zz{{A sample command.}}
427
 
            }}zz{{:Usage:   bzr Demo
428
 
            }}
429
 
            zz{{:Options:
430
 
              --usage        Show usage message and options.
431
 
              -v, --verbose  Display more information.
432
 
              -q, --quiet    Only display errors and warnings.
433
 
              -h, --help     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
 
            ''',
 
439
zz{{:Purpose: zz{{A sample command.}}
 
440
}}zz{{:Usage:   bzr Demo
 
441
}}
 
442
zz{{:Options:
 
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
Description:
 
449
  zz{{zz{{Blah blah blah.}}
 
450
 
 
451
}}:Formats:
 
452
  zz{{Interesting stuff about formats.}}
 
453
 
 
454
Examples:
 
455
  zz{{Example 1::}}
 
456
 
 
457
    zz{{cmd arg1}}
 
458
 
 
459
Tips:
 
460
  zz{{Clever things to keep in mind.}}
 
461
 
 
462
''',
450
463
                           cmd_Demo())
451
464
 
452
465
    def test_help_text_custom_usage(self):
462
475
            Blah blah blah.
463
476
            """
464
477
        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        Show usage message and options.
474
 
              -v, --verbose  Display more information.
475
 
              -q, --quiet    Only display errors and warnings.
476
 
              -h, --help     Show help message.
477
 
            }}
478
 
            Description:
479
 
              zz{{zz{{Blah blah blah.}}
480
 
 
481
 
            }}
482
 
            ''',
 
478
zz{{:Purpose: zz{{A sample command.}}
 
479
}}zz{{:Usage:
 
480
    zz{{cmd Demo [opts] args}}
 
481
 
 
482
    zz{{cmd Demo -h}}
 
483
 
 
484
}}
 
485
zz{{:Options:
 
486
  --usage        zz{{Show usage message and options.}}
 
487
  -q, --quiet    zz{{Only display errors and warnings.}}
 
488
  -v, --verbose  zz{{Display more information.}}
 
489
  -h, --help     zz{{Show help message.}}
 
490
}}
 
491
Description:
 
492
  zz{{zz{{Blah blah blah.}}
 
493
 
 
494
}}
 
495
''',
483
496
                           cmd_Demo())
484
497
 
485
498