summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tempfile.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-13 18:31:49 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-13 18:31:49 (GMT)
commit35ef9c19fe0f66d9d68b41100e85edc9feb45b1e (patch)
tree2e199adeacb7b794ec18c9ea79e57ba58e659cd3 /Lib/test/test_tempfile.py
parent6c104f6906bc7203f39a15bcc8b3d3905c7333e8 (diff)
downloadcpython-35ef9c19fe0f66d9d68b41100e85edc9feb45b1e.zip
cpython-35ef9c19fe0f66d9d68b41100e85edc9feb45b1e.tar.gz
cpython-35ef9c19fe0f66d9d68b41100e85edc9feb45b1e.tar.bz2
Patch #1537850: tempfile.NamedTemporaryFile now has a "delete" parameter
which can be set to False to prevent the default delete-on-close behavior.
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r--Lib/test/test_tempfile.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 2047a63..82f1ea3 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -561,11 +561,12 @@ test_classes.append(test_mktemp)
class test_NamedTemporaryFile(TC):
"""Test NamedTemporaryFile()."""
- def do_create(self, dir=None, pre="", suf=""):
+ def do_create(self, dir=None, pre="", suf="", delete=True):
if dir is None:
dir = tempfile.gettempdir()
try:
- file = tempfile.NamedTemporaryFile(dir=dir, prefix=pre, suffix=suf)
+ file = tempfile.NamedTemporaryFile(dir=dir, prefix=pre, suffix=suf,
+ delete=delete)
except:
self.failOnException("NamedTemporaryFile")
@@ -599,6 +600,22 @@ class test_NamedTemporaryFile(TC):
finally:
os.rmdir(dir)
+ def test_dis_del_on_close(self):
+ # Tests that delete-on-close can be disabled
+ dir = tempfile.mkdtemp()
+ tmp = None
+ try:
+ f = tempfile.NamedTemporaryFile(dir=dir, delete=False)
+ tmp = f.name
+ f.write('blat')
+ f.close()
+ self.failUnless(os.path.exists(f.name),
+ "NamedTemporaryFile %s missing after close" % f.name)
+ finally:
+ if tmp is not None:
+ os.unlink(tmp)
+ os.rmdir(dir)
+
def test_multiple_close(self):
# A NamedTemporaryFile can be closed many times without error