~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_implementations.py

  • Committer: Martin Pool
  • Date: 2006-06-20 07:55:43 UTC
  • mfrom: (1798 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060620075543-b10f6575d4a4fa32
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import sys
27
27
 
28
28
from bzrlib.errors import (DirectoryNotEmpty, NoSuchFile, FileExists,
29
 
                           LockError,
30
 
                           PathError,
31
 
                           TransportNotPossible, ConnectionError)
 
29
                           LockError, PathError,
 
30
                           TransportNotPossible, ConnectionError,
 
31
                           InvalidURL)
 
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
35
37
 
36
38
 
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)
280
282
 
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)
300
302
 
301
303
        del temp_transport
302
 
        temp_transport = MemoryTransport('memory:/')
 
304
        temp_transport = MemoryTransport('memory:///')
303
305
 
304
306
        files = ['a', 'b', 'c', 'd']
305
307
        t.copy_to(iter(files), temp_transport)
309
311
        del temp_transport
310
312
 
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)
314
316
            for f in files:
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)
702
703
        try:
 
704
            t = bzrlib.transport.get_transport(url)
703
705
            t.get('.bzr/branch')
704
706
        except (ConnectionError, NoSuchFile), e:
705
707
            pass
859
861
        self.assertEqual(transport.base + 'relpath',
860
862
                         transport.abspath('relpath'))
861
863
 
 
864
    def test_local_abspath(self):
 
865
        transport = self.get_transport()
 
866
        try:
 
867
            p = transport.local_abspath('.')
 
868
        except TransportNotPossible:
 
869
            pass # This is not a local transport
 
870
        else:
 
871
            self.assertEqual(getcwd(), p)
 
872
 
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)
900
911
 
 
912
    def test_unicode_paths(self):
 
913
        """Test that we can read/write files with Unicode names."""
 
914
        t = self.get_transport()
 
915
 
 
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
 
922
                ]
 
923
 
 
924
        try:
 
925
            self.build_tree(files, transport=t, line_endings='binary')
 
926
        except UnicodeError:
 
927
            raise TestSkipped("cannot handle unicode paths in current encoding")
 
928
 
 
929
        # A plain unicode string is not a valid url
 
930
        for fname in files:
 
931
            self.assertRaises(InvalidURL, t.get, fname)
 
932
 
 
933
        for fname in files:
 
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))
 
937
 
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.