Rev 2832: Fix #59150 test suite failing when paramiko is not installed in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Sep 19 09:05:01 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2832
revision-id: pqm at pqm.ubuntu.com-20070919080453-w4ygh8iu73fdc25i
parent: pqm at pqm.ubuntu.com-20070918045733-es6jch43pxvogvhj
parent: v.ladeuil+lp at free.fr-20070919064455-y83e0ocrrackkirj
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-09-19 09:04:53 +0100
message:
  Fix #59150 test suite failing when paramiko is not installed
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
  bzrlib/tests/transport_util.py transportutil.py-20070525113600-5v2igk89s8fensom-1
    ------------------------------------------------------------
    revno: 2831.1.1
    merged: v.ladeuil+lp at free.fr-20070919064455-y83e0ocrrackkirj
    parent: pqm at pqm.ubuntu.com-20070918045733-es6jch43pxvogvhj
    parent: v.ladeuil+lp at free.fr-20070919064250-zczjpcv2rrlx612x
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: bzr.integration
    timestamp: Wed 2007-09-19 08:44:55 +0200
    message:
      Fix #59150 test suite failing when paramiko is not installed
    ------------------------------------------------------------
    revno: 2822.1.5
    merged: v.ladeuil+lp at free.fr-20070919064250-zczjpcv2rrlx612x
    parent: v.ladeuil+lp at free.fr-20070917065019-5ox8p0iqdj0cksr9
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 59150
    timestamp: Wed 2007-09-19 08:42:50 +0200
    message:
      Review feeback.
      
      * bzrlib/tests/transport_util.py (_change_scheme_in): 
      Fix indentation, replace [] with "".
    ------------------------------------------------------------
    revno: 2822.1.4
    merged: v.ladeuil+lp at free.fr-20070917065019-5ox8p0iqdj0cksr9
    parent: v.ladeuil+lp at free.fr-20070914111435-i0hy1wvvtjyttxas
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 59150
    timestamp: Mon 2007-09-17 08:50:19 +0200
    message:
      Review feedback.
    ------------------------------------------------------------
    revno: 2822.1.3
    merged: v.ladeuil+lp at free.fr-20070914111435-i0hy1wvvtjyttxas
    parent: v.ladeuil+lp at free.fr-20070914095138-rhrn8fx40we2stew
    committer: v.ladeuil+lp at free.fr
    branch nick: 59150
    timestamp: Fri 2007-09-14 13:14:35 +0200
    message:
      Fix backing transport and server usage for ftp support.
      
      * bzrlib/tests/transport_util.py:
      (InstrumentedTransport.__init__): Short-circuiting the backed
      transport constructor fails for ftp. Avoid the assertion while
      still modifying the scheme.
      (TestCaseWithConnectionHookedTransport.get_url): Respect the
      backing scheme when replacing it before talking to the backing
      server.
    ------------------------------------------------------------
    revno: 2822.1.2
    merged: v.ladeuil+lp at free.fr-20070914095138-rhrn8fx40we2stew
    parent: v.ladeuil+lp at free.fr-20070914093852-8cryaf9zpcfyva7a
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 59150
    timestamp: Fri 2007-09-14 11:51:38 +0200
    message:
      Spurious debug statement deleted.
    ------------------------------------------------------------
    revno: 2822.1.1
    merged: v.ladeuil+lp at free.fr-20070914093852-8cryaf9zpcfyva7a
    parent: pqm at pqm.ubuntu.com-20070914043128-s7ck70bf5bzefbiq
    committer: v.ladeuil+lp at free.fr
    branch nick: 59150
    timestamp: Fri 2007-09-14 11:38:52 +0200
    message:
      Fix #59150 (again) by handling paramiko availability for transport_util.py.
      
      * bzrlib/tests/transport_util.py: 
      Fallback to ftp if parmamiko is not available.
      
      * bzrlib/tests/test_sftp_transport.py: 
      Be more tolerant about paramiko being absent so that other tests
      can still import us.
