~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_implementations.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-02-22 07:59:56 UTC
  • mfrom: (1553.5.33 bzr.mbp.locks)
  • Revision ID: pqm@pqm.ubuntu.com-20060222075956-fb281c427e571da6
add LockDir and related fixes

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,
 
28
from bzrlib.errors import (DirectoryNotEmpty, NoSuchFile, FileExists,
29
29
                           LockError,
 
30
                           PathError,
30
31
                           TransportNotPossible, ConnectionError)
31
32
from bzrlib.tests import TestCaseInTempDir, TestSkipped
32
33
from bzrlib.transport import memory, urlescape
552
553
        t.rmdir('adir')
553
554
        self.assertRaises(NoSuchFile, t.stat, 'adir')
554
555
 
 
556
    def test_rmdir_not_empty(self):
 
557
        """Deleting a non-empty directory raises an exception
 
558
        
 
559
        sftp (and possibly others) don't give us a specific "directory not
 
560
        empty" exception -- we can just see that the operation failed.
 
561
        """
 
562
        t = self.get_transport()
 
563
        if t.is_readonly():
 
564
            return
 
565
        t.mkdir('adir')
 
566
        t.mkdir('adir/bdir')
 
567
        self.assertRaises(PathError, t.rmdir, 'adir')
 
568
 
 
569
    def test_rename_dir_succeeds(self):
 
570
        t = self.get_transport()
 
571
        if t.is_readonly():
 
572
            raise TestSkipped("transport is readonly")
 
573
        t.mkdir('adir')
 
574
        t.mkdir('adir/asubdir')
 
575
        t.rename('adir', 'bdir')
 
576
        self.assertTrue(t.has('bdir/asubdir'))
 
577
        self.assertFalse(t.has('adir'))
 
578
 
 
579
    def test_rename_dir_nonempty(self):
 
580
        """Attempting to replace a nonemtpy directory should fail"""
 
581
        t = self.get_transport()
 
582
        if t.is_readonly():
 
583
            raise TestSkipped("transport is readonly")
 
584
        t.mkdir('adir')
 
585
        t.mkdir('adir/asubdir')
 
586
        t.mkdir('bdir')
 
587
        t.mkdir('bdir/bsubdir')
 
588
        self.assertRaises(PathError, t.rename, 'bdir', 'adir')
 
589
        # nothing was changed so it should still be as before
 
590
        self.assertTrue(t.has('bdir/bsubdir'))
 
591
        self.assertFalse(t.has('adir/bdir'))
 
592
        self.assertFalse(t.has('adir/bsubdir'))
 
593
 
555
594
    def test_delete_tree(self):
556
595
        t = self.get_transport()
557
596
 
790
829
    def test_iter_files_recursive(self):
791
830
        transport = self.get_transport()
792
831
        if not transport.listable():
793
 
            self.assertRaises(TransportNotPossible, 
 
832
            self.assertRaises(TransportNotPossible,
794
833
                              transport.iter_files_recursive)
795
834
            return
796
 
        self.build_tree(['isolated/', 
 
835
        self.build_tree(['isolated/',
797
836
                         'isolated/dir/',
798
837
                         'isolated/dir/foo',
799
838
                         'isolated/dir/bar',
800
839
                         'isolated/bar'],
801
840
                        transport=transport)
802
 
        transport = transport.clone('isolated')
803
841
        paths = set(transport.iter_files_recursive())
 
842
        # nb the directories are not converted
 
843
        self.assertEqual(paths,
 
844
                    set(['isolated/dir/foo',
 
845
                         'isolated/dir/bar',
 
846
                         'isolated/bar']))
 
847
        sub_transport = transport.clone('isolated')
 
848
        paths = set(sub_transport.iter_files_recursive())
804
849
        self.assertEqual(set(['dir/foo', 'dir/bar', 'bar']), paths)
805
850
 
806
851
    def test_connect_twice_is_same_content(self):