1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2005-2011 Canonical Ltd
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
19
19
from bzrlib import (
25
27
from bzrlib.builtins import cmd_commit
26
from bzrlib.commands import Command, parse_args
28
from bzrlib.commands import parse_args
27
29
from bzrlib.tests import TestCase
28
30
from bzrlib.repofmt import knitrepo
41
43
# XXX: Using cmd_commit makes these tests overly sensitive to changes
42
44
# to cmd_commit, when they are meant to be about option parsing in
44
self.assertEqual(parse_args(cmd_commit(), ['--help']),
45
([], {'author': [], 'exclude': [], 'fixes': [], 'help': True}))
46
self.assertEqual(parse_args(cmd_commit(), ['--message=biter']),
47
([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter'}))
47
([], {'author': [], 'exclude': [], 'fixes': [], 'help': True}),
48
parse_args(cmd_commit(), ['--help']))
50
([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter'}),
51
parse_args(cmd_commit(), ['--message=biter']))
49
53
def test_no_more_opts(self):
50
54
"""Terminated options"""
51
self.assertEqual(parse_args(cmd_commit(), ['--', '-file-with-dashes']),
52
(['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': []}))
56
(['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': []}),
57
parse_args(cmd_commit(), ['--', '-file-with-dashes']))
54
59
def test_option_help(self):
55
60
"""Options have help strings."""
107
112
self.assertFalse(option.Option('foo', hidden=False).is_hidden('foo'))
109
114
def test_registry_conversion(self):
110
registry = bzrdir.BzrDirFormatRegistry()
111
registry.register_metadir('one', 'RepositoryFormat7', 'one help')
112
registry.register_metadir('two', 'RepositoryFormatKnit1', 'two help')
113
registry.register_metadir('hidden', 'RepositoryFormatKnit1',
115
registry = controldir.ControlDirFormatRegistry()
116
bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
117
bzrdir.register_metadir(registry, 'two', 'RepositoryFormatKnit1', 'two help')
118
bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormatKnit1',
114
119
'two help', hidden=True)
115
120
registry.set_default('one')
116
121
options = [option.RegistryOption('format', '', registry, str)]
177
182
self.assertEqual('test option', my_option.help)
179
184
def test_help(self):
180
registry = bzrdir.BzrDirFormatRegistry()
181
registry.register_metadir('one', 'RepositoryFormat7', 'one help')
182
registry.register_metadir('two',
185
registry = controldir.ControlDirFormatRegistry()
186
bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
187
bzrdir.register_metadir(registry, 'two',
183
188
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
186
registry.register_metadir('hidden', 'RepositoryFormat7', 'hidden help',
191
bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormat7', 'hidden help',
188
193
registry.set_default('one')
189
194
options = [option.RegistryOption('format', 'format help', registry,
205
210
opt = option.Option('hello', help='fg', type=int, argname='gar')
206
211
self.assertEqual(list(opt.iter_switches()),
207
212
[('hello', None, 'GAR', 'fg')])
208
registry = bzrdir.BzrDirFormatRegistry()
209
registry.register_metadir('one', 'RepositoryFormat7', 'one help')
210
registry.register_metadir('two',
213
registry = controldir.ControlDirFormatRegistry()
214
bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
215
bzrdir.register_metadir(registry, 'two',
211
216
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
386
391
+ '\n'.join(msgs))
388
393
def test_is_hidden(self):
389
registry = bzrdir.BzrDirFormatRegistry()
390
registry.register_metadir('hidden', 'HiddenFormat',
394
registry = controldir.ControlDirFormatRegistry()
395
bzrdir.register_metadir(registry, 'hidden', 'HiddenFormat',
391
396
'hidden help text', hidden=True)
392
registry.register_metadir('visible', 'VisibleFormat',
397
bzrdir.register_metadir(registry, 'visible', 'VisibleFormat',
393
398
'visible help text', hidden=False)
394
399
format = option.RegistryOption('format', '', registry, str)
395
400
self.assertTrue(format.is_hidden('hidden'))
396
401
self.assertFalse(format.is_hidden('visible'))
403
def test_short_name(self):
404
registry = controldir.ControlDirFormatRegistry()
405
opt = option.RegistryOption('format', help='', registry=registry)
406
self.assertEquals(None, opt.short_name())
407
opt = option.RegistryOption('format', short_name='F', help='',
409
self.assertEquals('F', opt.short_name())
398
411
def test_option_custom_help(self):
399
412
the_opt = option.Option.OPTIONS['help']
400
413
orig_help = the_opt.help[:]
403
416
self.assertEqual('suggest lottery numbers', my_opt.help)
404
417
self.assertEqual(orig_help, the_opt.help)
419
def test_short_value_switches(self):
420
reg = registry.Registry()
421
reg.register('short', 'ShortChoice')
422
reg.register('long', 'LongChoice')
423
ropt = option.RegistryOption('choice', '', reg, value_switches=True,
424
short_value_switches={'short': 's'})
425
opts, args = parse([ropt], ['--short'])
426
self.assertEqual('ShortChoice', opts.choice)
427
opts, args = parse([ropt], ['-s'])
428
self.assertEqual('ShortChoice', opts.choice)
407
431
class TestVerboseQuietLinkage(TestCase):