=== modified file 'NEWS'
--- a/NEWS	2007-09-18 01:29:59 +0000
+++ b/NEWS	2007-09-19 06:44:55 +0000
@@ -47,6 +47,11 @@
 
    * Fix commit ordering in corner case (Aaron Bentley, #94975)
 
+   * Fallback to ftp when paramiko is not installed and sftp can't be used for
+     ``tests/commands`` so that the test suite is still usable without
+     paramiko.
+     (Vincent Ladeuil, #59150)
+
   API BREAKS:
 
    * The ``VersionedFile`` interface now allows content checks to be bypassed

=== modified file 'bzrlib/tests/test_sftp_transport.py'
--- a/bzrlib/tests/test_sftp_transport.py	2007-08-03 02:52:23 +0000
+++ b/bzrlib/tests/test_sftp_transport.py	2007-09-14 09:38:52 +0000
@@ -21,6 +21,12 @@
 import threading
 import time
 
+try:
+    import paramiko
+    paramiko_loaded = True
+except ImportError:
+    paramiko_loaded = False
+
 from bzrlib import (
     bzrdir,
     errors,
@@ -38,19 +44,16 @@
 from bzrlib.tests.HttpServer import HttpServer
 from bzrlib.transport import get_transport
 import bzrlib.transport.http
-from bzrlib.transport.sftp import (
-    SFTPAbsoluteServer,
-    SFTPHomeDirServer,
-    SFTPTransport,
-    )
+
+if paramiko_loaded:
+    from bzrlib.transport.sftp import (
+        SFTPAbsoluteServer,
+        SFTPHomeDirServer,
+        SFTPTransport,
+        )
+
 from bzrlib.workingtree import WorkingTree
 
-try:
-    import paramiko
-    paramiko_loaded = True
-except ImportError:
-    paramiko_loaded = False
-
 
 def set_test_transport_to_sftp(testcase):
     """A helper to set transports on test case instances."""

=== modified file 'bzrlib/tests/transport_util.py'
--- a/bzrlib/tests/transport_util.py	2007-07-22 15:44:59 +0000
+++ b/bzrlib/tests/transport_util.py	2007-09-19 06:42:50 +0000
@@ -14,38 +14,71 @@
 # 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_sftp_transport import TestCaseWithSFTPServer
+import bzrlib.hooks
+
+# SFTPTransport offers better performances but relies on paramiko, if paramiko
+# is not available, we fallback to FtpTransport
+from bzrlib.tests import test_sftp_transport
+if test_sftp_transport.paramiko_loaded:
+    from bzrlib.transport import sftp
+    _backing_scheme = 'sftp'
+    _backing_transport_class = sftp.SFTPTransport
+    _backing_test_class = test_sftp_transport.TestCaseWithSFTPServer
+else:
+    from bzrlib.transport import ftp
+    from bzrlib.tests import test_ftp_transport
+    _backing_scheme = 'ftp'
+    _backing_transport_class = ftp.FtpTransport
+    _backing_test_class = test_ftp_transport.TestCaseWithFTPServer
+
 from bzrlib.transport import (
+    ConnectedTransport,
     register_transport,
     register_urlparse_netloc_protocol,
     unregister_transport,
     _unregister_urlparse_netloc_protocol,
     )
-from bzrlib.transport.sftp import SFTPTransport
-
-
-class TransportHooks(Hooks):
+
+
+
+class TransportHooks(bzrlib.hooks.Hooks):
     """Dict-mapping hook name to a list of callables for transport hooks"""
 
     def __init__(self):
-        Hooks.__init__(self)
+        super(TransportHooks, self).__init__()
         # Invoked when the transport has just created a new connection.
         # The api signature is (transport, connection, credentials)
         self['_set_connection'] = []
 
 _hooked_scheme = 'hooked'
 
-class InstrumentedTransport(SFTPTransport):
+def _change_scheme_in(url, actual, desired):
+    if not url.startswith(actual + '://'):
+        raise AssertionError('url "%r" does not start with "%r]"'
+                             % (url, actual))
+    return desired + url[len(actual):]
+
+
+class InstrumentedTransport(_backing_transport_class):
     """Instrumented transport class to test commands behavior"""
 
     hooks = TransportHooks()
 
     def __init__(self, base, _from_transport=None):
         assert base.startswith(_hooked_scheme + '://')
-        # Avoid SFTPTransport assertion since we use a dedicated scheme
-        super(SFTPTransport, self).__init__(base,
-                                            _from_transport=_from_transport)
+        # We need to trick the backing transport class about the scheme used
+        # We'll do the reverse when we need to talk to the backing server
+        fake_base = _change_scheme_in(base, _hooked_scheme, _backing_scheme)
+        super(InstrumentedTransport, self).__init__(
+            fake_base, _from_transport=_from_transport)
+        # The following is needed to minimize the effects of our trick above
+        # while retaining the best compatibility.
+        self._scheme = _hooked_scheme
+        base = self._unsplit_url(self._scheme,
+                                 self._user, self._password,
+                                 self._host, self._port,
+                                 self._path)
+        super(ConnectedTransport, self).__init__(base)
 
 
 class ConnectionHookedTransport(InstrumentedTransport):
@@ -59,7 +92,7 @@
             hook(self, connection, credentials)
 
 
-class TestCaseWithConnectionHookedTransport(TestCaseWithSFTPServer):
+class TestCaseWithConnectionHookedTransport(_backing_test_class):
 
     def setUp(self):
         register_urlparse_netloc_protocol(_hooked_scheme)
@@ -76,8 +109,9 @@
     def get_url(self, relpath=None):
         super_self = super(TestCaseWithConnectionHookedTransport, self)
         url = super_self.get_url(relpath)
-        # Replace the sftp scheme by our own
-        url = _hooked_scheme + url[len('sftp'):]
+        # Replace the backing scheme by our own (see
+        # InstrumentedTransport.__init__)
+        url = _change_scheme_in(url, _backing_scheme, _hooked_scheme)
         return url
 
     def install_hooks(self):




More information about the bazaar-commits mailing list