bpo-28494: Test existing zipfile working behavior. (GH-15853) · python/cpython@74b0291 (original) (raw)
`@@ -5,6 +5,8 @@
`
5
5
`import pathlib
`
6
6
`import posixpath
`
7
7
`import struct
`
``
8
`+
import subprocess
`
``
9
`+
import sys
`
8
10
`import time
`
9
11
`import unittest
`
10
12
`import zipfile
`
`@@ -2443,6 +2445,44 @@ def build_alpharep_fixture():
`
2443
2445
`return zf
`
2444
2446
``
2445
2447
``
``
2448
`+
class TestExecutablePrependedZip(unittest.TestCase):
`
``
2449
`+
"""Test our ability to open zip files with an executable prepended."""
`
``
2450
+
``
2451
`+
def setUp(self):
`
``
2452
`+
self.exe_zip = findfile('exe_with_zip', subdir='ziptestdata')
`
``
2453
`+
self.exe_zip64 = findfile('exe_with_z64', subdir='ziptestdata')
`
``
2454
+
``
2455
`+
def _test_zip_works(self, name):
`
``
2456
`+
bpo-28494 sanity check: ensure is_zipfile works on these.
`
``
2457
`+
self.assertTrue(zipfile.is_zipfile(name),
`
``
2458
`+
f'is_zipfile failed on {name}')
`
``
2459
`+
Ensure we can operate on these via ZipFile.
`
``
2460
`+
with zipfile.ZipFile(name) as zipfp:
`
``
2461
`+
for n in zipfp.namelist():
`
``
2462
`+
data = zipfp.read(n)
`
``
2463
`+
self.assertIn(b'FAVORITE_NUMBER', data)
`
``
2464
+
``
2465
`+
def test_read_zip_with_exe_prepended(self):
`
``
2466
`+
self._test_zip_works(self.exe_zip)
`
``
2467
+
``
2468
`+
def test_read_zip64_with_exe_prepended(self):
`
``
2469
`+
self._test_zip_works(self.exe_zip64)
`
``
2470
+
``
2471
`+
@unittest.skipUnless(sys.executable, 'sys.executable required.')
`
``
2472
`+
@unittest.skipUnless(os.access('/bin/bash', os.X_OK),
`
``
2473
`+
'Test relies on #!/bin/bash working.')
`
``
2474
`+
def test_execute_zip2(self):
`
``
2475
`+
output = subprocess.check_output([self.exe_zip, sys.executable])
`
``
2476
`+
self.assertIn(b'number in executable: 5', output)
`
``
2477
+
``
2478
`+
@unittest.skipUnless(sys.executable, 'sys.executable required.')
`
``
2479
`+
@unittest.skipUnless(os.access('/bin/bash', os.X_OK),
`
``
2480
`+
'Test relies on #!/bin/bash working.')
`
``
2481
`+
def test_execute_zip64(self):
`
``
2482
`+
output = subprocess.check_output([self.exe_zip64, sys.executable])
`
``
2483
`+
self.assertIn(b'number in executable: 5', output)
`
``
2484
+
``
2485
+
2446
2486
`class TestPath(unittest.TestCase):
`
2447
2487
`def setUp(self):
`
2448
2488
`self.fixtures = contextlib.ExitStack()
`