~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_implementations.py

  • Committer: Robert Collins
  • Date: 2006-09-16 06:44:47 UTC
  • mfrom: (2014 +trunk)
  • mto: (2017.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2018.
  • Revision ID: robertc@robertcollins.net-20060916064447-99a2987e5485b5ea
Merge from bzr.dev, fixing found bugs handling 'has('/')' in MemoryTransport and SFTP transports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
        self.assertEqual(False, t.has_any(['c', 'c', 'c']))
92
92
        self.assertEqual(True, t.has_any(['b', 'b', 'b']))
93
93
 
 
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(''))
 
100
 
94
101
    def test_get(self):
95
102
        t = self.get_transport()
96
103
 
144
151
                             t.put, 'b', StringIO('file-like\ncontents\n'))
145
152
        self.check_transport_contents('file-like\ncontents\n', t, 'b')
146
153
 
 
154
        self.assertRaises(NoSuchFile,
 
155
                          self.applyDeprecated,
 
156
                          zero_eleven,
 
157
                          t.put, 'path/doesnt/exist/c', StringIO('contents'))
 
158
 
147
159
    def test_put_bytes(self):
148
160
        t = self.get_transport()
149
161
 
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')
402
414
 
 
415
    def test_put_permissions(self):
 
416
        t = self.get_transport()
 
417
 
 
418
        if t.is_readonly():
 
419
            return
 
420
        if not t._can_roundtrip_unix_modebits():
 
421
            # Can't roundtrip, so no need to run this test
 
422
            return
 
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)
 
439
 
 
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)
 
445
        
403
446
    def test_mkdir(self):
404
447
        t = self.get_transport()
405
448
 
998
1041
        self.failUnless(t2.has('d'))
999
1042
        self.failUnless(t3.has('b/d'))
1000
1043
 
 
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)
 
1061
 
 
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)
 
1067
 
 
1068
        # At the root, the URL must still end with / as its a directory
 
1069
        self.assertEqual(root_transport.base[-1], '/')
 
1070
 
 
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)
 
1077
 
 
1078
    def test_base_url(self):
 
1079
        t = self.get_transport()
 
1080
        self.assertEqual('/', t.base[-1])
 
1081
 
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'))
1033
1114
 
 
1115
        # This should work without raising an error.
 
1116
        transport.abspath("/")
 
1117
 
 
1118
        # the abspath of "/" and "/foo/.." should result in the same location
 
1119
        self.assertEqual(transport.abspath("/"), transport.abspath("/foo/.."))
 
1120
 
1034
1121
    def test_local_abspath(self):
1035
1122
        transport = self.get_transport()
1036
1123
        try:
1162
1249
        self.check_transport_contents('bar', transport2, 'foo')
1163
1250
 
1164
1251
    def test_lock_write(self):
 
1252
        """Test transport-level write locks.
 
1253
 
 
1254
        These are deprecated and transports may decline to support them.
 
1255
        """
1165
1256
        transport = self.get_transport()
1166
1257
        if transport.is_readonly():
1167
1258
            self.assertRaises(TransportNotPossible, transport.lock_write, 'foo')
1168
1259
            return
1169
1260
        transport.put_bytes('lock', '')
1170
 
        lock = transport.lock_write('lock')
 
1261
        try:
 
1262
            lock = transport.lock_write('lock')
 
1263
        except TransportNotPossible:
 
1264
            return
1171
1265
        # TODO make this consistent on all platforms:
1172
1266
        # self.assertRaises(LockError, transport.lock_write, 'lock')
1173
1267
        lock.unlock()
1174
1268
 
1175
1269
    def test_lock_read(self):
 
1270
        """Test transport-level read locks.
 
1271
 
 
1272
        These are deprecated and transports may decline to support them.
 
1273
        """
1176
1274
        transport = self.get_transport()
1177
1275
        if transport.is_readonly():
1178
1276
            file('lock', 'w').close()
1179
1277
        else:
1180
1278
            transport.put_bytes('lock', '')
1181
 
        lock = transport.lock_read('lock')
 
1279
        try:
 
1280
            lock = transport.lock_read('lock')
 
1281
        except TransportNotPossible:
 
1282
            return
1182
1283
        # TODO make this consistent on all platforms:
1183
1284
        # self.assertRaises(LockError, transport.lock_read, 'lock')
1184
1285
        lock.unlock()
1208
1309
        self.assertEqual(d[1], (9, '9'))
1209
1310
        self.assertEqual(d[2], (0, '0'))
1210
1311
        self.assertEqual(d[3], (3, '34'))
 
1312