~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: Vincent Ladeuil
  • Date: 2009-04-27 16:10:10 UTC
  • mto: (4310.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4311.
  • Revision ID: v.ladeuil+lp@free.fr-20090427161010-7swfzeagf63cpixd
Fix bug #367726 by reverting some default user handling introduced
while fixing bug #256612.

* bzrlib/transport/ssh.py:
(_paramiko_auth): Explicitly use getpass.getuser() as default
user.

* bzrlib/transport/ftp/_gssapi.py:
(GSSAPIFtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/transport/ftp/__init__.py:
(FtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/tests/test_sftp_transport.py:
(TestUsesAuthConfig.test_sftp_is_none_if_no_config)
(TestUsesAuthConfig.test_sftp_doesnt_prompt_username): Revert to
None as the default user.

* bzrlib/tests/test_remote.py:
(TestRemoteSSHTransportAuthentication): The really offending one:
revert to None as the default user.

* bzrlib/tests/test_config.py:
(TestAuthenticationConfig.test_username_default_no_prompt): Update
test (and some PEP8).

* bzrlib/smtp_connection.py:
(SMTPConnection._authenticate): Revert to None as the default
user.

* bzrlib/plugins/launchpad/account.py:
(_get_auth_user): Revert default value handling.

* bzrlib/config.py:
(AuthenticationConfig.get_user): Fix doc-string. Leave default
value handling to callers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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,
23
22
    errors,
24
23
    option,
25
24
    )
108
107
        self.assertFalse(option.Option('foo', hidden=False).is_hidden('foo'))
109
108
 
110
109
    def test_registry_conversion(self):
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
        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
114
            'two help', hidden=True)
116
115
        registry.set_default('one')
117
116
        options = [option.RegistryOption('format', '', registry, str)]
178
177
        self.assertEqual('test option', my_option.help)
179
178
 
180
179
    def test_help(self):
181
 
        registry = controldir.ControlDirFormatRegistry()
182
 
        bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
183
 
        bzrdir.register_metadir(registry, 'two',
 
180
        registry = bzrdir.BzrDirFormatRegistry()
 
181
        registry.register_metadir('one', 'RepositoryFormat7', 'one help')
 
182
        registry.register_metadir('two',
184
183
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
185
184
            'two help',
186
185
            )
187
 
        bzrdir.register_metadir(registry, 'hidden', 'RepositoryFormat7', 'hidden help',
 
186
        registry.register_metadir('hidden', 'RepositoryFormat7', 'hidden help',
188
187
            hidden=True)
189
188
        registry.set_default('one')
190
189
        options = [option.RegistryOption('format', 'format help', registry,
206
205
        opt = option.Option('hello', help='fg', type=int, argname='gar')
207
206
        self.assertEqual(list(opt.iter_switches()),
208
207
                         [('hello', None, 'GAR', 'fg')])
209
 
        registry = controldir.ControlDirFormatRegistry()
210
 
        bzrdir.register_metadir(registry, 'one', 'RepositoryFormat7', 'one help')
211
 
        bzrdir.register_metadir(registry, 'two',
 
208
        registry = bzrdir.BzrDirFormatRegistry()
 
209
        registry.register_metadir('one', 'RepositoryFormat7', 'one help')
 
210
        registry.register_metadir('two',
212
211
                'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
213
212
                'two help',
214
213
                )
319
318
        self.assertEqual('hello', name)
320
319
        self.assertEqual([], value)
321
320
 
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
 
 
329
321
 
330
322
class TestOptionDefinitions(TestCase):
331
323
    """Tests for options in the Bazaar codebase."""
332
324
 
333
325
    def get_builtin_command_options(self):
334
326
        g = []
335
 
        for cmd_name in sorted(commands.all_command_names()):
336
 
            cmd = commands.get_cmd_object(cmd_name)
 
327
        for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
 
328
            cmd = cmd_class()
337
329
            for opt_name, opt in sorted(cmd.options().items()):
338
330
                g.append((cmd_name, opt))
339
331
        return g
346
338
        g = dict(option.Option.OPTIONS.items())
347
339
        used_globals = {}
348
340
        msgs = []
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):
 
341
        for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
 
342
            for option_or_name in sorted(cmd_class.takes_options):
352
343
                if not isinstance(option_or_name, basestring):
353
344
                    self.assertIsInstance(option_or_name, option.Option)
354
345
                elif not option_or_name in g:
355
346
                    msgs.append("apparent reference to undefined "
356
347
                        "global option %r from %r"
357
 
                        % (option_or_name, cmd))
 
348
                        % (option_or_name, cmd_class))
358
349
                else:
359
350
                    used_globals.setdefault(option_or_name, []).append(cmd_name)
360
351
        unused_globals = set(g.keys()) - set(used_globals.keys())
387
378
                    + '\n'.join(msgs))
388
379
 
389
380
    def test_is_hidden(self):
390
 
        registry = controldir.ControlDirFormatRegistry()
391
 
        bzrdir.register_metadir(registry, 'hidden', 'HiddenFormat',
 
381
        registry = bzrdir.BzrDirFormatRegistry()
 
382
        registry.register_metadir('hidden', 'HiddenFormat',
392
383
            'hidden help text', hidden=True)
393
 
        bzrdir.register_metadir(registry, 'visible', 'VisibleFormat',
 
384
        registry.register_metadir('visible', 'VisibleFormat',
394
385
            'visible help text', hidden=False)
395
386
        format = option.RegistryOption('format', '', registry, str)
396
387
        self.assertTrue(format.is_hidden('hidden'))