~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_commands.py

  • Committer: Vincent Ladeuil
  • Date: 2007-06-06 13:52:02 UTC
  • mto: (2485.8.44 bzr.connection.sharing)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070606135202-mqhxcv6z57uce434
Fix merge multiple connections. Test suite *not* passing (sftp
refactoring pending but unrelated to merge).

* bzrlib/builtins.py:
(cmd_merge.run): Fix the multiple connections bug by reusing the
tramsport used to check for a bundle and keep all other used
transports in possible_transports.
(_merge_helper): Add a possible_transports parameter for
reuse.

* bzrlib/transport/__init__.py:
(Transport._reuse_for): By default, Transports are not reusable.
(ConnectedTransport._reuse_for): ConnectedTransports are reusable
under certain conditions.
(_urlRE): Fix misleading group name.
(_try_transport_factories): Moved after get_transport (another use
case for moved lines). The do_catching_redirections was
incorrectly inserted between get_transport and
_try_transport_factories.

* bzrlib/tests/test_transport.py:
(TestReusedTransports.test_reuse_same_transport)
(TestReusedTransports.test_don_t_reuse_different_transport): Add
more tests.

* bzrlib/merge.py:
(_get_tree, Merger.set_other): Add a possible_transports parameter
for reuse.

* bzrlib/bzrdir.py:
(BzrDir.open_containing): Add a possible_transports parameter for
reuse.

* bzrlib/branch.py:
(Branch.open_containing): Add a possible_transports parameter for
reuse.

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 sys
20
19
 
21
20
from bzrlib import (
22
 
    builtins,
23
21
    commands,
24
22
    config,
25
23
    errors,
136
134
        self.assertEqual(['bar', 'foo', 'gam'],
137
135
            command.get_see_also(['gam', 'bar', 'gam']))
138
136
 
139
 
 
140
 
class TestRegisterLazy(tests.TestCase):
141
 
 
142
 
    def setUp(self):
143
 
        import bzrlib.tests.fake_command
144
 
        del sys.modules['bzrlib.tests.fake_command']
145
 
        global lazy_command_imported
146
 
        lazy_command_imported = False
147
 
 
148
 
    @staticmethod
149
 
    def remove_fake():
150
 
        commands.plugin_cmds.remove('fake')
151
 
 
152
 
    def assertIsFakeCommand(self, cmd_obj):
153
 
        from bzrlib.tests.fake_command import cmd_fake
154
 
        self.assertIsInstance(cmd_obj, cmd_fake)
155
 
 
156
 
    def test_register_lazy(self):
157
 
        """Ensure lazy registration works"""
158
 
        commands.plugin_cmds.register_lazy('cmd_fake', [],
159
 
                                           'bzrlib.tests.fake_command')
160
 
        self.addCleanup(self.remove_fake)
161
 
        self.assertFalse(lazy_command_imported)
162
 
        fake_instance = commands.get_cmd_object('fake')
163
 
        self.assertTrue(lazy_command_imported)
164
 
        self.assertIsFakeCommand(fake_instance)
165
 
 
166
 
    def test_get_unrelated_does_not_import(self):
167
 
        commands.plugin_cmds.register_lazy('cmd_fake', [],
168
 
                                           'bzrlib.tests.fake_command')
169
 
        self.addCleanup(self.remove_fake)
170
 
        commands.get_cmd_object('status')
171
 
        self.assertFalse(lazy_command_imported)
172
 
 
173
 
    def test_aliases(self):
174
 
        commands.plugin_cmds.register_lazy('cmd_fake', ['fake_alias'],
175
 
                                           'bzrlib.tests.fake_command')
176
 
        self.addCleanup(self.remove_fake)
177
 
        fake_instance = commands.get_cmd_object('fake_alias')
178
 
        self.assertIsFakeCommand(fake_instance)
179
 
 
180
 
 
181
 
class TestExtendCommandHook(tests.TestCase):
182
 
 
183
 
    def test_fires_on_get_cmd_object(self):
184
 
        # The extend_command(cmd) hook fires when commands are delivered to the
185
 
        # ui, not simply at registration (because lazy registered plugin
186
 
        # commands are registered).
187
 
        # when they are simply created.
188
 
        hook_calls = []
189
 
        commands.Command.hooks.install_named_hook(
190
 
            "extend_command", hook_calls.append, None)
191
 
        # create a command, should not fire
192
 
        class ACommand(commands.Command):
193
 
            """A sample command."""
194
 
        cmd = ACommand()
195
 
        self.assertEqual([], hook_calls)
196
 
        # -- as a builtin
197
 
        # register the command class, should not fire
198
 
        try:
199
 
            builtins.cmd_test_extend_command_hook = ACommand
200
 
            self.assertEqual([], hook_calls)
201
 
            # and ask for the object, should fire
202
 
            cmd = commands.get_cmd_object('test-extend-command-hook')
203
 
            # For resilience - to ensure all code paths hit it - we
204
 
            # fire on everything returned in the 'cmd_dict', which is currently
205
 
            # all known commands, so assert that cmd is in hook_calls
206
 
            self.assertSubset([cmd], hook_calls)
207
 
            del hook_calls[:]
208
 
        finally:
209
 
            del builtins.cmd_test_extend_command_hook
210
 
        # -- as a plugin lazy registration
211
 
        try:
212
 
            # register the command class, should not fire
213
 
            commands.plugin_cmds.register_lazy('cmd_fake', [],
214
 
                                               'bzrlib.tests.fake_command')
215
 
            self.assertEqual([], hook_calls)
216
 
            # and ask for the object, should fire
217
 
            cmd = commands.get_cmd_object('fake')
218
 
            self.assertEqual([cmd], hook_calls)
219
 
        finally:
220
 
            commands.plugin_cmds.remove('fake')