~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_sftp_transport.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

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.addAttrCleanup(ssh._ssh_vendor_manager, '_cached_ssh_vendor')
 
316
        ssh._ssh_vendor_manager._cached_ssh_vendor = vendor
322
317
 
323
318
    def test_bad_connection_paramiko(self):
324
319
        """Test that a real connection attempt raises the right error"""