diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index b4d23ad..a11f60d 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -386,6 +386,30 @@ 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): + dir = tempfile.mkdtemp() + dirs = [dir] + try: + def mock_get_candidate_names(): + return iter(['aaa', 'aaa', 'bbb']) + with support.swap_attr(tempfile, + '_get_candidate_names', + mock_get_candidate_names): + dir2 = tempfile.mkdtemp(dir=dir, prefix='tmp', suffix='') + dirs.append(dir2) + self.assertTrue(dir2.endswith('aaa')) + + flags = tempfile._bin_openflags + (fd, name) = tempfile._mkstemp_inner(dir, 'tmp', '', flags) + try: + self.assertTrue(name.endswith('bbb')) + finally: + os.close(fd) + os.unlink(name) + finally: + for dir in reversed(dirs): + os.rmdir(dir) + test_classes.append(test__mkstemp_inner)