1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
1
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
33
from bzrlib.errors import (DirectoryNotEmpty, NoSuchFile, FileExists,
34
LockError, NoSmartServer, PathError,
35
TransportNotPossible, ConnectionError,
34
from bzrlib.errors import (ConnectionError,
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.smart import medium
42
50
from bzrlib.transport import memory, remote
43
51
import bzrlib.transport
369
377
dir_mode=0777, create_parent_dir=True)
370
378
self.assertTransportMode(t, 'dir777', 0777)
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()
390
unicode_string = u'\u1234'
392
(AssertionError, UnicodeEncodeError),
393
t.put_bytes, 'foo', unicode_string)
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()
405
unicode_file = pyStringIO(u'\u1234')
406
self.assertRaises(UnicodeEncodeError, t.put_file, 'foo', unicode_file)
372
408
def test_put_multi(self):
373
409
t = self.get_transport()
1114
1150
transport = self.get_transport()
1116
1152
p = transport.local_abspath('.')
1117
except TransportNotPossible:
1118
pass # This is not a local transport
1153
except (errors.NotLocalUrl, TransportNotPossible), e:
1154
# should be formattable
1120
1157
self.assertEqual(getcwd(), p)