1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2005-2010 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
102
103
self.assertRaises(errors.BzrCommandError, self.parse, options,
106
def test_is_hidden(self):
107
self.assertTrue(option.Option('foo', hidden=True).is_hidden('foo'))
108
self.assertFalse(option.Option('foo', hidden=False).is_hidden('foo'))
105
110
def test_registry_conversion(self):
106
registry = bzrdir.BzrDirFormatRegistry()
107
registry.register_metadir('one', 'RepositoryFormat7', 'one help')
108
registry.register_metadir('two', 'RepositoryFormatKnit1', 'two help')
109
registry.register_metadir('hidden', 'RepositoryFormatKnit1',
111
registry = controldir.ControlDirFormatRegistry()
112
bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
113
bzrdir.register_metadir(registry, 'two', 'RepositoryFormatKnit1', 'two help')
114
bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormatKnit1',
110
115
'two help', hidden=True)
111
116
registry.set_default('one')
112
117
options = [option.RegistryOption('format', '', registry, str)]
173
178
self.assertEqual('test option', my_option.help)
175
180
def test_help(self):
176
registry = bzrdir.BzrDirFormatRegistry()
177
registry.register_metadir('one', 'RepositoryFormat7', 'one help')
178
registry.register_metadir('two',
181
registry = controldir.ControlDirFormatRegistry()
182
bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
183
bzrdir.register_metadir(registry, 'two',
179
184
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
182
registry.register_metadir('hidden', 'RepositoryFormat7', 'hidden help',
187
bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormat7', 'hidden help',
184
189
registry.set_default('one')
185
190
options = [option.RegistryOption('format', 'format help', registry,
201
206
opt = option.Option('hello', help='fg', type=int, argname='gar')
202
207
self.assertEqual(list(opt.iter_switches()),
203
208
[('hello', None, 'GAR', 'fg')])
204
registry = bzrdir.BzrDirFormatRegistry()
205
registry.register_metadir('one', 'RepositoryFormat7', 'one help')
206
registry.register_metadir('two',
209
registry = controldir.ControlDirFormatRegistry()
210
bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
211
bzrdir.register_metadir(registry, 'two',
207
212
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
314
319
self.assertEqual('hello', name)
315
320
self.assertEqual([], value)
322
def test_list_option_param_name(self):
323
"""Test list options can have their param_name set."""
324
options = [option.ListOption('hello', type=str, param_name='greeting')]
325
opts, args = self.parse(
326
options, ['--hello=world', '--hello=sailor'])
327
self.assertEqual(['world', 'sailor'], opts.greeting)
318
330
class TestOptionDefinitions(TestCase):
319
331
"""Tests for options in the Bazaar codebase."""
321
333
def get_builtin_command_options(self):
323
for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
335
for cmd_name in sorted(commands.all_command_names()):
336
cmd = commands.get_cmd_object(cmd_name)
325
337
for opt_name, opt in sorted(cmd.options().items()):
326
338
g.append((cmd_name, opt))
334
346
g = dict(option.Option.OPTIONS.items())
335
347
used_globals = {}
337
for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
338
for option_or_name in sorted(cmd_class.takes_options):
349
for cmd_name in sorted(commands.all_command_names()):
350
cmd = commands.get_cmd_object(cmd_name)
351
for option_or_name in sorted(cmd.takes_options):
339
352
if not isinstance(option_or_name, basestring):
340
353
self.assertIsInstance(option_or_name, option.Option)
341
354
elif not option_or_name in g:
342
355
msgs.append("apparent reference to undefined "
343
356
"global option %r from %r"
344
% (option_or_name, cmd_class))
357
% (option_or_name, cmd))
346
359
used_globals.setdefault(option_or_name, []).append(cmd_name)
347
360
unused_globals = set(g.keys()) - set(used_globals.keys())
374
387
+ '\n'.join(msgs))
376
389
def test_is_hidden(self):
377
registry = bzrdir.BzrDirFormatRegistry()
378
registry.register_metadir('hidden', 'HiddenFormat',
390
registry = controldir.ControlDirFormatRegistry()
391
bzrdir.register_metadir(registry, 'hidden', 'HiddenFormat',
379
392
'hidden help text', hidden=True)
380
registry.register_metadir('visible', 'VisibleFormat',
393
bzrdir.register_metadir(registry, 'visible', 'VisibleFormat',
381
394
'visible help text', hidden=False)
382
395
format = option.RegistryOption('format', '', registry, str)
383
396
self.assertTrue(format.is_hidden('hidden'))