~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-04-08 07:32:48 UTC
  • mfrom: (5138.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100408073248-aj7k8qkvbv4nzlxd
(igc for parthm) update -r dotted-revno support

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from cStringIO import StringIO
18
18
import errno
19
 
import inspect
20
19
import sys
21
20
 
22
21
from bzrlib import (
34
33
 
35
34
class TestCommands(tests.TestCase):
36
35
 
37
 
    def test_all_commands_have_help(self):
38
 
        commands._register_builtin_commands()
39
 
        commands_without_help = set()
40
 
        base_doc = inspect.getdoc(commands.Command)
41
 
        for cmd_name in commands.all_command_names():
42
 
            cmd = commands.get_cmd_object(cmd_name)
43
 
            cmd_help = cmd.help()
44
 
            if not cmd_help or cmd_help == base_doc:
45
 
                commands_without_help.append(cmd_name)
46
 
        self.assertLength(0, commands_without_help)
47
 
 
48
36
    def test_display_command(self):
49
37
        """EPIPE message is selectively suppressed"""
50
38
        def pipe_thrower():
77
65
    @staticmethod
78
66
    def get_command(options):
79
67
        class cmd_foo(commands.Command):
80
 
            __doc__ = 'Bar'
 
68
            'Bar'
81
69
 
82
70
            takes_options = options
83
71
 
95
83
class TestGetAlias(tests.TestCase):
96
84
 
97
85
    def _get_config(self, config_text):
98
 
        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)
99
89
        return my_config
100
90
 
101
91
    def test_simple(self):
130
120
class TestSeeAlso(tests.TestCase):
131
121
    """Tests for the see also functional of Command."""
132
122
 
133
 
    @staticmethod
134
 
    def _get_command_with_see_also(see_also):
135
 
        class ACommand(commands.Command):
136
 
            __doc__ = """A sample command."""
137
 
            _see_also = see_also
138
 
        return ACommand()
139
 
 
140
123
    def test_default_subclass_no_see_also(self):
141
 
        command = self._get_command_with_see_also([])
 
124
        class ACommand(commands.Command):
 
125
            """A sample command."""
 
126
        command = ACommand()
142
127
        self.assertEqual([], command.get_see_also())
143
128
 
144
129
    def test__see_also(self):
145
130
        """When _see_also is defined, it sets the result of get_see_also()."""
146
 
        command = self._get_command_with_see_also(['bar', 'foo'])
 
131
        class ACommand(commands.Command):
 
132
            _see_also = ['bar', 'foo']
 
133
        command = ACommand()
147
134
        self.assertEqual(['bar', 'foo'], command.get_see_also())
148
135
 
149
136
    def test_deduplication(self):
150
137
        """Duplicates in _see_also are stripped out."""
151
 
        command = self._get_command_with_see_also(['foo', 'foo'])
 
138
        class ACommand(commands.Command):
 
139
            _see_also = ['foo', 'foo']
 
140
        command = ACommand()
152
141
        self.assertEqual(['foo'], command.get_see_also())
153
142
 
154
143
    def test_sorted(self):
155
144
        """_see_also is sorted by get_see_also."""
156
 
        command = self._get_command_with_see_also(['foo', 'bar'])
 
145
        class ACommand(commands.Command):
 
146
            _see_also = ['foo', 'bar']
 
147
        command = ACommand()
157
148
        self.assertEqual(['bar', 'foo'], command.get_see_also())
158
149
 
159
150
    def test_additional_terms(self):
160
151
        """Additional terms can be supplied and are deduped and sorted."""
161
 
        command = self._get_command_with_see_also(['foo', 'bar'])
 
152
        class ACommand(commands.Command):
 
153
            _see_also = ['foo', 'bar']
 
154
        command = ACommand()
162
155
        self.assertEqual(['bar', 'foo', 'gam'],
163
156
            command.get_see_also(['gam', 'bar', 'gam']))
164
157
 
219
212
            "extend_command", hook_calls.append, None)
220
213
        # create a command, should not fire
221
214
        class cmd_test_extend_command_hook(commands.Command):
222
 
            __doc__ = """A sample command."""
 
215
            """A sample command."""
223
216
        self.assertEqual([], hook_calls)
224
217
        # -- as a builtin
225
218
        # register the command class, should not fire
256
249
        commands.install_bzr_command_hooks()
257
250
        hook_calls = []
258
251
        class ACommand(commands.Command):
259
 
            __doc__ = """A sample command."""
 
252
            """A sample command."""
260
253
        def get_cmd(cmd_or_None, cmd_name):
261
254
            hook_calls.append(('called', cmd_or_None, cmd_name))
262
255
            if cmd_name in ('foo', 'info'):
287
280
        """Hook get_missing_command for testing."""
288
281
        self.hook_calls = []
289
282
        class ACommand(commands.Command):
290
 
            __doc__ = """A sample command."""
 
283
            """A sample command."""
291
284
        def get_missing_cmd(cmd_name):
292
285
            self.hook_calls.append(('called', cmd_name))
293
286
            if cmd_name in ('foo', 'info'):
344
337
        self.assertEqual(['called'], hook_calls)
345
338
        self.assertSubset(['foo', 'bar'], cmds)
346
339
 
347
 
 
348
340
class TestDeprecations(tests.TestCase):
349
341
 
350
342
    def test_shlex_split_unicode_deprecation(self):