Ejemplo n.º 1
0
 def test_remove_dir_force(self):
     """Test removing directory with read-only contents."""
     dpath = self.__create_dir()
     # Make the directory and its contents read-only
     util.chmod(dpath, 0, recursive=True)
     util.remove_dir(dpath, force=True)
     self.assertNot(os.path.exists(dpath))
Ejemplo n.º 2
0
 def test_copy_dir_missing_source(self):
     """Test copy_dir with missing source directory."""
     src_dir = self.__create_dir()
     util.remove_dir(src_dir)
     dst_dir = self.__create_dir()
     self.assertRaises(util.MissingSource, util.copy_dir, src_dir,
             dst_dir, mode=util.CopyDir_Delete)
Ejemplo n.º 3
0
    def test_remove_dir(self):
        dpath = self.__create_dir()
        self.assertRaises(util.DirNotEmpty, util.remove_dir, dpath, recurse=False)
        util.remove_dir(dpath, recurse=True)
        self.assertNot(os.path.exists(dpath))

        # Test removing an empty dir
        dpath = self._get_tempdir()
        util.remove_dir(dpath, recurse=False)
        self.assertNot(os.path.exists(dpath))
Ejemplo n.º 4
0
    def test_remove_dir_force_relative(self):
        """Test removing directory forcefully with relative path."""
        dpath = self.__create_dir()
        dpath_parent = os.path.dirname(dpath)
        os.chdir(dpath_parent)
        dpath_rel = util.replace_root(dpath, "", dpath_parent)
        # Make sure it's a pure relative path, i.e. it doesn't start with ./
        assert not dpath_rel.startswith(".")

        util.remove_dir(dpath_rel, force=True)
        self.assertNot(os.path.exists(dpath))
Ejemplo n.º 5
0
    def test_remove_dir_symlinked_dir(self):
        """Test remove_dir when there's a symlinked subdirectory that's removed before the symlink.

        If there's the subdirectory 'a' and in the same directory a symlink
        pointing to it, named 'b', remove_dir may remove the directory first
        thus breaking the symlink. In this case, remove_dir may still think
        the 'b' is a directory since it originally pointed to one.
        """
        dpath = self._get_tempdir()
        os.mkdir(os.path.join(dpath, "a"))
        os.symlink("a", os.path.join(dpath, "b"))

        util.remove_dir(dpath)
        self.assertNot(os.path.exists(dpath))
Ejemplo n.º 6
0
    def test_copy_dir(self):
        """ Test copying a directory.

        When a directory is copied, the client callback should be called periodically with
        progress status.
        """
        def callback(progress):
            self.__progress.append(progress)

        dpath = self.__create_dir()
        dstDir = self._get_tempdir()
        self.assertRaises(util.DestinationExists, util.copy_dir, dpath, dstDir)

        # Try forcing deletion of existing directory

        os.mkdir(os.path.join(dstDir, "testdir"))
        # Remove only write permission
        if util.get_os()[0] == Os_Windows:
            util.chmod(os.path.join(dstDir, "testdir"), 0500)
        else:
            util.chmod(dstDir, 0500)
        # Make sure we can access the directory (requires the correct
        # permissions on dstDir)
        assert os.path.exists(os.path.join(dstDir, "testdir"))
        # This should fail, because the conflicting directory is protected from
        # deletion
        self.assertRaises(util.PermissionsError, util.copy_dir, dpath,
                os.path.join(dstDir, "testdir"), mode=util.CopyDir_Delete)
        if util.get_os()[0] == Os_Windows:
            util.chmod(os.path.join(dstDir, "testdir"), 0700)
        else:
            util.chmod(dstDir, 0700)
        util.copy_dir(dpath, dstDir, mode=util.CopyDir_Delete)

        util.remove_dir(dstDir, recurse=True)
        self.__progress = []
        util.copy_dir(dpath, dstDir, callback=callback)
        self.assertEqual(compare_dirs(dpath, dstDir), ([], []))
        self.assertEqual(self.__progress[0], 0.0)
        self.assertEqual(self.__progress[-1], 100.0)

        # Test ignoring certain files
        dpath = self._get_tempdir()
        os.mkdir(os.path.join(dpath, ".svn"))
        util.create_file(os.path.join(dpath, "test"))
        dstDir = self._get_tempdir()
        util.copy_dir(dpath, dstDir, ignore=[".*"], mode=util.CopyDir_Delete)
        self.assertEqual(os.listdir(dstDir), ["test"])