Rev 2490: Factor out InstrumentedTransport. in file:///v/home/vila/src/experimental/reuse.transports/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri May 25 12:38:42 BST 2007


At file:///v/home/vila/src/experimental/reuse.transports/

------------------------------------------------------------
revno: 2490
revision-id: v.ladeuil+lp at free.fr-20070525113840-s4puzzxhbspe6mop
parent: v.ladeuil+lp at free.fr-20070520173839-e5d44epigc5ungdh
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Fri 2007-05-25 13:38:40 +0200
message:
  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.
added:
  bzrlib/tests/TransportUtil.py  transportutil.py-20070525113600-5v2igk89s8fensom-1
modified:
  bzrlib/tests/commands/test_branch.py test_branch.py-20070520173042-ou3a796w3xn1y8ps-1
  bzrlib/tests/commands/test_init.py test_init.py-20070514074921-audbcdd8o56dpame-1
-------------- next part --------------
=== added file 'bzrlib/tests/TransportUtil.py'
--- a/bzrlib/tests/TransportUtil.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/TransportUtil.py	2007-05-25 11:38:40 +0000
@@ -0,0 +1,78 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+from bzrlib.hooks import Hooks
+from bzrlib.tests.test_ftp_transport import TestCaseWithFTPServer
+from bzrlib.transport import (
+    register_transport,
+    unregister_transport,
+    )
+from bzrlib.transport.ftp import FtpTransport
+
+
+class TransportHooks(Hooks):
+    """Dict-mapping hook name to a list of callables for transport hooks"""
+
+    def __init__(self):
+        Hooks.__init__(self)
+        # invoked when the transport is about to create or reuse
+        # an ftp connection. The api signature is (transport, ftp_instance)
+        self['get_FTP'] = []
+
+
+class InstrumentedTransport(FtpTransport):
+    """Instrumented transport class to test commands behavior"""
+
+    hooks = TransportHooks()
+
+
+class ConnectionHookedTransport(InstrumentedTransport):
+    """Transport instrumented to inspect connections"""
+
+    def _get_FTP(self):
+        """See FtpTransport._get_FTP.
+
+        This is where we can detect if the connection is reused
+        or if a new one is created. This a bit ugly, but it's the
+        easiest until transport classes are refactored.
+        """
+        instance = super(ConnectionHookedTransport, self)._get_FTP()
+        for hook in self.hooks['get_FTP']:
+            hook(self, instance)
+        return instance
+
+
+class TestCaseWithConnectionHookedTransport(TestCaseWithFTPServer):
+
+    def setUp(self):
+        super(TestCaseWithConnectionHookedTransport, self).setUp()
+        ConnectionHookedTransport.hooks.install_hook('get_FTP',
+                                                     self.get_connection_hook)
+        # Make our instrumented transport the default ftp transport
+        register_transport('ftp://', ConnectionHookedTransport)
+
+        def cleanup():
+            InstrumentedTransport.hooks = TransportHooks()
+            unregister_transport('ftp://', ConnectionHookedTransport)
+
+        self.addCleanup(cleanup)
+        self.connections = []
+
+    def get_connection_hook(self, transport, connection):
+        if connection is not None and connection not in self.connections:
+            self.connections.append(connection)
+

=== modified file 'bzrlib/tests/commands/test_branch.py'
--- a/bzrlib/tests/commands/test_branch.py	2007-05-20 17:38:39 +0000
+++ b/bzrlib/tests/commands/test_branch.py	2007-05-25 11:38:40 +0000
@@ -15,66 +15,11 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-import os
-
 from bzrlib.builtins import cmd_branch
