mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-108303: Move zip
and tar
archives to Lib/test/archivetestdata
(#111549)
This commit is contained in:
parent
18c954849b
commit
890ef1b035
14 changed files with 24 additions and 23 deletions
|
@ -1,21 +1,23 @@
|
||||||
# Test data for `test_zipfile`
|
# Test data for `test_zipfile`, `test_tarfile` (and even some others)
|
||||||
|
|
||||||
The test executables in this directory are created manually from header.sh and
|
## `test_zipfile`
|
||||||
|
|
||||||
|
The test executables in this directory are created manually from `header.sh` and
|
||||||
the `testdata_module_inside_zip.py` file. You must have Info-ZIP's zip utility
|
the `testdata_module_inside_zip.py` file. You must have Info-ZIP's zip utility
|
||||||
installed (`apt install zip` on Debian).
|
installed (`apt install zip` on Debian).
|
||||||
|
|
||||||
## Purpose
|
### Purpose of `exe_with_zip` and `exe_with_z64`
|
||||||
|
|
||||||
These are used to test executable files with an appended zipfile, in a scenario
|
These are used to test executable files with an appended zipfile, in a scenario
|
||||||
where the executable is _not_ a Python interpreter itself so our automatic
|
where the executable is _not_ a Python interpreter itself so our automatic
|
||||||
zipimport machinery (that'd look for `__main__.py`) is not being used.
|
zipimport machinery (that'd look for `__main__.py`) is not being used.
|
||||||
|
|
||||||
## Updating the test executables
|
### Updating the test executables
|
||||||
|
|
||||||
If you update header.sh or the testdata_module_inside_zip.py file, rerun the
|
If you update header.sh or the testdata_module_inside_zip.py file, rerun the
|
||||||
commands below. These are expected to be rarely changed, if ever.
|
commands below. These are expected to be rarely changed, if ever.
|
||||||
|
|
||||||
### Standard old format (2.0) zip file
|
#### Standard old format (2.0) zip file
|
||||||
|
|
||||||
```
|
```
|
||||||
zip -0 zip2.zip testdata_module_inside_zip.py
|
zip -0 zip2.zip testdata_module_inside_zip.py
|
||||||
|
@ -23,7 +25,7 @@ cat header.sh zip2.zip >exe_with_zip
|
||||||
rm zip2.zip
|
rm zip2.zip
|
||||||
```
|
```
|
||||||
|
|
||||||
### Modern format (4.5) zip64 file
|
#### Modern format (4.5) zip64 file
|
||||||
|
|
||||||
Redirecting from stdin forces Info-ZIP's zip tool to create a zip64.
|
Redirecting from stdin forces Info-ZIP's zip tool to create a zip64.
|
||||||
|
|
||||||
|
@ -32,4 +34,3 @@ zip -0 <testdata_module_inside_zip.py >zip64.zip
|
||||||
cat header.sh zip64.zip >exe_with_z64
|
cat header.sh zip64.zip >exe_with_z64
|
||||||
rm zip64.zip
|
rm zip64.zip
|
||||||
```
|
```
|
||||||
|
|
|
@ -1318,7 +1318,7 @@ class TestChdir(unittest.TestCase):
|
||||||
def test_reentrant(self):
|
def test_reentrant(self):
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
target1 = self.make_relative_path('data')
|
target1 = self.make_relative_path('data')
|
||||||
target2 = self.make_relative_path('ziptestdata')
|
target2 = self.make_relative_path('archivetestdata')
|
||||||
self.assertNotIn(old_cwd, (target1, target2))
|
self.assertNotIn(old_cwd, (target1, target2))
|
||||||
chdir1, chdir2 = chdir(target1), chdir(target2)
|
chdir1, chdir2 = chdir(target1), chdir(target2)
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ def sha256sum(data):
|
||||||
|
|
||||||
TEMPDIR = os.path.abspath(os_helper.TESTFN) + "-tardir"
|
TEMPDIR = os.path.abspath(os_helper.TESTFN) + "-tardir"
|
||||||
tarextdir = TEMPDIR + '-extract-test'
|
tarextdir = TEMPDIR + '-extract-test'
|
||||||
tarname = support.findfile("testtar.tar")
|
tarname = support.findfile("testtar.tar", subdir="archivetestdata")
|
||||||
gzipname = os.path.join(TEMPDIR, "testtar.tar.gz")
|
gzipname = os.path.join(TEMPDIR, "testtar.tar.gz")
|
||||||
bz2name = os.path.join(TEMPDIR, "testtar.tar.bz2")
|
bz2name = os.path.join(TEMPDIR, "testtar.tar.bz2")
|
||||||
xzname = os.path.join(TEMPDIR, "testtar.tar.xz")
|
xzname = os.path.join(TEMPDIR, "testtar.tar.xz")
|
||||||
|
@ -491,7 +491,7 @@ class CommonReadTest(ReadTest):
|
||||||
# bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
|
# bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
|
||||||
# with an exception
|
# with an exception
|
||||||
with self.assertRaisesRegex(tarfile.ReadError, "file could not be opened successfully"):
|
with self.assertRaisesRegex(tarfile.ReadError, "file could not be opened successfully"):
|
||||||
with tarfile.open(support.findfile('recursion.tar')) as tar:
|
with tarfile.open(support.findfile('recursion.tar', subdir='archivetestdata')):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_extractfile_name(self):
|
def test_extractfile_name(self):
|
||||||
|
@ -2565,7 +2565,7 @@ class MiscTest(unittest.TestCase):
|
||||||
support.check__all__(self, tarfile, not_exported=not_exported)
|
support.check__all__(self, tarfile, not_exported=not_exported)
|
||||||
|
|
||||||
def test_useful_error_message_when_modules_missing(self):
|
def test_useful_error_message_when_modules_missing(self):
|
||||||
fname = os.path.join(os.path.dirname(__file__), 'testtar.tar.xz')
|
fname = os.path.join(os.path.dirname(__file__), 'archivetestdata', 'testtar.tar.xz')
|
||||||
with self.assertRaises(tarfile.ReadError) as excinfo:
|
with self.assertRaises(tarfile.ReadError) as excinfo:
|
||||||
error = tarfile.CompressionError('lzma module is not available'),
|
error = tarfile.CompressionError('lzma module is not available'),
|
||||||
with unittest.mock.patch.object(tarfile.TarFile, 'xzopen', side_effect=error):
|
with unittest.mock.patch.object(tarfile.TarFile, 'xzopen', side_effect=error):
|
||||||
|
@ -2630,7 +2630,7 @@ class CommandLineTest(unittest.TestCase):
|
||||||
self.assertIn(b'is a tar archive.\n', out)
|
self.assertIn(b'is a tar archive.\n', out)
|
||||||
|
|
||||||
def test_test_command_invalid_file(self):
|
def test_test_command_invalid_file(self):
|
||||||
zipname = support.findfile('zipdir.zip')
|
zipname = support.findfile('zipdir.zip', subdir='archivetestdata')
|
||||||
rc, out, err = self.tarfilecmd_failure('-t', zipname)
|
rc, out, err = self.tarfilecmd_failure('-t', zipname)
|
||||||
self.assertIn(b' is not a tar archive.', err)
|
self.assertIn(b' is not a tar archive.', err)
|
||||||
self.assertEqual(out, b'')
|
self.assertEqual(out, b'')
|
||||||
|
@ -2672,7 +2672,7 @@ class CommandLineTest(unittest.TestCase):
|
||||||
self.assertEqual(out, expected)
|
self.assertEqual(out, expected)
|
||||||
|
|
||||||
def test_list_command_invalid_file(self):
|
def test_list_command_invalid_file(self):
|
||||||
zipname = support.findfile('zipdir.zip')
|
zipname = support.findfile('zipdir.zip', subdir='archivetestdata')
|
||||||
rc, out, err = self.tarfilecmd_failure('-l', zipname)
|
rc, out, err = self.tarfilecmd_failure('-l', zipname)
|
||||||
self.assertIn(b' is not a tar archive.', err)
|
self.assertIn(b' is not a tar archive.', err)
|
||||||
self.assertEqual(out, b'')
|
self.assertEqual(out, b'')
|
||||||
|
@ -2797,7 +2797,7 @@ class CommandLineTest(unittest.TestCase):
|
||||||
os_helper.rmtree(tarextdir)
|
os_helper.rmtree(tarextdir)
|
||||||
|
|
||||||
def test_extract_command_invalid_file(self):
|
def test_extract_command_invalid_file(self):
|
||||||
zipname = support.findfile('zipdir.zip')
|
zipname = support.findfile('zipdir.zip', subdir='archivetestdata')
|
||||||
with os_helper.temp_cwd(tarextdir):
|
with os_helper.temp_cwd(tarextdir):
|
||||||
rc, out, err = self.tarfilecmd_failure('-e', zipname)
|
rc, out, err = self.tarfilecmd_failure('-e', zipname)
|
||||||
self.assertIn(b' is not a tar archive.', err)
|
self.assertIn(b' is not a tar archive.', err)
|
||||||
|
|
|
@ -1754,7 +1754,7 @@ class OtherTests(unittest.TestCase):
|
||||||
@requires_zlib()
|
@requires_zlib()
|
||||||
def test_read_unicode_filenames(self):
|
def test_read_unicode_filenames(self):
|
||||||
# bug #10801
|
# bug #10801
|
||||||
fname = findfile('zip_cp437_header.zip')
|
fname = findfile('zip_cp437_header.zip', subdir='archivetestdata')
|
||||||
with zipfile.ZipFile(fname) as zipfp:
|
with zipfile.ZipFile(fname) as zipfp:
|
||||||
for name in zipfp.namelist():
|
for name in zipfp.namelist():
|
||||||
zipfp.open(name).close()
|
zipfp.open(name).close()
|
||||||
|
@ -2804,7 +2804,7 @@ class TestWithDirectory(unittest.TestCase):
|
||||||
os.mkdir(TESTFN2)
|
os.mkdir(TESTFN2)
|
||||||
|
|
||||||
def test_extract_dir(self):
|
def test_extract_dir(self):
|
||||||
with zipfile.ZipFile(findfile("zipdir.zip")) as zipf:
|
with zipfile.ZipFile(findfile("zipdir.zip", subdir="archivetestdata")) as zipf:
|
||||||
zipf.extractall(TESTFN2)
|
zipf.extractall(TESTFN2)
|
||||||
self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a")))
|
self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a")))
|
||||||
self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a", "b")))
|
self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a", "b")))
|
||||||
|
@ -2973,7 +2973,7 @@ class CommandLineTest(unittest.TestCase):
|
||||||
self.assertNotEqual(err.strip(), b'')
|
self.assertNotEqual(err.strip(), b'')
|
||||||
|
|
||||||
def test_test_command(self):
|
def test_test_command(self):
|
||||||
zip_name = findfile('zipdir.zip')
|
zip_name = findfile('zipdir.zip', subdir='archivetestdata')
|
||||||
for opt in '-t', '--test':
|
for opt in '-t', '--test':
|
||||||
out = self.zipfilecmd(opt, zip_name)
|
out = self.zipfilecmd(opt, zip_name)
|
||||||
self.assertEqual(out.rstrip(), b'Done testing')
|
self.assertEqual(out.rstrip(), b'Done testing')
|
||||||
|
@ -2982,7 +2982,7 @@ class CommandLineTest(unittest.TestCase):
|
||||||
self.assertEqual(out, b'')
|
self.assertEqual(out, b'')
|
||||||
|
|
||||||
def test_list_command(self):
|
def test_list_command(self):
|
||||||
zip_name = findfile('zipdir.zip')
|
zip_name = findfile('zipdir.zip', subdir='archivetestdata')
|
||||||
t = io.StringIO()
|
t = io.StringIO()
|
||||||
with zipfile.ZipFile(zip_name, 'r') as tf:
|
with zipfile.ZipFile(zip_name, 'r') as tf:
|
||||||
tf.printdir(t)
|
tf.printdir(t)
|
||||||
|
@ -3015,7 +3015,7 @@ class CommandLineTest(unittest.TestCase):
|
||||||
unlink(TESTFN2)
|
unlink(TESTFN2)
|
||||||
|
|
||||||
def test_extract_command(self):
|
def test_extract_command(self):
|
||||||
zip_name = findfile('zipdir.zip')
|
zip_name = findfile('zipdir.zip', subdir='archivetestdata')
|
||||||
for opt in '-e', '--extract':
|
for opt in '-e', '--extract':
|
||||||
with temp_dir() as extdir:
|
with temp_dir() as extdir:
|
||||||
out = self.zipfilecmd(opt, zip_name, extdir)
|
out = self.zipfilecmd(opt, zip_name, extdir)
|
||||||
|
@ -3036,8 +3036,8 @@ class TestExecutablePrependedZip(unittest.TestCase):
|
||||||
"""Test our ability to open zip files with an executable prepended."""
|
"""Test our ability to open zip files with an executable prepended."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.exe_zip = findfile('exe_with_zip', subdir='ziptestdata')
|
self.exe_zip = findfile('exe_with_zip', subdir='archivetestdata')
|
||||||
self.exe_zip64 = findfile('exe_with_z64', subdir='ziptestdata')
|
self.exe_zip64 = findfile('exe_with_z64', subdir='archivetestdata')
|
||||||
|
|
||||||
def _test_zip_works(self, name):
|
def _test_zip_works(self, name):
|
||||||
# bpo28494 sanity check: ensure is_zipfile works on these.
|
# bpo28494 sanity check: ensure is_zipfile works on these.
|
||||||
|
|
|
@ -2169,6 +2169,7 @@ LIBSUBDIRS= asyncio \
|
||||||
TESTSUBDIRS= idlelib/idle_test \
|
TESTSUBDIRS= idlelib/idle_test \
|
||||||
test \
|
test \
|
||||||
test/audiodata \
|
test/audiodata \
|
||||||
|
test/archivetestdata \
|
||||||
test/certdata \
|
test/certdata \
|
||||||
test/certdata/capath \
|
test/certdata/capath \
|
||||||
test/cjkencodings \
|
test/cjkencodings \
|
||||||
|
@ -2283,8 +2284,7 @@ TESTSUBDIRS= idlelib/idle_test \
|
||||||
test/tracedmodules \
|
test/tracedmodules \
|
||||||
test/typinganndata \
|
test/typinganndata \
|
||||||
test/xmltestdata \
|
test/xmltestdata \
|
||||||
test/xmltestdata/c14n-20 \
|
test/xmltestdata/c14n-20
|
||||||
test/ziptestdata
|
|
||||||
|
|
||||||
COMPILEALL_OPTS=-j0
|
COMPILEALL_OPTS=-j0
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue