From bdfd5ccb1e2e22408371b26b806886e20b971285 Mon Sep 17 00:00:00 2001 From: Gustavo Niemeyer Date: Wed, 5 Dec 2007 21:02:10 -0200 Subject: New 'path' option to MockerTestCase.makeFile() and makeDir(), which allows setting the full target path with a single option. --- test.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'test.py') diff --git a/test.py b/test.py index a37977b..df463a5 100755 --- a/test.py +++ b/test.py @@ -863,6 +863,18 @@ class MockerTestCaseTest(TestCase): finally: shutil.rmtree(dirname) + def test_make_file_with_path(self): + path = tempfile.mktemp() + try: + filename = self.test.makeFile("", path=path) + self.assertEquals(filename, path) + self.assertEquals(os.path.getsize(filename), 0) + self.test.run() + self.assertFalse(os.path.exists(filename)) + finally: + if os.path.isfile(path): + os.unlink(path) + def test_make_dir_returns_dirname(self): dirname = self.test.makeDir() self.assertEquals(os.path.isdir(dirname), True) @@ -890,12 +902,24 @@ class MockerTestCaseTest(TestCase): self.assertTrue(os.path.basename(dirname).endswith("-suffix")) def test_make_dir_with_dirname(self): - parent_dirname = tempfile.mkdtemp() + dirname = tempfile.mkdtemp() + try: + path = self.test.makeDir(dirname=dirname) + self.assertEquals(os.path.dirname(path), dirname) + finally: + if os.path.exists(dirname): + shutil.rmtree(dirname) + + def test_make_dir_with_path(self): + path = tempfile.mktemp() try: - dirname = self.test.makeDir(dirname=parent_dirname) - self.assertEquals(os.path.dirname(dirname), parent_dirname) + self.assertEquals(self.test.makeDir(path=path), path) + self.assertEquals(os.path.isdir(path), True) + self.test.run() + self.assertEquals(os.path.isdir(path), False) finally: - shutil.rmtree(parent_dirname) + if os.path.exists(path): + shutil.rmtree(path) class MockerTest(TestCase): -- cgit v1.2.1