mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-28494: Test existing zipfile working behavior. (GH-15853)
Add unittests for executables with a zipfile appended to test_zipfile, as zipfile.is_zipfile and zipfile.ZipFile work properly on these today.
This commit is contained in:
parent
afdeb189e9
commit
3f4db4a0ba
6 changed files with 101 additions and 0 deletions
|
@ -5,6 +5,8 @@ import os
|
|||
import pathlib
|
||||
import posixpath
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
import zipfile
|
||||
|
@ -2470,6 +2472,44 @@ def build_alpharep_fixture():
|
|||
return zf
|
||||
|
||||
|
||||
class TestExecutablePrependedZip(unittest.TestCase):
|
||||
"""Test our ability to open zip files with an executable prepended."""
|
||||
|
||||
def setUp(self):
|
||||
self.exe_zip = findfile('exe_with_zip', subdir='ziptestdata')
|
||||
self.exe_zip64 = findfile('exe_with_z64', subdir='ziptestdata')
|
||||
|
||||
def _test_zip_works(self, name):
|
||||
# bpo-28494 sanity check: ensure is_zipfile works on these.
|
||||
self.assertTrue(zipfile.is_zipfile(name),
|
||||
f'is_zipfile failed on {name}')
|
||||
# Ensure we can operate on these via ZipFile.
|
||||
with zipfile.ZipFile(name) as zipfp:
|
||||
for n in zipfp.namelist():
|
||||
data = zipfp.read(n)
|
||||
self.assertIn(b'FAVORITE_NUMBER', data)
|
||||
|
||||
def test_read_zip_with_exe_prepended(self):
|
||||
self._test_zip_works(self.exe_zip)
|
||||
|
||||
def test_read_zip64_with_exe_prepended(self):
|
||||
self._test_zip_works(self.exe_zip64)
|
||||
|
||||
@unittest.skipUnless(sys.executable, 'sys.executable required.')
|
||||
@unittest.skipUnless(os.access('/bin/bash', os.X_OK),
|
||||
'Test relies on #!/bin/bash working.')
|
||||
def test_execute_zip2(self):
|
||||
output = subprocess.check_output([self.exe_zip, sys.executable])
|
||||
self.assertIn(b'number in executable: 5', output)
|
||||
|
||||
@unittest.skipUnless(sys.executable, 'sys.executable required.')
|
||||
@unittest.skipUnless(os.access('/bin/bash', os.X_OK),
|
||||
'Test relies on #!/bin/bash working.')
|
||||
def test_execute_zip64(self):
|
||||
output = subprocess.check_output([self.exe_zip64, sys.executable])
|
||||
self.assertIn(b'number in executable: 5', output)
|
||||
|
||||
|
||||
class TestPath(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.fixtures = contextlib.ExitStack()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue