~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-03-08 14:31:23 UTC
  • mfrom: (1598 +trunk)
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060308143123-448308b0db4de410
[merge] bzr.dev 1573, lots of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 by Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
25
25
import stat
26
26
import sys
27
27
 
28
 
from bzrlib.errors import (NoSuchFile, FileExists,
29
 
                           LockError,
 
28
from bzrlib.errors import (DirectoryNotEmpty, NoSuchFile, FileExists,
 
29
                           LockError, PathError,
30
30
                           TransportNotPossible, ConnectionError,
31
31
                           InvalidURL)
32
32
from bzrlib.tests import TestCaseInTempDir, TestSkipped
231
231
        self.assertRaises(FileExists, t.mkdir, 'dir_g')
232
232
 
233
233
        # Test get/put in sub-directories
234
 
        self.assertEqual(
 
234
        self.assertEqual(2, 
235
235
            t.put_multi([('dir_a/a', StringIO('contents of dir_a/a')),
236
 
                         ('dir_b/b', StringIO('contents of dir_b/b'))])
237
 
                        , 2)
 
236
                         ('dir_b/b', StringIO('contents of dir_b/b'))]))
238
237
        self.check_transport_contents('contents of dir_a/a', t, 'dir_a/a')
239
238
        self.check_transport_contents('contents of dir_b/b', t, 'dir_b/b')
240
239
 
268
267
        def simple_copy_files(transport_from, transport_to):
269
268
            files = ['a', 'b', 'c', 'd']
270
269
            self.build_tree(files, transport=transport_from)
271
 
            transport_from.copy_to(files, transport_to)
 
270
            self.assertEqual(4, transport_from.copy_to(files, transport_to))
272
271
            for f in files:
273
272
                self.check_transport_contents(transport_to.get(f).read(),
274
273
                                              transport_from, f)
326
325
                    t.append, 'a', 'add\nsome\nmore\ncontents\n')
327
326
            _append('a', StringIO('add\nsome\nmore\ncontents\n'))
328
327
        else:
329
 
            t.append('a', StringIO('add\nsome\nmore\ncontents\n'))
 
328
            self.assertEqual(20,
 
329
                t.append('a', StringIO('add\nsome\nmore\ncontents\n')))
330
330
 
