~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp_transport.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-26 10:49:57 UTC
  • mfrom: (4987.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100126104957-dmtqnc0pckuruyla
(vila,
        jam) Implement TestCase.overrideAttr to simplify tests setUp/cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
302
302
    def setUp(self):
303
303
        self.requireFeature(features.paramiko)
304
304
        super(SSHVendorBadConnection, self).setUp()
305
 
        import bzrlib.transport.ssh
306
305
 
307
306
        # open a random port, so we know nobody else is using it
308
307
        # but don't actually listen on the port.
309
308
        s = socket.socket()
310
309
        s.bind(('localhost', 0))
 
310
        self.addCleanup(s.close)
311
311
        self.bogus_url = 'sftp://%s:%s/' % s.getsockname()
312
312
 
313
 
        orig_vendor = bzrlib.transport.ssh._ssh_vendor_manager._cached_ssh_vendor
314
 
        def reset():
315
 
            bzrlib.transport.ssh._ssh_vendor_manager._cached_ssh_vendor = orig_vendor
316
 
            s.close()
317
 
        self.addCleanup(reset)
318
 
 
319
313
    def set_vendor(self, vendor):
320
 
        import bzrlib.transport.ssh
321
 
        bzrlib.transport.ssh._ssh_vendor_manager._cached_ssh_vendor = vendor
 
314
        from bzrlib.transport import ssh
 
315
        self.overrideAttr(ssh._ssh_vendor_manager, '_cached_ssh_vendor', vendor)
322
316
 
323
317
    def test_bad_connection_paramiko(self):
324
318
        """Test that a real connection attempt raises the right error"""