def test_tmpdir(self): td = tmpdir() self.assertEqual(os.path.dirname(td), os.getcwd()) self.assertRegexpMatches(os.path.basename(td), r"^_test.\d+$") td = tmpdir("/tmp") self.assertEqual(os.path.dirname(td), "/tmp") self.assertRegexpMatches(os.path.basename(td), r"^_test.\d+$") td = tmpdir(dirname="_goob") self.assertEqual(os.path.dirname(td), os.getcwd()) self.assertEqual(os.path.basename(td), "_goob") td = tmpdir("/tmp", "_goob") self.assertEqual(os.path.dirname(td), "/tmp") self.assertEqual(os.path.basename(td), "_goob")
def test_ensure_dir(self): tdir = tmpdir() base = os.path.basename(tdir) td = ensure_tmpdir() self.assertEquals(td, tdir) self.assertTrue(os.path.exists(td)) self.assertTrue(os.path.isdir(td)) self.assertEqual(os.path.dirname(td), os.getcwd()) self.assertRegexpMatches(os.path.basename(tdir), r"^_test.\d+$") shutil.rmtree(td) assert not os.path.exists(td) td = ensure_tmpdir("/tmp") self.assertEquals(td, os.path.join("/tmp", base)) self.assertTrue(os.path.exists(td)) self.assertTrue(os.path.isdir(td)) self.assertEqual(os.path.dirname(td), "/tmp") self.assertRegexpMatches(os.path.basename(td), r"^_test.\d+$") shutil.rmtree(td) assert not os.path.exists(td) td = ensure_tmpdir(dirname="_goob") self.assertTrue(os.path.exists(td)) self.assertTrue(os.path.isdir(td)) self.assertEqual(os.path.dirname(td), os.getcwd()) self.assertEqual(os.path.basename(td), "_goob") shutil.rmtree(td) assert not os.path.exists(td) td = ensure_tmpdir("/tmp", "_goob") self.assertTrue(os.path.exists(td)) self.assertTrue(os.path.isdir(td)) self.assertEqual(os.path.dirname(td), "/tmp") self.assertEqual(os.path.basename(td), "_goob") shutil.rmtree(td) assert not os.path.exists(td)
def test_ctor(self): tf = Tempfiles() self.assertEqual(tf.root, tmpdir()) self.assertTrue(os.path.exists(tf.root)) self.assertFalse(tf._autoclean) self.assertEqual(len(tf._files), 0)
def tearDown(self): tempdir = tmpdir() if os.path.exists(tempdir): shutil.rmtree(tempdir)