def test_tmpdir1(self): """simple temporary directory""" tmpdir = TemporaryDirectory(dir=self._tmpdir) path = tmpdir.path self.assertIsNotNone(path) self.assertTrue(os.path.isdir(path)) self.assertEqual(str(tmpdir), path) # a simple assignment to path is not supposed to work, but _path # can still be modified (_never_ do that) self.assertRaises(AttributeError, setattr, tmpdir, 'path', path) tmpdir.rmtree() self.assertIsNone(tmpdir.path) self.assertFalse(os.path.isdir(path))
def test_tmpdir1(self): """simple temporary directory""" tmpdir = TemporaryDirectory(dir=self._tmpdir) path = tmpdir.path self.assertIsNotNone(path) self.assertTrue(os.path.isdir(path)) self.assertEqual(str(tmpdir), path) # a simple assignment to path is not supposed to work, but _path # can still be modified (_never_ do that) self.assertRaises(AttributeError, setattr, tmpdir, 'path', path) tmpdir.rmtree() self.assertIsNone(tmpdir.path) self.assertFalse(os.path.isdir(path))
def test_tmpdir3(self): """multiple remove""" tmpdir = TemporaryDirectory(dir=self._tmpdir) path = tmpdir.path self.assertIsNotNone(path) self.assertTrue(os.path.isdir(path)) tmpdir.rmtree() self.assertFalse(os.path.isdir(path)) # a call to path does not recreate the tmpdir self.assertIsNone(tmpdir.path) self.assertFalse(os.path.isdir(path)) # recreate directory os.mkdir(path) self.assertTrue(os.path.isdir(path)) # subsequent rmdir/rmtree calls have no affect anymore tmpdir.rmdir() tmpdir.rmtree() self.assertTrue(os.path.isdir(path)) os.rmdir(path)
def test_tmpdir3(self): """multiple remove""" tmpdir = TemporaryDirectory(dir=self._tmpdir) path = tmpdir.path self.assertIsNotNone(path) self.assertTrue(os.path.isdir(path)) tmpdir.rmtree() self.assertFalse(os.path.isdir(path)) # a call to path does not recreate the tmpdir self.assertIsNone(tmpdir.path) self.assertFalse(os.path.isdir(path)) # recreate directory os.mkdir(path) self.assertTrue(os.path.isdir(path)) # subsequent rmdir/rmtree calls have no affect anymore tmpdir.rmdir() tmpdir.rmtree() self.assertTrue(os.path.isdir(path)) os.rmdir(path)
def test_tmpdir9(self): """test __enter__ (tmpdir was already deleted)""" tmpdir = TemporaryDirectory(dir=self._tmpdir) tmpdir.rmtree() self.assertIsNone(tmpdir.path) self.assertRaises(ValueError, tmpdir.__enter__)
def test_tmpdir9(self): """test __enter__ (tmpdir was already deleted)""" tmpdir = TemporaryDirectory(dir=self._tmpdir) tmpdir.rmtree() self.assertIsNone(tmpdir.path) self.assertRaises(ValueError, tmpdir.__enter__)