summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2007-12-07 07:51:38 -0200
committerGustavo Niemeyer <gustavo@niemeyer.net>2007-12-07 07:51:38 -0200
commit92e4f5b0bc5ec7a06284b9cc2245fdfb052d9707 (patch)
tree783a715ae664d1a33b2a86b8b91ae08cb6215c54
parentbdfd5ccb1e2e22408371b26b806886e20b971285 (diff)
downloadmocker-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--NEWS4
-rw-r--r--mocker.py14
-rwxr-xr-xtest.py7
3 files changed, 17 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index 7bff9ac..418097d 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
==================
diff --git a/mocker.py b/mocker.py
index 99450d7..5f8572b 100644
--- a/mocker.py
+++ b/mocker.py
@@ -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)
diff --git a/test.py b/test.py
index df463a5..783463c 100755
--- a/test.py
+++ b/test.py
@@ -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):