116
116
def parse(self, options, args):
117
117
parser = option.get_optparser(dict((o.name, o) for o in options))
118
118
return parser.parse_args(args)
120
120
def test_conversion(self):
121
121
options = [option.Option('hello')]
122
122
opts, args = self.parse(options, ['--no-hello', '--hello'])
128
128
options = [option.Option('number', type=int)]
129
129
opts, args = self.parse(options, ['--number', '6'])
130
130
self.assertEqual(6, opts.number)
131
self.assertRaises(errors.BzrCommandError, self.parse, options,
131
self.assertRaises(errors.BzrCommandError, self.parse, options,
133
self.assertRaises(errors.BzrCommandError, self.parse, options,
133
self.assertRaises(errors.BzrCommandError, self.parse, options,
136
136
def test_registry_conversion(self):
143
143
self.assertEqual({'format':'one'}, opts)
144
144
opts, args = self.parse(options, ['--format', 'two'])
145
145
self.assertEqual({'format':'two'}, opts)
146
self.assertRaises(errors.BadOptionValue, self.parse, options,
146
self.assertRaises(errors.BadOptionValue, self.parse, options,
147
147
['--format', 'three'])
148
self.assertRaises(errors.BzrCommandError, self.parse, options,
148
self.assertRaises(errors.BzrCommandError, self.parse, options,
150
options = [option.RegistryOption('format', '', registry, str,
150
options = [option.RegistryOption('format', '', registry, str,
151
151
value_switches=True)]
152
152
opts, args = self.parse(options, ['--two'])
153
153
self.assertEqual({'format':'two'}, opts)
154
154
opts, args = self.parse(options, ['--two', '--one'])
155
155
self.assertEqual({'format':'one'}, opts)
156
opts, args = self.parse(options, ['--two', '--one',
156
opts, args = self.parse(options, ['--two', '--one',
157
157
'--format', 'two'])
158
158
self.assertEqual({'format':'two'}, opts)
160
160
def test_registry_converter(self):
161
options = [option.RegistryOption('format', '',
161
options = [option.RegistryOption('format', '',
162
162
bzrdir.format_registry, builtins.get_format_type)]
163
163
opts, args = self.parse(options, ['--format', 'knit'])
164
164
self.assertIsInstance(opts.format.repository_format,
198
198
value_switches=True)
199
199
self.assertEqual(list(opt.iter_switches()),
200
200
[('format', None, 'ARG', 'format help'),
201
('default', None, None, 'one help'),
202
('one', None, None, 'one help'),
203
('two', None, None, 'two help'),
201
('default', None, None, 'one help'),
202
('one', None, None, 'one help'),
203
('two', None, None, 'two help'),
206
206
# >>> parse_args('log -r 500'.split())