diff options
| author | Eli Bendersky <eliben@gmail.com> | 2013-09-06 13:17:15 (GMT) |
|---|---|---|
| committer | Eli Bendersky <eliben@gmail.com> | 2013-09-06 13:17:15 (GMT) |
| commit | 8c7e925f6ea1333c7f2838a7643bbe39c6eff6af (patch) | |
| tree | a64e5adc7d3f4cb78e76ba5ebd00c2686f0c20a5 /Lib/test/test_tempfile.py | |
| parent | fb03696fdabeb850cdc714cd1abb45f6d93fcdf6 (diff) | |
| download | cpython-8c7e925f6ea1333c7f2838a7643bbe39c6eff6af.zip cpython-8c7e925f6ea1333c7f2838a7643bbe39c6eff6af.tar.gz cpython-8c7e925f6ea1333c7f2838a7643bbe39c6eff6af.tar.bz2 | |
Close #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.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index b4d23ad..eb3e2b9 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -386,6 +386,32 @@ class test__mkstemp_inner(TC): self.do_create(bin=0).write("blat\n") # XXX should test that the file really is a text file + 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) + test_classes.append(test__mkstemp_inner) |
