cpython: a1c125f21db4 (original) (raw)
Mercurial > cpython
changeset 100369:a1c125f21db4 3.5
Issue #26385: Cleanup NamedTemporaryFile if open() fails, by SilentGhost [#26385]
Martin Panter vadmium+py@gmail.com | |
---|---|
date | Sun, 28 Feb 2016 05:22:20 +0000 |
parents | 8f8e86ea3abb |
children | 865cf8eba51a 9dba1457ddd7 |
files | Lib/tempfile.py Lib/test/test_tempfile.py Misc/NEWS |
diffstat | 3 files changed, 14 insertions(+), 2 deletions(-)[+] [-] Lib/tempfile.py 3 Lib/test/test_tempfile.py 10 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -552,7 +552,8 @@ def NamedTemporaryFile(mode='w+b', buffe newline=newline, encoding=encoding) return _TemporaryFileWrapper(file, name, delete)
--- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -948,9 +948,17 @@ class TestNamedTemporaryFile(BaseTestCas self.assertRaises(ValueError, tempfile.NamedTemporaryFile) self.assertEqual(len(closed), 1)
- def test_bad_mode(self):
dir = tempfile.mkdtemp()[](#l2.8)
self.addCleanup(support.rmtree, dir)[](#l2.9)
with self.assertRaises(ValueError):[](#l2.10)
tempfile.NamedTemporaryFile(mode='wr', dir=dir)[](#l2.11)
with self.assertRaises(TypeError):[](#l2.12)
tempfile.NamedTemporaryFile(mode=2, dir=dir)[](#l2.13)
self.assertEqual(os.listdir(dir), [])[](#l2.14)
+ # How to test the mode and bufsize parameters? - class TestSpooledTemporaryFile(BaseTestCase): """Test SpooledTemporaryFile()."""
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -84,6 +84,9 @@ Core and Builtins Library ------- +- Issue #26385: Remove the file if the internal open() call in