cpython: 5bfb4147405e (original) (raw)
Mercurial > cpython
changeset 100368:5bfb4147405e 2.7
Issue #26385: Cleanup NamedTemporaryFile if fdopen() fails, by SilentGhost [#26385]
Martin Panter vadmium+py@gmail.com | |
---|---|
date | Mon, 29 Feb 2016 00:31:38 +0000 |
parents | 408891646a37 |
children | 305ae007899b |
files | Lib/tempfile.py Lib/test/test_tempfile.py Misc/NEWS |
diffstat | 3 files changed, 12 insertions(+), 1 deletions(-)[+] [-] Lib/tempfile.py 3 Lib/test/test_tempfile.py 7 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -476,7 +476,8 @@ def NamedTemporaryFile(mode='w+b', bufsi try: file = _os.fdopen(fd, mode, bufsize) return _TemporaryFileWrapper(file, name, delete)
--- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -827,6 +827,13 @@ class test_NamedTemporaryFile(TC): os.close = old_close os.fdopen = old_fdopen
- def test_bad_mode(self):
dir = tempfile.mkdtemp()[](#l2.8)
self.addCleanup(support.rmtree, dir)[](#l2.9)
with self.assertRaises(TypeError):[](#l2.10)
tempfile.NamedTemporaryFile(mode=(), dir=dir)[](#l2.11)
self.assertEqual(os.listdir(dir), [])[](#l2.12)
+ # How to test the mode and bufsize parameters? test_classes.append(test_NamedTemporaryFile)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -55,6 +55,9 @@ Core and Builtins Library ------- +- Issue #26385: Remove the file if the internal fdopen() call in