Rev 6341: (gz) Avoid using run_bzr_subprocess in a bt.test_sftp_transport test (Martin in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Dec 5 10:59:57 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6341 [merge]
revision-id: pqm at pqm.ubuntu.com-20111205105956-2sswur26splv04w8
parent: pqm at pqm.ubuntu.com-20111205101444-58xei8jjp03xy10w
parent: martin.packman at canonical.com-20111205095249-4geybv49bpljygrj
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-12-05 10:59:56 +0000
message:
(gz) Avoid using run_bzr_subprocess in a bt.test_sftp_transport test (Martin
Packman)
modified:
bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
bzrlib/transport/ssh.py ssh.py-20060824042150-0s9787kng6zv1nwq-1
=== modified file 'bzrlib/tests/test_sftp_transport.py'
--- a/bzrlib/tests/test_sftp_transport.py 2011-09-26 15:21:01 +0000
+++ b/bzrlib/tests/test_sftp_transport.py 2011-12-05 09:52:49 +0000
@@ -279,9 +279,12 @@
self.addCleanup(s.close)
self.bogus_url = 'sftp://%s:%s/' % s.getsockname()
- def set_vendor(self, vendor):
+ def set_vendor(self, vendor, subprocess_stderr=None):
from bzrlib.transport import ssh
self.overrideAttr(ssh._ssh_vendor_manager, '_cached_ssh_vendor', vendor)
+ if subprocess_stderr is not None:
+ self.overrideAttr(ssh.SubprocessVendor, "_stderr_target",
+ subprocess_stderr)
def test_bad_connection_paramiko(self):
"""Test that a real connection attempt raises the right error"""
@@ -292,32 +295,16 @@
def test_bad_connection_ssh(self):
"""None => auto-detect vendor"""
- self.set_vendor(None)
- # This is how I would normally test the connection code
- # it makes it very clear what we are testing.
- # However, 'ssh' will create stipple on the output, so instead
- # I'm using run_bzr_subprocess, and parsing the output
- # try:
- # t = _mod_transport.get_transport(self.bogus_url)
- # except errors.ConnectionError:
- # # Correct error
- # pass
- # except errors.NameError, e:
- # if 'SSHException' in str(e):
- # raise TestSkipped('Known NameError bug in paramiko 1.6.1')
- # raise
- # else:
- # self.fail('Excepted ConnectionError to be raised')
-
- out, err = self.run_bzr_subprocess(['log', self.bogus_url], retcode=3)
- self.assertEqual('', out)
- if "NameError: global name 'SSHException'" in err:
- # We aren't fixing this bug, because it is a bug in
- # paramiko, but we know about it, so we don't have to
- # fail the test
- raise TestSkipped('Known NameError bug with paramiko-1.6.1')
- self.assertContainsRe(err, r'bzr: ERROR: Unable to connect to SSH host'
- r' 127\.0\.0\.1:\d+; ')
+ f = file(os.devnull, "wb")
+ self.addCleanup(f.close)
+ self.set_vendor(None, f)
+ t = _mod_transport.get_transport_from_url(self.bogus_url)
+ try:
+ self.assertRaises(errors.ConnectionError, t.get, 'foobar')
+ except NameError, e:
+ if "global name 'SSHException'" in str(e):
+ self.knownFailure('Known NameError bug in paramiko 1.6.1')
+ raise
class SFTPLatencyKnob(TestCaseWithSFTPServer):
=== modified file 'bzrlib/transport/ssh.py'
--- a/bzrlib/transport/ssh.py 2011-05-16 13:39:39 +0000
+++ b/bzrlib/transport/ssh.py 2011-12-01 17:00:50 +0000
@@ -352,6 +352,11 @@
class SubprocessVendor(SSHVendor):
"""Abstract base class for vendors that use pipes to a subprocess."""
+ # In general stderr should be inherited from the parent process so prompts
+ # are visible on the terminal. This can be overriden to another file for
+ # tests, but beware of using PIPE which may hang due to not being read.
+ _stderr_target = None
+
def _connect(self, argv):
# Attempt to make a socketpair to use as stdin/stdout for the SSH
# subprocess. We prefer sockets to pipes because they support
@@ -368,6 +373,7 @@
else:
stdin = stdout = subproc_sock
proc = subprocess.Popen(argv, stdin=stdin, stdout=stdout,
+ stderr=self._stderr_target,
**os_specific_subprocess_params())
if subproc_sock is not None:
subproc_sock.close()
More information about the bazaar-commits
mailing list