コード例 #1
0
    def test_already_exists(self):
        dir = os.path.join(self.tempdir, 'already_exists')

        os.makedirs(dir)
        with self.assertRaises(Exception):
            with PrivateTemporaryDirectory(dir):
                pass
        shutil.rmtree(dir)
コード例 #2
0
    def test_cleanup(self):
        dir = os.path.join(self.tempdir, 'cleanup')

        with PrivateTemporaryDirectory(dir) as ctx:
            self.assertTrue(os.path.isdir(dir))
            ctx.cleanup()
            self.assertFalse(os.path.isdir(dir))
            ctx.cleanup()  # also check whether multiple calls don't throw
            ctx.cleanup()
コード例 #3
0
 def test_cleanup(self):
     ctx = PrivateTemporaryDirectory(dir=self.tempdir)
     self.assertTrue(os.path.isdir(ctx.name))
     ctx.cleanup()
     self.assertFalse(os.path.isdir(ctx.name))
     ctx.cleanup()  # also check whether multiple calls don't throw
     ctx.cleanup()
コード例 #4
0
 def test_mode(self):
     with PrivateTemporaryDirectory(dir=self.tempdir, mode=0o700) as dir:
         self.assertEqual(0o40700, os.stat(dir).st_mode)
コード例 #5
0
 def test_simple(self):
     with PrivateTemporaryDirectory(dir=self.tempdir) as dir:
         self.assertTrue(os.path.isdir(dir))
     self.assertFalse(os.path.isdir(dir))
コード例 #6
0
    def test_mode(self):
        dir = os.path.join(self.tempdir, 'mode')

        with PrivateTemporaryDirectory(dir, mode=0o700):
            self.assertEqual(0o40700, os.stat(dir).st_mode)
コード例 #7
0
    def test_simple(self):
        dir = os.path.join(self.tempdir, 'simple')

        with PrivateTemporaryDirectory(dir):
            self.assertTrue(os.path.isdir(dir))
        self.assertFalse(os.path.isdir(dir))