~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_implementations.py

  • Committer: John Arbash Meinel
  • Date: 2006-12-01 19:41:16 UTC
  • mfrom: (2158 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2159.
  • Revision ID: john@arbash-meinel.com-20061201194116-nvn5qhfxux5284jc
[merge] bzr.dev 2158

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from bzrlib.symbol_versioning import zero_eleven
39
39
from bzrlib.tests import TestCaseInTempDir, TestSkipped
40
40
from bzrlib.tests.test_transport import TestTransportImplementation
41
 
from bzrlib.transport import memory, smart
 
41
from bzrlib.transport import memory, smart, chroot
42
42
import bzrlib.transport
43
43
 
44
44
 
57
57
        """Check that transport.get(relpath).read() == content."""
58
58
        self.assertEqualDiff(content, transport.get(relpath).read())
59
59
 
60
 
    def assertListRaises(self, excClass, func, *args, **kwargs):
61
 
        """Fail unless excClass is raised when the iterator from func is used.
62
 
        
63
 
        Many transport functions can return generators this makes sure
64
 
        to wrap them in a list() call to make sure the whole generator
65
 
        is run, and that the proper exception is raised.
66
 
        """
67
 
        try:
68
 
            list(func(*args, **kwargs))
69
 
        except excClass:
70
 
            return
71
 
        else:
72
 
            if getattr(excClass,'__name__', None) is not None:
73
 
                excName = excClass.__name__
74
 
            else:
75
 
                excName = str(excClass)
76
 
            raise self.failureException, "%s not raised" % excName
77
 
 
78
60
    def test_has(self):
79
61
        t = self.get_transport()
80
62
 
94
76
 
95
77
    def test_has_root_works(self):
96
78
        current_transport = self.get_transport()
97
 
        # import pdb;pdb.set_trace()
 
79
        if isinstance(current_transport, chroot.ChrootTransportDecorator):
 
80
            raise TestSkipped("ChrootTransportDecorator disallows clone('..')")
98
81
        self.assertTrue(current_transport.has('/'))
99
82
        root = current_transport.clone('/')
100
83
        self.assertTrue(root.has(''))
961
944
            l.sort()
962
945
            return l
963
946
 
964
 
        # SftpServer creates control files in the working directory
965
 
        # so lets move down a directory to avoid those.
966
 
        if not t.is_readonly():
967
 
            t.mkdir('wd')
968
 
        else:
969
 
            os.mkdir('wd')
970
 
        t = t.clone('wd')
971
 
 
972
947
        self.assertEqual([], sorted_list('.'))
973
948
        # c2 is precisely one letter longer than c here to test that
974
949
        # suffixing is not confused.
975
950
        # a%25b checks that quoting is done consistently across transports
976
951
        tree_names = ['a', 'a%25b', 'b', 'c/', 'c/d', 'c/e', 'c2/']
 
952
 
977
953
        if not t.is_readonly():
978
954
            self.build_tree(tree_names, transport=t)
979
955
        else:
980
 
            self.build_tree(['wd/' + name for name in tree_names])
 
956
            self.build_tree(tree_names)
981
957
 
982
958
        self.assertEqual(
983
959
            ['a', 'a%2525b', 'b', 'c', 'c2'], sorted_list('.'))
987
963
            t.delete('c/d')
988
964
            t.delete('b')
989
965
        else:
990
 
            os.unlink('wd/c/d')
991
 
            os.unlink('wd/b')
 
966
            os.unlink('c/d')
 
967
            os.unlink('b')
992
968
            
993
969
        self.assertEqual(['a', 'a%2525b', 'c', 'c2'], sorted_list('.'))
994
970
        self.assertEqual(['e'], sorted_list('c'))
1014
990
    def test_clone(self):
1015
991
        # TODO: Test that clone moves up and down the filesystem
1016
992
        t1 = self.get_transport()
 
993
        if isinstance(t1, chroot.ChrootTransportDecorator):
 
994
            raise TestSkipped("ChrootTransportDecorator disallows clone('..')")
1017
995
 
1018
996
        self.build_tree(['a', 'b/', 'b/c'], transport=t1)
1019
997
 
1046
1024
 
1047
1025
    def test_clone_to_root(self):
1048
1026
        orig_transport = self.get_transport()
 
1027
        if isinstance(orig_transport, chroot.ChrootTransportDecorator):
 
1028
            raise TestSkipped("ChrootTransportDecorator disallows clone('..')")
1049
1029
        # Repeatedly go up to a parent directory until we're at the root
1050
1030
        # directory of this transport
1051
1031
        root_transport = orig_transport
1074
1054
    def test_clone_from_root(self):
1075
1055
        """At the root, cloning to a simple dir should just do string append."""
1076
1056
        orig_transport = self.get_transport()
 
1057
        if isinstance(orig_transport, chroot.ChrootTransportDecorator):
 
1058
            raise TestSkipped("ChrootTransportDecorator disallows clone('/')")
1077
1059
        root_transport = orig_transport.clone('/')
1078
1060
        self.assertEqual(root_transport.base + '.bzr/',
1079
1061
            root_transport.clone('.bzr').base)
1094
1076
 
1095
1077
    def test_relpath_at_root(self):
1096
1078
        t = self.get_transport()
 
1079
        if isinstance(t, chroot.ChrootTransportDecorator):
 
1080
            raise TestSkipped("ChrootTransportDecorator disallows clone('..')")
1097
1081
        # clone all the way to the top
1098
1082
        new_transport = t.clone('..')
1099
1083
        while new_transport.base != t.base:
1109
1093
        # that have aliasing problems like symlinks should go in backend
1110
1094
        # specific test cases.
1111
1095
        transport = self.get_transport()
 
1096
        if isinstance(transport, chroot.ChrootTransportDecorator):
 
1097
            raise TestSkipped("ChrootTransportDecorator disallows clone('..')")
1112
1098
        
1113
1099
        self.assertEqual(transport.base + 'relpath',
1114
1100
                         transport.abspath('relpath'))
1133
1119
 
1134
1120
    def test_abspath_at_root(self):
1135
1121
        t = self.get_transport()
 
1122
        if isinstance(t, chroot.ChrootTransportDecorator):
 
1123
            raise TestSkipped("ChrootTransportDecorator disallows clone('..')")
1136
1124
        # clone all the way to the top
1137
1125
        new_transport = t.clone('..')
1138
1126
        while new_transport.base != t.base:
1237
1225
        # check that our server (whatever it is) is accessable reliably
1238
1226
        # via get_transport and multiple connections share content.
1239
1227
        transport = self.get_transport()
 
1228
        if isinstance(transport, chroot.ChrootTransportDecorator):
 
1229
            raise TestSkipped("ChrootTransportDecorator disallows clone('..')")
1240
1230
        if transport.is_readonly():
1241
1231
            return
1242
1232
        transport.put_bytes('foo', 'bar')
1295
1285
        else:
1296
1286
            transport.put_bytes('a', '0123456789')
1297
1287
 
 
1288
        d = list(transport.readv('a', ((0, 1),)))
 
1289
        self.assertEqual(d[0], (0, '0'))
 
1290
 
1298
1291
        d = list(transport.readv('a', ((0, 1), (1, 1), (3, 2), (9, 1))))
1299
1292
        self.assertEqual(d[0], (0, '0'))
1300
1293
        self.assertEqual(d[1], (1, '1'))