diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-02-28 05:22:20 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-02-28 05:22:20 (GMT) |
commit | 7869a227795da08841f8139b69b7d4521b12e184 (patch) | |
tree | fa6da1d13f8e13379f3914e328cf25a10e5f5eac /Lib/test/test_tempfile.py | |
parent | 96421d6f1136292abfe8748903f11231fba6cb16 (diff) | |
download | cpython-7869a227795da08841f8139b69b7d4521b12e184.zip cpython-7869a227795da08841f8139b69b7d4521b12e184.tar.gz cpython-7869a227795da08841f8139b69b7d4521b12e184.tar.bz2 |
Issue #26385: Cleanup NamedTemporaryFile if open() fails, by SilentGhost
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r-- | Lib/test/test_tempfile.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 4a077cc..51df1ec 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -948,8 +948,16 @@ class TestNamedTemporaryFile(BaseTestCase): self.assertRaises(ValueError, tempfile.NamedTemporaryFile) self.assertEqual(len(closed), 1) - # How to test the mode and bufsize parameters? + def test_bad_mode(self): + dir = tempfile.mkdtemp() + self.addCleanup(support.rmtree, dir) + with self.assertRaises(ValueError): + tempfile.NamedTemporaryFile(mode='wr', dir=dir) + with self.assertRaises(TypeError): + tempfile.NamedTemporaryFile(mode=2, dir=dir) + self.assertEqual(os.listdir(dir), []) + # How to test the mode and bufsize parameters? class TestSpooledTemporaryFile(BaseTestCase): """Test SpooledTemporaryFile().""" |