331
331
        self.check_transport_contents(
332
332
            'diff\ncontents for\na\nadd\nsome\nmore\ncontents\n',
340
340
            _append('a', StringIO('and\nthen\nsome\nmore\n'))
341
341
            _append('b', StringIO('some\nmore\nfor\nb\n'))
342
342
        else:
343
 
            t.append_multi([('a', StringIO('and\nthen\nsome\nmore\n')),
344
 
                    ('b', StringIO('some\nmore\nfor\nb\n'))])
 
343
            self.assertEqual((43, 15), 
 
344
                t.append_multi([('a', StringIO('and\nthen\nsome\nmore\n')),
 
345
                                ('b', StringIO('some\nmore\nfor\nb\n'))]))
345
346
        self.check_transport_contents(
346
347
            'diff\ncontents for\na\n'
347
348
            'add\nsome\nmore\ncontents\n'
356
357
            _append('a', StringIO('a little bit more\n'))
357
358
            _append('b', StringIO('from an iterator\n'))
358
359
        else:
359
 
            t.append_multi(iter([('a', StringIO('a little bit more\n')),
360
 
                    ('b', StringIO('from an iterator\n'))]))
 
360
            self.assertEqual((62, 31),
 
361
                t.append_multi(iter([('a', StringIO('a little bit more\n')),
 
362
                                     ('b', StringIO('from an iterator\n'))])))
361
363
        self.check_transport_contents(
362
364
            'diff\ncontents for\na\n'
363
365
            'add\nsome\nmore\ncontents\n'
375
377
            _append('a', StringIO('some text in a\n'))
376
378
            _append('d', StringIO('missing file r\n'))
377
379
        else:
378
 
            t.append('c', StringIO('some text\nfor a missing file\n'))
379
 
            t.append_multi([('a', StringIO('some text in a\n')),
380
 
                            ('d', StringIO('missing file r\n'))])
 
380
            self.assertEqual(0,
 
381
                t.append('c', StringIO('some text\nfor a missing file\n')))
 
382
            self.assertEqual((80, 0),
 
383
                t.append_multi([('a', StringIO('some text in a\n')),
 
384
                                ('d', StringIO('missing file r\n'))]))
381
385
        self.check_transport_contents(
382
386
            'diff\ncontents for\na\n'
383
387
            'add\nsome\nmore\ncontents\n'
553
557
        t.rmdir('adir')
554
558
        self.assertRaises(NoSuchFile, t.stat, 'adir')
555
559
 
 
560
    def test_rmdir_not_empty(self):
 
561
        """Deleting a non-empty directory raises an exception
 
562
        
 
563
        sftp (and possibly others) don't give us a specific "directory not
 
564
        empty" exception -- we can just see that the operation failed.
 
565
        """
 
566
        t = self.get_transport()
 
567
        if t.is_readonly():
 
568
            return
 
569
        t.mkdir('adir')
 
570
        t.mkdir('adir/bdir')
 
571
        self.assertRaises(PathError, t.rmdir, 'adir')
 
572
 
 
573
    def test_rename_dir_succeeds(self):
 
574
        t = self.get_transport()
 
575
        if t.is_readonly():
 
576
            raise TestSkipped("transport is readonly")
 
577
        t.mkdir('adir')
 
578
        t.mkdir('adir/asubdir')
 
579
        t.rename('adir', 'bdir')
 
580
        self.assertTrue(t.has('bdir/asubdir'))
 
581
        self.assertFalse(t.has('adir'))
 
582
 
 
583
    def test_rename_dir_nonempty(self):
 
584
        """Attempting to replace a nonemtpy directory should fail"""
 
585
        t = self.get_transport()
 
586
        if t.is_readonly():
 
587
            raise TestSkipped("transport is readonly")
 
588
        t.mkdir('adir')
 
589
        t.mkdir('adir/asubdir')
 
590
        t.mkdir('bdir')
 
591
        t.mkdir('bdir/bsubdir')
 
592
        self.assertRaises(PathError, t.rename, 'bdir', 'adir')
 
593
        # nothing was changed so it should still be as before
 
594
        self.assertTrue(t.has('bdir/bsubdir'))
 
595
        self.assertFalse(t.has('adir/bdir'))
 
596
        self.assertFalse(t.has('adir/bsubdir'))
 
597
 
556
598
    def test_delete_tree(self):
557
599
        t = self.get_transport()
558
600
 
791
833
    def test_iter_files_recursive(self):
792
834
        transport = self.get_transport()
793
835
        if not transport.listable():
794
 
            self.assertRaises(TransportNotPossible, 
 
836
            self.assertRaises(TransportNotPossible,
795
837
                              transport.iter_files_recursive)
796
838
            return
797
 
        self.build_tree(['isolated/', 
 
839
        self.build_tree(['isolated/',
798
840
                         'isolated/dir/',
799
841
                         'isolated/dir/foo',
800
842
                         'isolated/dir/bar',
801
843
                         'isolated/bar'],
802
844
                        transport=transport)
803
 
        transport = transport.clone('isolated')
804
845
        paths = set(transport.iter_files_recursive())
 
846
        # nb the directories are not converted
 
847
        self.assertEqual(paths,
 
848
                    set(['isolated/dir/foo',
 
849
                         'isolated/dir/bar',
 
850
                         'isolated/bar']))
 
851
        sub_transport = transport.clone('isolated')
 
852
        paths = set(sub_transport.iter_files_recursive())
805
853
        self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
806
854
 
807
855
    def test_unicode_paths(self):