~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
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 (
20
20
    bzrdir,
21
21
    commands,
 
22
    controldir,
22
23
    errors,
23
24
    option,
24
25
    )
102
103
        self.assertRaises(errors.BzrCommandError, self.parse, options,
103
104
                          ['--no-number'])
104
105
 
 
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'))
 
109
 
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)
174
179
 
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',
180
185
            'two help',
181
186
            )
182
 
        registry.register_metadir('hidden', 'RepositoryFormat7', 'hidden help',
 
187
        bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormat7', 'hidden help',
183
188
            hidden=True)
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',
208
213
                'two help',
209
214
                )
314
319
        self.assertEqual('hello', name)
315
320
        self.assertEqual([], value)
316
321
 
 
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)
 
328
 
317
329
 
318
330
class TestOptionDefinitions(TestCase):
319
331
    """Tests for options in the Bazaar codebase."""
320
332
 
321
333
    def get_builtin_command_options(self):
322
334
        g = []
323
 
        for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
324
 
            cmd = cmd_class()
 
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))
327
339
        return g
334
346
        g = dict(option.Option.OPTIONS.items())
335
347
        used_globals = {}
336
348
        msgs = []
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))
345
358
                else:
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))
375
388
 
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'))