91
91
self.assertEqual(False, t.has_any(['c', 'c', 'c']))
92
92
self.assertEqual(True, t.has_any(['b', 'b', 'b']))
94
def test_has_root_works(self):
95
current_transport = self.get_transport()
96
# import pdb;pdb.set_trace()
97
self.assertTrue(current_transport.has('/'))
98
root = current_transport.clone('/')
99
self.assertTrue(root.has(''))
94
101
def test_get(self):
95
102
t = self.get_transport()
144
151
t.put, 'b', StringIO('file-like\ncontents\n'))
145
152
self.check_transport_contents('file-like\ncontents\n', t, 'b')
154
self.assertRaises(NoSuchFile,
155
self.applyDeprecated,
157
t.put, 'path/doesnt/exist/c', StringIO('contents'))
147
159
def test_put_bytes(self):
148
160
t = self.get_transport()
400
412
self.check_transport_contents('diff\ncontents for\na\n', t, 'a')
401
413
self.check_transport_contents('another contents\nfor d\n', t, 'd')
415
def test_put_permissions(self):
416
t = self.get_transport()
420
if not t._can_roundtrip_unix_modebits():
421
# Can't roundtrip, so no need to run this test
423
self.applyDeprecated(zero_eleven, t.put, 'mode644',
424
StringIO('test text\n'), mode=0644)
425
self.assertTransportMode(t, 'mode644', 0644)
426
self.applyDeprecated(zero_eleven, t.put, 'mode666',
427
StringIO('test text\n'), mode=0666)
428
self.assertTransportMode(t, 'mode666', 0666)
429
self.applyDeprecated(zero_eleven, t.put, 'mode600',
430
StringIO('test text\n'), mode=0600)
431
self.assertTransportMode(t, 'mode600', 0600)
432
# Yes, you can put a file such that it becomes readonly
433
self.applyDeprecated(zero_eleven, t.put, 'mode400',
434
StringIO('test text\n'), mode=0400)
435
self.assertTransportMode(t, 'mode400', 0400)
436
self.applyDeprecated(zero_eleven, t.put_multi,
437
[('mmode644', StringIO('text\n'))], mode=0644)
438
self.assertTransportMode(t, 'mmode644', 0644)
440
# The default permissions should be based on the current umask
441
umask = osutils.get_umask()
442
self.applyDeprecated(zero_eleven, t.put, 'nomode',
443
StringIO('test text\n'), mode=None)
444
self.assertTransportMode(t, 'nomode', 0666 & ~umask)
403
446
def test_mkdir(self):
404
447
t = self.get_transport()
998
1041
self.failUnless(t2.has('d'))
999
1042
self.failUnless(t3.has('b/d'))
1044
def test_clone_to_root(self):
1045
orig_transport = self.get_transport()
1046
# Repeatedly go up to a parent directory until we're at the root
1047
# directory of this transport
1048
root_transport = orig_transport
1049
new_transport = root_transport.clone("..")
1050
# as we are walking up directories, the path must be must be
1051
# growing less, except at the top
1052
self.assertTrue(len(new_transport.base) < len(root_transport.base)
1053
or new_transport.base == root_transport.base)
1054
while new_transport.base != root_transport.base:
1055
root_transport = new_transport
1056
new_transport = root_transport.clone("..")
1057
# as we are walking up directories, the path must be must be
1058
# growing less, except at the top
1059
self.assertTrue(len(new_transport.base) < len(root_transport.base)
1060
or new_transport.base == root_transport.base)
1062
# Cloning to "/" should take us to exactly the same location.
1063
self.assertEqual(root_transport.base, orig_transport.clone("/").base)
1064
# the abspath of "/" from the original transport should be the same
1065
# as the base at the root:
1066
self.assertEqual(orig_transport.abspath("/"), root_transport.base)
1068
# At the root, the URL must still end with / as its a directory
1069
self.assertEqual(root_transport.base[-1], '/')
1071
def test_clone_from_root(self):
1072
"""At the root, cloning to a simple dir should just do string append."""
1073
orig_transport = self.get_transport()
1074
root_transport = orig_transport.clone('/')
1075
self.assertEqual(root_transport.base + '.bzr/',
1076
root_transport.clone('.bzr').base)
1078
def test_base_url(self):
1079
t = self.get_transport()
1080
self.assertEqual('/', t.base[-1])
1001
1082
def test_relpath(self):
1002
1083
t = self.get_transport()
1003
1084
self.assertEqual('', t.relpath(t.base))
1031
1112
self.assertEqual(transport.base + 'relpath',
1032
1113
transport.abspath('relpath'))
1115
# This should work without raising an error.
1116
transport.abspath("/")
1118
# the abspath of "/" and "/foo/.." should result in the same location
1119
self.assertEqual(transport.abspath("/"), transport.abspath("/foo/.."))
1034
1121
def test_local_abspath(self):
1035
1122
transport = self.get_transport()
1162
1249
self.check_transport_contents('bar', transport2, 'foo')
1164
1251
def test_lock_write(self):
1252
"""Test transport-level write locks.
1254
These are deprecated and transports may decline to support them.
1165
1256
transport = self.get_transport()
1166
1257
if transport.is_readonly():
1167
1258
self.assertRaises(TransportNotPossible, transport.lock_write, 'foo')
1169
1260
transport.put_bytes('lock', '')
1170
lock = transport.lock_write('lock')
1262
lock = transport.lock_write('lock')
1263
except TransportNotPossible:
1171
1265
# TODO make this consistent on all platforms:
1172
1266
# self.assertRaises(LockError, transport.lock_write, 'lock')
1175
1269
def test_lock_read(self):
1270
"""Test transport-level read locks.
1272
These are deprecated and transports may decline to support them.
1176
1274
transport = self.get_transport()
1177
1275
if transport.is_readonly():
1178
1276
file('lock', 'w').close()
1180
1278
transport.put_bytes('lock', '')
1181
lock = transport.lock_read('lock')
1280
lock = transport.lock_read('lock')
1281
except TransportNotPossible:
1182
1283
# TODO make this consistent on all platforms:
1183
1284
# self.assertRaises(LockError, transport.lock_read, 'lock')