~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Vincent Ladeuil
  • Date: 2010-04-06 10:12:42 UTC
  • mto: This revision was merged to the branch mainline in revision 5135.
  • Revision ID: v.ladeuil+lp@free.fr-20100406101242-rcg0zelo6y2ca808
Some more cleanup and typos.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 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
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
17
18
import errno
18
 
import inspect
19
19
import sys
20
20
 
21
21
from bzrlib import (
33
33
 
34
34
class TestCommands(tests.TestCase):
35
35
 
36
 
    def test_all_commands_have_help(self):
37
 
        commands._register_builtin_commands()
38
 
        commands_without_help = set()
39
 
        base_doc = inspect.getdoc(commands.Command)
40
 
        for cmd_name in commands.all_command_names():
41
 
            cmd = commands.get_cmd_object(cmd_name)
42
 
            cmd_help = cmd.help()
43
 
            if not cmd_help or cmd_help == base_doc:
44
 
                commands_without_help.append(cmd_name)
45
 
        self.assertLength(0, commands_without_help)
46
 
 
47
36
    def test_display_command(self):
48
37
        """EPIPE message is selectively suppressed"""
49
38
        def pipe_thrower():
76
65
    @staticmethod
77
66
    def get_command(options):
78
67
        class cmd_foo(commands.Command):
79
 
            __doc__ = 'Bar'
 
68
            'Bar'
80
69
 
81
70
            takes_options = options
82
71
 
91
80
        self.assertContainsRe(c.get_help_text(), '--foo')
92
81
 
93
82
 
94
 
class TestInvokedAs(tests.TestCase):
95
 
 
96
 
    def test_invoked_as(self):
97
 
        """The command object knows the actual name used to invoke it."""
98
 
        commands.install_bzr_command_hooks()
99
 
        commands._register_builtin_commands()
100
 
        # get one from the real get_cmd_object.
101
 
        c = commands.get_cmd_object('ci')
102
 
        self.assertIsInstance(c, builtins.cmd_commit)
103
 
        self.assertEquals(c.invoked_as, 'ci')
104
 
 
105
 
 
106
83
class TestGetAlias(tests.TestCase):
107
84
 
108
85
    def _get_config(self, config_text):
109
 
        my_config = config.GlobalConfig.from_string(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)
110
89
        return my_config
111
90
 
112
91
    def test_simple(self):
141
120
class TestSeeAlso(tests.TestCase):
142
121
    """Tests for the see also functional of Command."""
143
122
 
144
 
    @staticmethod
145
 
    def _get_command_with_see_also(see_also):
146
 
        class ACommand(commands.Command):
147
 
            __doc__ = """A sample command."""
148
 
            _see_also = see_also
149
 
        return ACommand()
150
 
 
151
123
    def test_default_subclass_no_see_also(self):
152
 
        command = self._get_command_with_see_also([])
 
124
        class ACommand(commands.Command):
 
125
            """A sample command."""
 
126
        command = ACommand()
153
127
        self.assertEqual([], command.get_see_also())
154
128
 
155
129
    def test__see_also(self):
156
130
        """When _see_also is defined, it sets the result of get_see_also()."""
157
 
        command = self._get_command_with_see_also(['bar', 'foo'])
 
131
        class ACommand(commands.Command):
 
132
            _see_also = ['bar', 'foo']
 
133
        command = ACommand()
158
134
        self.assertEqual(['bar', 'foo'], command.get_see_also())
159
135
 
160
136
    def test_deduplication(self):
161
137
        """Duplicates in _see_also are stripped out."""
162
 
        command = self._get_command_with_see_also(['foo', 'foo'])
 
138
        class ACommand(commands.Command):
 
139
            _see_also = ['foo', 'foo']
 
140
        command = ACommand()
163
141
        self.assertEqual(['foo'], command.get_see_also())
164
142
 
165
143
    def test_sorted(self):
166
144
        """_see_also is sorted by get_see_also."""
167
 
        command = self._get_command_with_see_also(['foo', 'bar'])
 
145
        class ACommand(commands.Command):
 
146
            _see_also = ['foo', 'bar']
 
147
        command = ACommand()
168
148
        self.assertEqual(['bar', 'foo'], command.get_see_also())
169
149
 
170
150
    def test_additional_terms(self):
171
151
        """Additional terms can be supplied and are deduped and sorted."""
172
 
        command = self._get_command_with_see_also(['foo', 'bar'])
 
152
        class ACommand(commands.Command):
 
153
            _see_also = ['foo', 'bar']
 
154
        command = ACommand()
173
155
        self.assertEqual(['bar', 'foo', 'gam'],
174
156
            command.get_see_also(['gam', 'bar', 'gam']))
175
157
 
230
212
            "extend_command", hook_calls.append, None)
231
213
        # create a command, should not fire
232
214
        class cmd_test_extend_command_hook(commands.Command):
233
 
            __doc__ = """A sample command."""
 
215
            """A sample command."""
234
216
        self.assertEqual([], hook_calls)
235
217
        # -- as a builtin
236
218
        # register the command class, should not fire
267
249
        commands.install_bzr_command_hooks()
268
250
        hook_calls = []
269
251
        class ACommand(commands.Command):
270
 
            __doc__ = """A sample command."""
 
252
            """A sample command."""
271
253
        def get_cmd(cmd_or_None, cmd_name):
272
254
            hook_calls.append(('called', cmd_or_None, cmd_name))
273
255
            if cmd_name in ('foo', 'info'):
298
280
        """Hook get_missing_command for testing."""
299
281
        self.hook_calls = []
300
282
        class ACommand(commands.Command):
301
 
            __doc__ = """A sample command."""
 
283
            """A sample command."""
302
284
        def get_missing_cmd(cmd_name):
303
285
            self.hook_calls.append(('called', cmd_name))
304
286
            if cmd_name in ('foo', 'info'):
355
337
        self.assertEqual(['called'], hook_calls)
356
338
        self.assertSubset(['foo', 'bar'], cmds)
357
339
 
358
 
 
359
340
class TestDeprecations(tests.TestCase):
360
341
 
361
342
    def test_shlex_split_unicode_deprecation(self):