summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tempfile.py
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-09-06 13:11:19 (GMT)
committerEli Bendersky <eliben@gmail.com>2013-09-06 13:11:19 (GMT)
commitf315df31bd8a927768bb94c3342d155cdc87d997 (patch)
tree25a027aa12346e1fff608ea693a61ff3b2cd2aa2 /Lib/test/test_tempfile.py
parent43c6ef189955474001aad75d3b47d895180b2d42 (diff)
downloadcpython-f315df31bd8a927768bb94c3342d155cdc87d997.zip
cpython-f315df31bd8a927768bb94c3342d155cdc87d997.tar.gz
cpython-f315df31bd8a927768bb94c3342d155cdc87d997.tar.bz2
Issue #18849: Fixed a Windows-specific tempfile bug where collision with an
existing directory caused mkstemp and related APIs to fail instead of retrying. Report and fix by Vlad Shcherbina.
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r--Lib/test/test_tempfile.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 2962939..b56d648 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -372,6 +372,32 @@ class TestMkstempInner(BaseTestCase):
os.lseek(f.fd, 0, os.SEEK_SET)
self.assertEqual(os.read(f.fd, 20), b"blat")
+ def test_collision_with_existing_directory(self):
+ # _mkstemp_inner tries another name when a directory with
+ # the chosen name already exists
+ container_dir = tempfile.mkdtemp()
+ try:
+ def mock_get_candidate_names():
+ return iter(['aaa', 'aaa', 'bbb'])
+ with support.swap_attr(tempfile,
+ '_get_candidate_names',
+ mock_get_candidate_names):
+ dir = tempfile.mkdtemp(dir=container_dir)
+ self.assertTrue(dir.endswith('aaa'))
+
+ flags = tempfile._bin_openflags
+ (fd, name) = tempfile._mkstemp_inner(container_dir,
+ tempfile.template,
+ '',
+ flags)
+ try:
+ self.assertTrue(name.endswith('bbb'))
+ finally:
+ os.close(fd)
+ os.unlink(name)
+ finally:
+ support.rmtree(container_dir)
+
class TestGetTempPrefix(BaseTestCase):
"""Test gettempprefix()."""