Пример #1
0
    def testRmDirsWithSimplePath(self):
        self.mox.StubOutWithMock(shutil, 'rmtree')
        shutil.rmtree('directory')

        self.mox.ReplayAll()

        file_util.RmDirs('directory')
        self.mox.VerifyAll()
Пример #2
0
    def testRmDirsForPermissionDeniedOnParentDirectory(self):
        self.mox.StubOutWithMock(os, 'rmdir')
        os.rmdir('path/to').AndRaise(
            OSError(errno.EACCES, 'Permission denied', 'path/to'))

        self.mox.StubOutWithMock(shutil, 'rmtree')
        shutil.rmtree('path/to/directory')

        self.mox.ReplayAll()

        file_util.RmDirs('path/to/directory')
        self.mox.VerifyAll()
Пример #3
0
    def testRmDirsForNotEmptyDirectory(self):
        self.mox.StubOutWithMock(os, 'rmdir')
        os.rmdir('path/to').AndRaise(
            OSError(errno.ENOTEMPTY, 'Directory not empty', 'path/to'))

        self.mox.StubOutWithMock(shutil, 'rmtree')
        shutil.rmtree('path/to/directory')

        self.mox.ReplayAll()

        file_util.RmDirs('path/to/directory')
        self.mox.VerifyAll()
Пример #4
0
    def testRmDirsForNonExistingDirectory(self):
        self.mox.StubOutWithMock(os, 'rmdir')
        os.rmdir('path/to')
        os.rmdir('path')

        self.mox.StubOutWithMock(shutil, 'rmtree')
        shutil.rmtree('path/to/directory').AndRaise(
            OSError(errno.ENOENT,
                    "No such file or directory 'path/to/directory'"))

        self.mox.ReplayAll()

        file_util.RmDirs('path/to/directory')
        self.mox.VerifyAll()
Пример #5
0
    def testRmDirs(self):
        test_sandbox = os.path.join(FLAGS.test_tmpdir, 'test-rm-dirs')
        test_dir = os.path.join(test_sandbox, 'test', 'dir')

        os.makedirs(test_sandbox)
        with open(os.path.join(test_sandbox, 'file'), 'w'):
            pass
        os.makedirs(test_dir)
        with open(os.path.join(test_dir, 'file'), 'w'):
            pass

        file_util.RmDirs(test_dir)

        self.assertFalse(os.path.exists(os.path.join(test_sandbox, 'test')))
        self.assertTrue(os.path.exists(os.path.join(test_sandbox, 'file')))

        shutil.rmtree(test_sandbox)