mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-130379: Fix incorrect zipapp logic to avoid including the target in itself (gh-130509)
This commit is contained in:
parent
f976892b7d
commit
64ccbbbf36
3 changed files with 50 additions and 2 deletions
|
@ -89,6 +89,30 @@ class ZipAppTest(unittest.TestCase):
|
|||
self.assertIn('test.py', z.namelist())
|
||||
self.assertNotIn('test.pyc', z.namelist())
|
||||
|
||||
def test_create_archive_self_insertion(self):
|
||||
# When creating an archive, we shouldn't
|
||||
# include the archive in the list of files to add.
|
||||
source = self.tmpdir
|
||||
(source / '__main__.py').touch()
|
||||
(source / 'test.py').touch()
|
||||
target = self.tmpdir / 'target.pyz'
|
||||
|
||||
zipapp.create_archive(source, target)
|
||||
with zipfile.ZipFile(target, 'r') as z:
|
||||
self.assertEqual(len(z.namelist()), 2)
|
||||
self.assertIn('__main__.py', z.namelist())
|
||||
self.assertIn('test.py', z.namelist())
|
||||
|
||||
def test_target_overwrites_source_file(self):
|
||||
# The target cannot be one of the files to add.
|
||||
source = self.tmpdir
|
||||
(source / '__main__.py').touch()
|
||||
target = source / 'target.pyz'
|
||||
target.touch()
|
||||
|
||||
with self.assertRaises(zipapp.ZipAppError):
|
||||
zipapp.create_archive(source, target)
|
||||
|
||||
def test_create_archive_filter_exclude_dir(self):
|
||||
# Test packing a directory and using a filter to exclude a
|
||||
# subdirectory (ensures that the path supplied to include
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue