~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/commands/test_branch.py

  • Committer: Vincent Ladeuil
  • Date: 2007-05-25 11:38:40 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-20070525113840-s4puzzxhbspe6mop
Factor out InstrumentedTransport.

* bzrlib/tests/commands/test_init.py: 
Simplified by using TransportUtils

* bzrlib/tests/commands/test_branch.py: 
Simplified by using TransportUtils

* bzrlib/tests/TransportUtil.py: 
Factored out from commands/test_init.py and
commands/test_branch.py. Another use case for tracking lines moved
across files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
import os
19
 
 
20
18
from bzrlib.builtins import cmd_branch
21
 
from bzrlib.hooks import Hooks
22
 
from bzrlib.tests.test_ftp_transport import TestCaseWithFTPServer
23
 
from bzrlib.transport import (
24
 
    register_transport,
25
 
    unregister_transport,
26
 
    )
27
 
from bzrlib.transport.ftp import FtpTransport
28
 
 
29
 
 
30
 
class TransportHooks(Hooks):
31
 
    """Dict-mapping hook name to a list of callables for transport hooks"""
32
 
 
33
 
    def __init__(self):
34
 
        Hooks.__init__(self)
35
 
        # invoked when the transport is about to create or reuse
36
 
        # an ftp connection. The api signature is (transport, ftp_instance)
37
 
        self['get_FTP'] = []
38
 
 
39
 
 
40
 
class InstrumentedTransport(FtpTransport):
41
 
    """Instrumented transport class to test use by init command"""
42
 
 
43
 
    hooks = TransportHooks()
44
 
 
45
 
    def _get_FTP(self):
46
 
        """See FtpTransport._get_FTP.
47
 
 
48
 
        This is where we can detect if the connection is reused
49
 
        or if a new one is created. This a bit ugly, but it's the
50
 
        easiest until transport classes are refactored.
51
 
        """
52
 
        instance = super(InstrumentedTransport, self)._get_FTP()
53
 
        for hook in self.hooks['get_FTP']:
54
 
            hook(self, instance)
55
 
        return instance
56
 
 
57
 
 
58
 
class TestBranch(TestCaseWithFTPServer):
59
 
 
60
 
    def setUp(self):
61
 
        super(TestBranch, self).setUp()
62
 
        InstrumentedTransport.hooks.install_hook('get_FTP',
63
 
                                                 self.get_connection_hook)
64
 
        # Make our instrumented transport the default ftp transport
65
 
        register_transport('ftp://', InstrumentedTransport)
66
 
 
67
 
        def cleanup():
68
 
            InstrumentedTransport.hooks = TransportHooks()
69
 
            unregister_transport('ftp://', InstrumentedTransport)
70
 
 
71
 
        self.addCleanup(cleanup)
72
 
        self.connections = []
73
 
 
74
 
 
75
 
    def get_connection_hook(self, transport, connection):
76
 
        if connection is not None and connection not in self.connections:
77
 
            self.connections.append(connection)
 
19
from bzrlib.tests.TransportUtil import TestCaseWithConnectionHookedTransport
 
20
 
 
21
 
 
22
class TestBranch(TestCaseWithConnectionHookedTransport):
78
23
 
79
24
    def test_branch_locally(self):
80
25
        self.make_branch_and_tree('branch')
84
29
 
85
30
# FIXME: Bug in ftp transport suspected, neither of the two
86
31
# cmd.run() variants can finish, we get stucked somewhere in a
87
 
# rename....
 
32
# rename.... Have a look at changes introduced in revno 2423 ?
 
33
# Done, reverting the -r 2422.2423 patch makes things better but
 
34
# BzrDir.sprout still try to create a working tree without
 
35
# checking that the path is local and the test still hangs
 
36
# (server shutdown missing ?). Needs more investigation.
88
37
 
89
38
#    def test_branch_remotely(self):
90
39
#        self.make_branch_and_tree('branch')