summaryrefslogtreecommitdiff
path: root/Lib/test/test_py_compile.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-06-14 18:33:00 -0400
committerBrett Cannon <brett@python.org>2013-06-14 18:33:00 -0400
commit33915eba7c8293eab4962345fbbb1e5d193295ed (patch)
tree320c366c8c8f651c6c0d515b662f8cecf2e41cac /Lib/test/test_py_compile.py
parent3fe35e65034de82c45e2d8fe1ebe4a2929c68453 (diff)
downloadcpython-git-33915eba7c8293eab4962345fbbb1e5d193295ed.tar.gz
Issue #17222: Raise FileExistsError when py_compile.compile would
overwrite a symlink or non-regular file with a regular file.
Diffstat (limited to 'Lib/test/test_py_compile.py')
-rw-r--r--Lib/test/test_py_compile.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
index e1795546e1..54dc59660a 100644
--- a/Lib/test/test_py_compile.py
+++ b/Lib/test/test_py_compile.py
@@ -36,6 +36,26 @@ class PyCompileTests(unittest.TestCase):
self.assertTrue(os.path.exists(self.pyc_path))
self.assertFalse(os.path.exists(self.cache_path))
+ def test_do_not_overwrite_symlinks(self):
+ # In the face of a cfile argument being a symlink, bail out.
+ # Issue #17222
+ try:
+ os.symlink(self.pyc_path + '.actual', self.pyc_path)
+ except OSError:
+ self.skipTest('need to be able to create a symlink for a file')
+ else:
+ assert os.path.islink(self.pyc_path)
+ with self.assertRaises(FileExistsError):
+ py_compile.compile(self.source_path, self.pyc_path)
+
+ @unittest.skipIf(not os.path.exists(os.devnull) or os.path.isfile(os.devnull),
+ 'requires os.devnull and for it to be a non-regular file')
+ def test_do_not_overwrite_nonregular_files(self):
+ # In the face of a cfile argument being a non-regular file, bail out.
+ # Issue #17222
+ with self.assertRaises(FileExistsError):
+ py_compile.compile(self.source_path, os.devnull)
+
def test_cache_path(self):
py_compile.compile(self.source_path)
self.assertTrue(os.path.exists(self.cache_path))