diff options
author | Barry Warsaw <barry@python.org> | 2014-12-01 22:52:43 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2014-12-01 22:52:43 (GMT) |
commit | d32d4ae4ca94c0ec89b26a0798bdb33767e950ed (patch) | |
tree | 2cc9b9d89f0b0a98ab4604718940da83b0e6bde2 /Lib/test/test_py_compile.py | |
parent | 95df265e3a7a0713fcd8744e7a67ee8b29a17333 (diff) | |
parent | 9e4db75426be7433af7c0d5b569fb3f3c4b5877e (diff) | |
download | cpython-d32d4ae4ca94c0ec89b26a0798bdb33767e950ed.zip cpython-d32d4ae4ca94c0ec89b26a0798bdb33767e950ed.tar.gz cpython-d32d4ae4ca94c0ec89b26a0798bdb33767e950ed.tar.bz2 |
- Issue #22966: Fix __pycache__ pyc file name clobber when pyc_compile is
asked to compile a source file containing multiple dots in the source file
name.
Diffstat (limited to 'Lib/test/test_py_compile.py')
-rw-r--r-- | Lib/test/test_py_compile.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py index 138f173..e99c317 100644 --- a/Lib/test/test_py_compile.py +++ b/Lib/test/test_py_compile.py @@ -3,6 +3,7 @@ import os import py_compile import shutil import stat +import sys import tempfile import unittest @@ -99,5 +100,21 @@ class PyCompileTests(unittest.TestCase): self.assertFalse(os.path.exists( importlib.util.cache_from_source(bad_coding))) + def test_double_dot_no_clobber(self): + # http://bugs.python.org/issue22966 + # py_compile foo.bar.py -> __pycache__/foo.cpython-34.pyc + weird_path = os.path.join(self.directory, 'foo.bar.py') + cache_path = importlib.util.cache_from_source(weird_path) + pyc_path = weird_path + 'c' + self.assertEqual( + '/'.join(cache_path.split('/')[-2:]), + '__pycache__/foo.bar.{}.pyc'.format(sys.implementation.cache_tag)) + with open(weird_path, 'w') as file: + file.write('x = 123\n') + py_compile.compile(weird_path) + self.assertTrue(os.path.exists(cache_path)) + self.assertFalse(os.path.exists(pyc_path)) + + if __name__ == "__main__": unittest.main() |