28
28
from bzrlib.errors import (DirectoryNotEmpty, NoSuchFile, FileExists,
31
TransportNotPossible, ConnectionError)
30
TransportNotPossible, ConnectionError,
32
from bzrlib.osutils import getcwd
32
33
from bzrlib.tests import TestCaseInTempDir, TestSkipped
33
from bzrlib.transport import memory, urlescape
34
from bzrlib.transport import memory
34
35
import bzrlib.transport
36
import bzrlib.urlutils as urlutils
37
39
def _append(fn, txt):
113
115
self.build_tree(files, transport=t)
114
116
self.assertEqual(True, t.has('a'))
115
117
self.assertEqual(False, t.has('c'))
116
self.assertEqual(True, t.has(urlescape('%')))
118
self.assertEqual(True, t.has(urlutils.escape('%')))
117
119
self.assertEqual(list(t.has_multi(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])),
118
120
[True, True, False, False, True, False, True, False])
119
121
self.assertEqual(True, t.has_any(['a', 'b', 'c']))
120
self.assertEqual(False, t.has_any(['c', 'd', 'f', urlescape('%%')]))
122
self.assertEqual(False, t.has_any(['c', 'd', 'f', urlutils.escape('%%')]))
121
123
self.assertEqual(list(t.has_multi(iter(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']))),
122
124
[True, True, False, False, True, False, True, False])
123
125
self.assertEqual(False, t.has_any(['c', 'c', 'c']))
279
281
transport_from, f)
281
283
t = self.get_transport()
282
temp_transport = MemoryTransport('memory:/')
284
temp_transport = MemoryTransport('memory:///')
283
285
simple_copy_files(t, temp_transport)
284
286
if not t.is_readonly():
285
287
t.mkdir('copy_to_simple')
299
301
t.copy_to(['e/f'], temp_transport)
301
303
del temp_transport
302
temp_transport = MemoryTransport('memory:/')
304
temp_transport = MemoryTransport('memory:///')
304
306
files = ['a', 'b', 'c', 'd']
305
307
t.copy_to(iter(files), temp_transport)
309
311
del temp_transport
311
313
for mode in (0666, 0644, 0600, 0400):
312
temp_transport = MemoryTransport("memory:/")
314
temp_transport = MemoryTransport("memory:///")
313
315
t.copy_to(files, temp_transport, mode=mode)
315
317
self.assertTransportMode(temp_transport, f, mode)
698
700
except NotImplementedError:
699
701
raise TestSkipped("Transport %s has no bogus URL support." %
700
702
self._server.__class__)
701
t = bzrlib.transport.get_transport(url)
704
t = bzrlib.transport.get_transport(url)
703
705
t.get('.bzr/branch')
704
706
except (ConnectionError, NoSuchFile), e:
859
861
self.assertEqual(transport.base + 'relpath',
860
862
transport.abspath('relpath'))
864
def test_local_abspath(self):
865
transport = self.get_transport()
867
p = transport.local_abspath('.')
868
except TransportNotPossible:
869
pass # This is not a local transport
871
self.assertEqual(getcwd(), p)
862
873
def test_abspath_at_root(self):
863
874
t = self.get_transport()
864
875
# clone all the way to the top
898
909
paths = set(sub_transport.iter_files_recursive())
899
910
self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
912
def test_unicode_paths(self):
913
"""Test that we can read/write files with Unicode names."""
914
t = self.get_transport()
916
files = [u'\xe5', # a w/ circle iso-8859-1
917
u'\xe4', # a w/ dots iso-8859-1
918
u'\u017d', # Z with umlat iso-8859-2
919
u'\u062c', # Arabic j
920
u'\u0410', # Russian A
921
u'\u65e5', # Kanji person
925
self.build_tree(files, transport=t, line_endings='binary')
927
raise TestSkipped("cannot handle unicode paths in current encoding")
929
# A plain unicode string is not a valid url
931
self.assertRaises(InvalidURL, t.get, fname)
934
fname_utf8 = fname.encode('utf-8')
935
contents = 'contents of %s\n' % (fname_utf8,)
936
self.check_transport_contents(contents, t, urlutils.escape(fname))
901
938
def test_connect_twice_is_same_content(self):
902
939
# check that our server (whatever it is) is accessable reliably
903
940
# via get_transport and multiple connections share content.