/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_implementations.py

Upgraded to the latest bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import os
24
24
from cStringIO import StringIO
 
25
from StringIO import StringIO as pyStringIO
25
26
import stat
26
27
import sys
27
28
 
30
31
    osutils,
31
32
    urlutils,
32
33
    )
33
 
from bzrlib.errors import (DirectoryNotEmpty, NoSuchFile, FileExists,
34
 
                           LockError, NoSmartServer, PathError,
35
 
                           TransportNotPossible, ConnectionError,
36
 
                           InvalidURL)
 
34
from bzrlib.errors import (ConnectionError,
 
35
                           DirectoryNotEmpty,
 
36
                           FileExists,
 
37
                           InvalidURL,
 
38
                           LockError,
 
39
                           NoSmartServer,
 
40
                           NoSuchFile,
 
41
                           NotLocalUrl,
 
42
                           PathError,
 
43
                           TransportNotPossible,
 
44
                           )
37
45
from bzrlib.osutils import getcwd
 
46
from bzrlib.smart import medium
38
47
from bzrlib.symbol_versioning import zero_eleven
39
48
from bzrlib.tests import TestCaseInTempDir, TestSkipped
40
49
from bzrlib.tests.test_transport import TestTransportImplementation
41
 
from bzrlib.transport import memory, smart
 
50
from bzrlib.transport import memory, remote
42
51
import bzrlib.transport
43
52
 
44
53
 
45
 
def _append(fn, txt):
46
 
    """Append the given text (file-like object) to the supplied filename."""
47
 
    f = open(fn, 'ab')
48
 
    try:
49
 
        f.write(txt.read())
50
 
    finally:
51
 
        f.close()
52
 
 
53
 
 
54
54
class TransportTests(TestTransportImplementation):
55
55
 
 
56
    def setUp(self):
 
57
        super(TransportTests, self).setUp()
 
58
        self._captureVar('BZR_NO_SMART_VFS', None)
 
59
 
56
60
    def check_transport_contents(self, content, transport, relpath):
57
61
        """Check that transport.get(relpath).read() == content."""
58
62
        self.assertEqualDiff(content, transport.get(relpath).read())
373
377
                              dir_mode=0777, create_parent_dir=True)
374
378
        self.assertTransportMode(t, 'dir777', 0777)
375
379
 
 
380
    def test_put_bytes_unicode(self):
 
381
        # Expect put_bytes to raise AssertionError or UnicodeEncodeError if
 
382
        # given unicode "bytes".  UnicodeEncodeError doesn't really make sense
 
383
        # (we don't want to encode unicode here at all, callers should be
 
384
        # strictly passing bytes to put_bytes), but we allow it for backwards
 
385
        # compatibility.  At some point we should use a specific exception.
 
386
        # See https://bugs.launchpad.net/bzr/+bug/106898.
 
387
        t = self.get_transport()
 
388
        if t.is_readonly():
 
389
            return
 
390
        unicode_string = u'\u1234'
 
391
        self.assertRaises(
 
392
            (AssertionError, UnicodeEncodeError),
 
393
            t.put_bytes, 'foo', unicode_string)
 
394
 
 
395
    def test_put_file_unicode(self):
 
396
        # Like put_bytes, except with a StringIO.StringIO of a unicode string.
 
397
        # This situation can happen (and has) if code is careless about the type
 
398
        # of "string" they initialise/write to a StringIO with.  We cannot use
 
399
        # cStringIO, because it never returns unicode from read.
 
400
        # Like put_bytes, UnicodeEncodeError isn't quite the right exception to
 
401
        # raise, but we raise it for hysterical raisins.
 
402
        t = self.get_transport()
 
403
        if t.is_readonly():
 
404
            return
 
405
        unicode_file = pyStringIO(u'\u1234')
 
406
        self.assertRaises(UnicodeEncodeError, t.put_file, 'foo', unicode_file)
 
407
 
376
408
    def test_put_multi(self):
377
409
        t = self.get_transport()
378
410
 
1118
1150
        transport = self.get_transport()
1119
1151
        try:
1120
1152
            p = transport.local_abspath('.')
1121
 
        except TransportNotPossible:
 
1153
        except NotLocalUrl:
1122
1154
            pass # This is not a local transport
1123
1155
        else:
1124
1156
            self.assertEqual(getcwd(), p)
1315
1347
        transport = self.get_transport()
1316
1348
        try:
1317
1349
            client_medium = transport.get_smart_medium()
1318
 
            self.assertIsInstance(client_medium, smart.SmartClientMedium)
 
1350
            self.assertIsInstance(client_medium, medium.SmartClientMedium)
1319
1351
        except errors.NoSmartMedium:
1320
1352
            # as long as we got it we're fine
1321
1353
            pass