~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

[merge] win32

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from bzrlib.tests import TestCase, TestCaseInTempDir
24
24
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
25
25
from bzrlib.transport import memory, urlescape
 
26
from bzrlib.osutils import pathjoin
26
27
 
27
28
 
28
29
def _append(fn, txt):
95
96
        self.assertEqual(open('a', 'rb').read(), t.get('a').read())
96
97
        content_f = t.get_multi(files)
97
98
        for path,f in zip(files, content_f):
98
 
            self.assertEqual(open(path).read(), f.read())
 
99
            self.assertEqual(f.read(), open(path, 'rb').read())
99
100
 
100
101
        content_f = t.get_multi(iter(files))
101
102
        for path,f in zip(files, content_f):
102
 
            self.assertEqual(f.read(), open(path).read())
 
103
            self.assertEqual(f.read(), open(path, 'rb').read())
103
104
 
104
105
        self.assertRaises(NoSuchFile, t.get, 'c')
105
106
        self.assertListRaises(NoSuchFile, t.get_multi, ['a', 'b', 'c'])
278
279
                             ('dir_b/b', 'contents of dir_b/b')])
279
280
                          , 2)
280
281
        for f in ('dir_a/a', 'dir_b/b'):
281
 
            self.assertEqual(t.get(f).read(), open(f).read())
 
282
            self.assertEqual(t.get(f).read(), open(f, 'rb').read())
282
283
 
283
284
    def test_copy_to(self):
284
285
        import tempfile
295
296
 
296
297
        t.copy_to(files, local_t)
297
298
        for f in files:
298
 
            self.assertEquals(open(f).read(),
299
 
                    open(os.path.join(dtmp_base, f)).read())
 
299
            self.assertEquals(open(f, 'rb').read(),
 
300
                    open(pathjoin(dtmp_base, f), 'rb').read())
300
301
 
301
302
        # Test that copying into a missing directory raises
302
303
        # NoSuchFile
304
305
        open('e/f', 'wb').write('contents of e')
305
306
        self.assertRaises(NoSuchFile, t.copy_to, ['e/f'], local_t)
306
307
 
307
 
        os.mkdir(os.path.join(dtmp_base, 'e'))
 
308
        os.mkdir(pathjoin(dtmp_base, 'e'))
308
309
        t.copy_to(['e/f'], local_t)
309
310
 
310
311
        del dtmp, dtmp_base, local_t
316
317
        files = ['a', 'b', 'c', 'd']
317
318
        t.copy_to(iter(files), local_t)
318
319
        for f in files:
319
 
            self.assertEquals(open(f).read(),
320
 
                    open(os.path.join(dtmp_base, f)).read())
 
320
            self.assertEquals(open(f, 'rb').read(),
 
321
                    open(pathjoin(dtmp_base, f), 'rb').read())
321
322
 
322
323
        del dtmp, dtmp_base, local_t
323
324
 
654
655
            self.assertRaises(TransportNotPossible, t.list_dir, '.')
655
656
            return
656
657
 
 
658
        def sorted_list(d):
 
659
            l = list(t.list_dir(d))
 
660
            l.sort()
 
661
            return l
 
662
 
657
663
        # SftpServer creates control files in the working directory
658
664
        # so lets move down a directory to be safe
659
665
        os.mkdir('wd')
660
666
        os.chdir('wd')
661
667
        t = t.clone('wd')
662
668
 
663
 
        self.assertEqual([], list(t.list_dir('.')))
 
669
        self.assertEqual([], sorted_list(u'.'))
664
670
        self.build_tree(['a', 'b', 'c/', 'c/d', 'c/e'])
665
671
 
666
 
        self.assertEqual(['a', 'b', 'c'], list(t.list_dir('.')))
667
 
        self.assertEqual(['d', 'e'], list(t.list_dir('c')))
 
672
        self.assertEqual([u'a', u'b', u'c'], sorted_list(u'.'))
 
673
        self.assertEqual([u'd', u'e'], sorted_list(u'c'))
668
674
 
669
675
        os.remove('c/d')
670
676
        os.remove('b')
671
 
        self.assertEqual(['a', 'c'], list(t.list_dir('.')))
672
 
        self.assertEqual(['e'], list(t.list_dir('c')))
 
677
        self.assertEqual([u'a', u'c'], sorted_list('.'))
 
678
        self.assertEqual([u'e'], sorted_list(u'c'))
673
679
 
674
680
        self.assertListRaises(NoSuchFile, t.list_dir, 'q')
675
681
        self.assertListRaises(NoSuchFile, t.list_dir, 'c/f')