~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testtransport.py

[merge] robertc's integration, updated tests to check for retcode=3

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
from cStringIO import StringIO
20
20
 
21
 
from bzrlib.errors import NoSuchFile, FileExists, TransportNotPossible
 
21
from bzrlib.errors import (NoSuchFile, FileExists, TransportNotPossible,
 
22
                           ConnectionError)
22
23
from bzrlib.selftest import TestCase, TestCaseInTempDir
23
24
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
24
25
from bzrlib.transport import memory, urlescape
65
66
        self.assertEqual(t.has(urlescape('%')), True)
66
67
        self.assertEqual(list(t.has_multi(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])),
67
68
                [True, True, False, False, True, False, True, False])
 
69
        self.assertEqual(t.has_any(['a', 'b', 'c']), True)
 
70
        self.assertEqual(t.has_any(['c', 'd', 'f', urlescape('%%')]), False)
68
71
        self.assertEqual(list(t.has_multi(iter(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']))),
69
72
                [True, True, False, False, True, False, True, False])
 
73
        self.assertEqual(t.has_any(['c', 'c', 'c']), False)
 
74
        self.assertEqual(t.has_any(['b', 'b', 'b']), True)
70
75
 
71
76
    def test_get(self):
72
77
        t = self.get_transport()
291
296
            self.assertEquals(open(f).read(),
292
297
                    open(os.path.join(dtmp_base, f)).read())
293
298
 
 
299
        # Test that copying into a missing directory raises
 
300
        # NoSuchFile
 
301
        os.mkdir('e')
 
302
        open('e/f', 'wb').write('contents of e')
 
303
        self.assertRaises(NoSuchFile, t.copy_to, ['e/f'], local_t)
 
304
 
 
305
        os.mkdir(os.path.join(dtmp_base, 'e'))
 
306
        t.copy_to(['e/f'], local_t)
 
307
 
294
308
        del dtmp, dtmp_base, local_t
295
309
 
296
310
        dtmp = tempfile.mkdtemp(dir='.', prefix='test-transport-')
450
464
        # TODO: Test Transport.move
451
465
        pass
452
466
 
 
467
    def test_connection_error(self):
 
468
        """ConnectionError is raised when connection is impossible"""
 
469
        if not hasattr(self, "get_bogus_transport"):
 
470
            return
 
471
        t = self.get_bogus_transport()
 
472
        self.assertRaises(ConnectionError, t.get, '.bzr/branch')
453
473
 
 
474
        
454
475
class LocalTransportTest(TestCaseInTempDir, TestTransportMixIn):
455
476
    def get_transport(self):
456
477
        from bzrlib.transport.local import LocalTransport
466
487
        url = self.get_remote_url('.')
467
488
        return HttpTransport(url)
468
489
 
 
490
    def get_bogus_transport(self):
 
491
        from bzrlib.transport.http import HttpTransport
 
492
        return HttpTransport('http://jasldkjsalkdjalksjdkljasd')
 
493
 
469
494
 
470
495
class TestMemoryTransport(TestCase):
471
496
 
556
581
        transport.put('bar', StringIO('phowar'))
557
582
        self.assertEqual(7, transport.stat('foo').st_size)
558
583
        self.assertEqual(6, transport.stat('bar').st_size)
559
 
        
 
584