diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-07 07:51:38 -0200 |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2007-12-07 07:51:38 -0200 |
commit | 92e4f5b0bc5ec7a06284b9cc2245fdfb052d9707 (patch) | |
tree | 783a715ae664d1a33b2a86b8b91ae08cb6215c54 | |
parent | bdfd5ccb1e2e22408371b26b806886e20b971285 (diff) | |
download | mocker-92e4f5b0bc5ec7a06284b9cc2245fdfb052d9707.tar.gz |
MockerTestCase.makeFile() with content=None (the default) now
consistently returns an unexistent temporary filename which
is properly cleaned up if created.
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | mocker.py | 14 | ||||
-rwxr-xr-x | test.py | 7 |
3 files changed, 17 insertions, 8 deletions
@@ -22,6 +22,10 @@ Twisted Trial's TestCase, so that coexistence by multiple inheritance is possible and trivial. +- MockerTestCase.makeFile() with content=None (the default) now + consistently returns an unexistent temporary filename which + is properly cleaned up if created. + 0.9.3 (2007-11-24) ================== @@ -99,16 +99,14 @@ class MockerTestCase(unittest.TestCase): if test_method is not None: def test_method_wrapper(): try: - try: - result = test_method() - finally: - if (self.mocker.is_recording() and - self.mocker.get_events()): - raise RuntimeError("Mocker must be put in replay " - "mode with self.mocker.replay()") + result = test_method() except: raise else: + if (self.mocker.is_recording() and + self.mocker.get_events()): + raise RuntimeError("Mocker must be put in replay " + "mode with self.mocker.replay()") if (hasattr(result, "addCallback") and hasattr(result, "addErrback")): def verify(result): @@ -181,6 +179,8 @@ class MockerTestCase(unittest.TestCase): fd, path = tempfile.mkstemp(suffix, prefix, dirname) self.__cleanup_paths.append(path) os.close(fd) + if content is None: + os.unlink(path) if content is not None: file = open(path, "w") file.write(content) @@ -810,8 +810,13 @@ class MockerTestCaseTest(TestCase): self.assertEquals(MockerTestCase.assertFalse.im_func, MockerTestCase.failIf.im_func) - def test_make_file_returns_filename(self): + def test_make_file_returns_writable_filename(self): filename = self.test.makeFile() + self.assertFalse(os.path.isfile(filename)) + open(filename, "w").write("Is writable!") + + def test_make_file_creates_file(self): + filename = self.test.makeFile("") self.assertEquals(os.path.getsize(filename), 0) def test_make_file_cleansup_on_success(self): |