-from bzrlib.hooks import Hooks
-from bzrlib.tests.test_ftp_transport import TestCaseWithFTPServer
-from bzrlib.transport import (
-    register_transport,
-    unregister_transport,
-    )
-from bzrlib.transport.ftp import FtpTransport
-
-
-class TransportHooks(Hooks):
-    """Dict-mapping hook name to a list of callables for transport hooks"""
-
-    def __init__(self):
-        Hooks.__init__(self)
-        # invoked when the transport is about to create or reuse
-        # an ftp connection. The api signature is (transport, ftp_instance)
-        self['get_FTP'] = []
-
-
-class InstrumentedTransport(FtpTransport):
-    """Instrumented transport class to test use by init command"""
-
-    hooks = TransportHooks()
-
-    def _get_FTP(self):
-        """See FtpTransport._get_FTP.
-
-        This is where we can detect if the connection is reused
-        or if a new one is created. This a bit ugly, but it's the
-        easiest until transport classes are refactored.
-        """
-        instance = super(InstrumentedTransport, self)._get_FTP()
-        for hook in self.hooks['get_FTP']:
-            hook(self, instance)
-        return instance
-
-
-class TestBranch(TestCaseWithFTPServer):
-
-    def setUp(self):
-        super(TestBranch, self).setUp()
-        InstrumentedTransport.hooks.install_hook('get_FTP',
-                                                 self.get_connection_hook)
-        # Make our instrumented transport the default ftp transport
-        register_transport('ftp://', InstrumentedTransport)
-
-        def cleanup():
-            InstrumentedTransport.hooks = TransportHooks()
-            unregister_transport('ftp://', InstrumentedTransport)
-
-        self.addCleanup(cleanup)
-        self.connections = []
-
-
-    def get_connection_hook(self, transport, connection):
-        if connection is not None and connection not in self.connections:
-            self.connections.append(connection)
+from bzrlib.tests.TransportUtil import TestCaseWithConnectionHookedTransport
+
+
+class TestBranch(TestCaseWithConnectionHookedTransport):
 
     def test_branch_locally(self):
         self.make_branch_and_tree('branch')
@@ -84,7 +29,11 @@
 
 # FIXME: Bug in ftp transport suspected, neither of the two
 # cmd.run() variants can finish, we get stucked somewhere in a
-# rename....
+# rename.... Have a look at changes introduced in revno 2423 ?
+# Done, reverting the -r 2422.2423 patch makes things better but
+# BzrDir.sprout still try to create a working tree without
+# checking that the path is local and the test still hangs
+# (server shutdown missing ?). Needs more investigation.
 
 #    def test_branch_remotely(self):
 #        self.make_branch_and_tree('branch')

=== modified file 'bzrlib/tests/commands/test_init.py'
--- a/bzrlib/tests/commands/test_init.py	2007-05-20 17:38:39 +0000
+++ b/bzrlib/tests/commands/test_init.py	2007-05-25 11:38:40 +0000
@@ -15,66 +15,10 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-import os
-
 from bzrlib.builtins import cmd_init
-from bzrlib.hooks import Hooks
-from bzrlib.tests.test_ftp_transport import TestCaseWithFTPServer
-from bzrlib.transport import (
-    register_transport,
-    unregister_transport,
-    )
-from bzrlib.transport.ftp import FtpTransport
-
-
-class TransportHooks(Hooks):
-    """Dict-mapping hook name to a list of callables for transport hooks"""
-
-    def __init__(self):
-        Hooks.__init__(self)
-        # invoked when the transport is about to create or reuse
-        # an ftp connection. The api signature is (transport, ftp_instance)
-        self['get_FTP'] = []
-
-
-class InstrumentedTransport(FtpTransport):
-    """Instrumented transport class to test use by init command"""
-
-    hooks = TransportHooks()
-
-    def _get_FTP(self):
-        """See FtpTransport._get_FTP.
-
-        This is where we can detect if the connection is reused
-        or if a new one is created. This a bit ugly, but it's the
-        easiest until transport classes are refactored.
-        """
-        instance = super(InstrumentedTransport, self)._get_FTP()
-        for hook in self.hooks['get_FTP']:
-            hook(self, instance)
-        return instance
-
-
-class TestInit(TestCaseWithFTPServer):
-
-    def setUp(self):
-        super(TestInit, self).setUp()
-        InstrumentedTransport.hooks.install_hook('get_FTP',
-                                                 self.get_connection_hook)
-        # Make our instrumented transport the default ftp transport
-        register_transport('ftp://', InstrumentedTransport)
-
-        def cleanup():
-            InstrumentedTransport.hooks = TransportHooks()
-            unregister_transport('ftp://', InstrumentedTransport)
-
-        self.addCleanup(cleanup)
-        self.connections = []
-
-
-    def get_connection_hook(self, transport, connection):
-        if connection is not None and connection not in self.connections:
-            self.connections.append(connection)
+from bzrlib.tests.TransportUtil import TestCaseWithConnectionHookedTransport
+
+class TestInit(TestCaseWithConnectionHookedTransport):
 
     def test_init(self):
         cmd = cmd_init()



More information about the bazaar-commits mailing list