~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Martin Pool
  • Date: 2010-03-15 06:54:44 UTC
  • mto: This revision was merged to the branch mainline in revision 5095.
  • Revision ID: mbp@canonical.com-20100315065444-gfs7vp8te4ez5rc9
Fix typo in ReadVFile.readline (thanks mnordhoff)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2004, 2005 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
65
65
    @staticmethod
66
66
    def get_command(options):
67
67
        class cmd_foo(commands.Command):
68
 
            __doc__ = 'Bar'
 
68
            'Bar'
69
69
 
70
70
            takes_options = options
71
71
 
120
120
class TestSeeAlso(tests.TestCase):
121
121
    """Tests for the see also functional of Command."""
122
122
 
123
 
    @staticmethod
124
 
    def _get_command_with_see_also(see_also):
125
 
        class ACommand(commands.Command):
126
 
            __doc__ = """A sample command."""
127
 
            _see_also = see_also
128
 
        return ACommand()
129
 
 
130
123
    def test_default_subclass_no_see_also(self):
131
 
        command = self._get_command_with_see_also([])
 
124
        class ACommand(commands.Command):
 
125
            """A sample command."""
 
126
        command = ACommand()
132
127
        self.assertEqual([], command.get_see_also())
133
128
 
134
129
    def test__see_also(self):
135
130
        """When _see_also is defined, it sets the result of get_see_also()."""
136
 
        command = self._get_command_with_see_also(['bar', 'foo'])
 
131
        class ACommand(commands.Command):
 
132
            _see_also = ['bar', 'foo']
 
133
        command = ACommand()
137
134
        self.assertEqual(['bar', 'foo'], command.get_see_also())
138
135
 
139
136
    def test_deduplication(self):
140
137
        """Duplicates in _see_also are stripped out."""
141
 
        command = self._get_command_with_see_also(['foo', 'foo'])
 
138
        class ACommand(commands.Command):
 
139
            _see_also = ['foo', 'foo']
 
140
        command = ACommand()
142
141
        self.assertEqual(['foo'], command.get_see_also())
143
142
 
144
143
    def test_sorted(self):
145
144
        """_see_also is sorted by get_see_also."""
146
 
        command = self._get_command_with_see_also(['foo', 'bar'])
 
145
        class ACommand(commands.Command):
 
146
            _see_also = ['foo', 'bar']
 
147
        command = ACommand()
147
148
        self.assertEqual(['bar', 'foo'], command.get_see_also())
148
149
 
149
150
    def test_additional_terms(self):
150
151
        """Additional terms can be supplied and are deduped and sorted."""
151
 
        command = self._get_command_with_see_also(['foo', 'bar'])
 
152
        class ACommand(commands.Command):
 
153
            _see_also = ['foo', 'bar']
 
154
        command = ACommand()
152
155
        self.assertEqual(['bar', 'foo', 'gam'],
153
156
            command.get_see_also(['gam', 'bar', 'gam']))
154
157
 
208
211
        commands.Command.hooks.install_named_hook(
209
212
            "extend_command", hook_calls.append, None)
210
213
        # create a command, should not fire
211
 
        class cmd_test_extend_command_hook(commands.Command):
212
 
            __doc__ = """A sample command."""
 
214
        class ACommand(commands.Command):
 
215
            """A sample command."""
 
216
        cmd = ACommand()
213
217
        self.assertEqual([], hook_calls)
214
218
        # -- as a builtin
215
219
        # register the command class, should not fire
216
220
        try:
217
 
            commands.builtin_command_registry.register(cmd_test_extend_command_hook)
 
221
            builtins.cmd_test_extend_command_hook = ACommand
218
222
            self.assertEqual([], hook_calls)
219
223
            # and ask for the object, should fire
220
224
            cmd = commands.get_cmd_object('test-extend-command-hook')
224
228
            self.assertSubset([cmd], hook_calls)
225
229
            del hook_calls[:]
226
230
        finally:
227
 
            commands.builtin_command_registry.remove('test-extend-command-hook')
 
231
            del builtins.cmd_test_extend_command_hook
228
232
        # -- as a plugin lazy registration
229
233
        try:
230
234
            # register the command class, should not fire
246
250
        commands.install_bzr_command_hooks()
247
251
        hook_calls = []
248
252
        class ACommand(commands.Command):
249
 
            __doc__ = """A sample command."""
 
253
            """A sample command."""
250
254
        def get_cmd(cmd_or_None, cmd_name):
251
255
            hook_calls.append(('called', cmd_or_None, cmd_name))
252
256
            if cmd_name in ('foo', 'info'):
277
281
        """Hook get_missing_command for testing."""
278
282
        self.hook_calls = []
279
283
        class ACommand(commands.Command):
280
 
            __doc__ = """A sample command."""
 
284
            """A sample command."""
281
285
        def get_missing_cmd(cmd_name):
282
286
            self.hook_calls.append(('called', cmd_name))
283
287
            if cmd_name in ('foo', 'info'):