~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 13:38:56 UTC
  • mto: (6437.23.12 2.5)
  • mto: This revision was merged to the branch mainline in revision 6473.
  • Revision ID: jelmer@samba.org-20120220133856-v6vh35o51n21v5ru
Cope with repository being missing in more cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from cStringIO import StringIO
18
17
import errno
 
18
import inspect
19
19
import sys
20
20
 
21
21
from bzrlib import (
24
24
    config,
25
25
    errors,
26
26
    option,
27
 
    symbol_versioning,
28
27
    tests,
29
28
    )
30
29
from bzrlib.commands import display_command
33
32
 
34
33
class TestCommands(tests.TestCase):
35
34
 
 
35
    def test_all_commands_have_help(self):
 
36
        commands._register_builtin_commands()
 
37
        commands_without_help = set()
 
38
        base_doc = inspect.getdoc(commands.Command)
 
39
        for cmd_name in commands.all_command_names():
 
40
            cmd = commands.get_cmd_object(cmd_name)
 
41
            cmd_help = cmd.help()
 
42
            if not cmd_help or cmd_help == base_doc:
 
43
                commands_without_help.append(cmd_name)
 
44
        self.assertLength(0, commands_without_help)
 
45
 
36
46
    def test_display_command(self):
37
47
        """EPIPE message is selectively suppressed"""
38
48
        def pipe_thrower():
80
90
        self.assertContainsRe(c.get_help_text(), '--foo')
81
91
 
82
92
 
 
93
class TestInsideCommand(tests.TestCaseInTempDir):
 
94
 
 
95
    def test_command_see_config_overrides(self):
 
96
        def run(cmd):
 
97
            # We override the run() command method so we can observe the
 
98
            # overrides from inside.
 
99
            c = config.GlobalStack()
 
100
            self.assertEquals('12', c.get('xx'))
 
101
            self.assertEquals('foo', c.get('yy'))
 
102
        self.overrideAttr(builtins.cmd_rocks, 'run', run)
 
103
        self.run_bzr(['rocks', '-Oxx=12', '-Oyy=foo'])
 
104
        c = config.GlobalStack()
 
105
        # Ensure that we don't leak outside of the command
 
106
        self.assertEquals(None, c.get('xx'))
 
107
        self.assertEquals(None, c.get('yy'))
 
108
 
 
109
 
 
110
class TestInvokedAs(tests.TestCase):
 
111
 
 
112
    def test_invoked_as(self):
 
113
        """The command object knows the actual name used to invoke it."""
 
114
        commands.install_bzr_command_hooks()
 
115
        commands._register_builtin_commands()
 
116
        # get one from the real get_cmd_object.
 
117
        c = commands.get_cmd_object('ci')
 
118
        self.assertIsInstance(c, builtins.cmd_commit)
 
119
        self.assertEquals(c.invoked_as, 'ci')
 
120
 
 
121
 
83
122
class TestGetAlias(tests.TestCase):
84
123
 
85
124
    def _get_config(self, config_text):
86
 
        my_config = config.GlobalConfig()
87
 
        config_file = StringIO(config_text.encode('utf-8'))
88
 
        my_config._parser = my_config._get_parser(file=config_file)
 
125
        my_config = config.GlobalConfig.from_string(config_text)
89
126
        return my_config
90
127
 
91
128
    def test_simple(self):
333
370
        cmds = list(commands.all_command_names())
334
371
        self.assertEqual(['called'], hook_calls)
335
372
        self.assertSubset(['foo', 'bar'], cmds)
336
 
 
337
 
class TestDeprecations(tests.TestCase):
338
 
 
339
 
    def test_shlex_split_unicode_deprecation(self):
340
 
        res = self.applyDeprecated(
341
 
                symbol_versioning.deprecated_in((2, 2, 0)),
342
 
                commands.shlex_split_unicode, 'whatever')