8000 gh-108303: Move `zip` and `tar` archives to `Lib/test/archivetestdata… · python/cpython@890ef1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 890ef1b

Browse files
authored
gh-108303: Move zip and tar archives to Lib/test/archivetestdata (#111549)
1 parent 18c9548 commit 890ef1b

14 files changed

+24
-23
lines changed

Lib/test/ziptestdata/README.md renamed to Lib/test/archivetestdata/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
# Test data for `test_zipfile`
1+
# Test data for `test_zipfile`, `test_tarfile` (and even some others)
22

3-
The test executables in this directory are created manually from header.sh and
3+
## `test_zipfile`
4+
5+
The test executables in this directory are created manually from `header.sh` and
46
the `testdata_module_inside_zip.py` file. You must have Info-ZIP's zip utility
57
installed (`apt install zip` on Debian).
68

7-
## Purpose
9+
### Purpose of `exe_with_zip` and `exe_with_z64`
810

911
These are used to test executable files with an appended zipfile, in a scenario
1012
where the executable is _not_ a Python interpreter itself so our automatic
1113
zipimport machinery (that'd look for `__main__.py`) is not being used.
1214

13-
## Updating the test executables
15+
### Updating the test executables
1416

1517
If you update header.sh or the testdata_module_inside_zip.py file, rerun the
1618
commands below. These are expected to be rarely changed, if ever.
1719

18-
### Standard old format (2.0) zip file
20+
#### Standard old format (2.0) zip file
1921

2022
```
2123
zip -0 zip2.zip testdata_module_inside_zip.py
2224
cat header.sh zip2.zip >exe_with_zip
2325
rm zip2.zip
2426
```
2527

26-
### Modern format (4.5) zip64 file
28+
#### Modern format (4.5) zip64 file
2729

2830
Redirecting from stdin forces Info-ZIP's zip tool to create a zip64.
2931

@@ -32,4 +34,3 @@ zip -0 <testdata_module_inside_zip.py >zip64.zip
3234
cat header.sh zip64.zip >exe_with_z64
3335
rm zip64.zip
3436
```
35-
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Lib/test/test_contextlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ def test_simple(self):
13181318
def test_reentrant(self):
13191319
old_cwd = os.getcwd()
13201320
target1 = self.make_relative_path('data')
1321-
target2 = self.make_relative_path('ziptestdata')
1321+
target2 = self.make_relative_path('archivetestdata')
13221322
self.assertNotIn(old_cwd, (target1, target2))
13231323
chdir1, chdir2 = chdir(target1), chdir(target2)
13241324

Lib/test/test_tarfile.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def sha256sum(data):
4343

4444
TEMPDIR = os.path.abspath(os_helper.TESTFN) + "-tardir"
4545
tarextdir = TEMPDIR + '-extract-test'
46-
tarname = support.findfile("testtar.tar")
46+
tarname = support.findfile("testtar.tar", subdir="archivetestdata")
4747
gzipname = os.path.join(TEMPDIR, "testtar.tar.gz")
4848
bz2name = os.path.join(TEMPDIR, "testtar.tar.bz2")
4949
xzname = os.path.join(TEMPDIR, "testtar.tar.xz")
@@ -491,7 +491,7 @@ def test_length_zero_header(self):
491491
# bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
492492
# with an exception
493493
with self.assertRaisesRegex(tarfile.ReadError, "file could not be opened successfully"):
494-
with tarfile.open(support.findfile('recursion.tar')) as tar:
494+
with tarfile.open(support.findfile('recursion.tar', subdir='archivetestdata')):
495495
pass
496496

497497
def test_extractfile_name(self):
@@ -2565,7 +2565,7 @@ def test__all__(self):
25652565
support.check__all__(self, tarfile, not_exported=not_exported)
25662566

25672567
def test_useful_error_message_when_modules_missing(self):
2568-
fname = os.path.join(os.path.dirname(__file__), 'testtar.tar.xz')
2568+
fname = os.path.join(os.path.dirname(__file__), 'archivetestdata', 'testtar.tar.xz')
25692569
with self.assertRaises(tarfile.ReadError) as excinfo:
25702570
error = tarfile.CompressionError('lzma module is not available'),
25712571
with unittest.mock.patch.object(tarfile.TarFile, 'xzopen', side_effect=error):
@@ -2630,7 +2630,7 @@ def test_test_command_verbose(self):
26302630
self.assertIn(b'is a tar archive.\n', out)
26312631

26322632
def test_test_command_invalid_file(self):
2633-
zipname = support.findfile('zipdir.zip')
2633+
zipname = support.findfile('zipdir.zip', subdir='archivetestdata')
26342634
rc, out, err = self.tarfilecmd_failure('-t', zipname)
26352635
self.assertIn(b' is not a tar archive.', err)
26362636
self.assertEqual(out, b'')
@@ -2672,7 +2672,7 @@ def test_list_command_verbose(self):
26722672
self.assertEqual(out, expected)
26732673

26742674
def test_list_command_invalid_file(self):
2675-
zipname = support.findfile('zipdir.zip')
2675+
zipname = support.findfile('zipdir.zip', subdir='archivetestdata')
26762676
rc, out, err = self.tarfilecmd_failure('-l', zipname)
26772677
self.assertIn(b' is not a tar archive.', err)
26782678
self.assertEqual(out, b'')
@@ -2797,7 +2797,7 @@ def test_extract_command_different_directory(self):
27972797
os_helper.rmtree(tarextdir)
27982798

27992799
def test_extract_command_invalid_file(self):
2800-
zipname = support.findfile('zipdir.zip')
2800+
zipname = support.findfile('zipdir.zip', subdir='archivetestdata')
28012801
with os_helper.temp_cwd(tarextdir):
28022802
rc, out, err = self.tarfilecmd_failure('-e', zipname)
28032803
self.assertIn(b' is not a tar archive.', err)

Lib/test/test_zipfile/test_core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ def test_unsupported_version(self):
17541754
@requires_zlib()
17551755
def test_read_unicode_filenames(self):
17561756
# bug #10801
1757-
fname = findfile('zip_cp437_header.zip')
1757+
fname = findfile('zip_cp437_header.zip', subdir='archivetestdata')
17581758
with zipfile.ZipFile(fname) as zipfp:
17591759
for name in zipfp.namelist():
17601760
zipfp.open(name).close()
@@ -2804,7 +2804,7 @@ def setUp(self):
28042804
os.mkdir(TESTFN2)
28052805

28062806
def test_extract_dir(self):
2807-
with zipfile.ZipFile(findfile("zipdir.zip")) as zipf:
2807+
with zipfile.ZipFile(findfile("zipdir.zip", subdir="archivetestdata")) as zipf:
28082808
zipf.extractall(TESTFN2)
28092809
self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a")))
28102810
self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a", "b")))
@@ -2973,7 +2973,7 @@ def test_bad_use(self):
29732973
self.assertNotEqual(err.strip(), b'')
29742974

29752975
def test_test_command(self):
2976-
zip_name = findfile('zipdir.zip')
2976+
zip_name = findfile('zipdir.zip', subdir='archivetestdata')
29772977
for opt in '-t', '--test':
29782978
out = self.zipfilecmd(opt, zip_name)
29792979
self.assertEqual(out.rstrip(), b'Done testing')
@@ -2982,7 +2982,7 @@ def test_test_command(self):
29822982
self.assertEqual(out, b'')
29832983

29842984
def test_list_command(self):
2985-
zip_name = findfile('zipdir.zip')
2985+
zip_name = findfile('zipdir.zip', subdir='archivetestdata')
29862986
t = io.StringIO()
29872987
with zipfile.ZipFile(zip_name, 'r') as tf:
29882988
tf.printdir(t)
@@ -3015,7 +3015,7 @@ def test_create_command(self):
30153015
unlink(TESTFN2)
30163016

30173017
def test_extract_command(self):
3018-
zip_name = findfile('zipdir.zip')
3018+
zip_name = findfile('zipdir.zip', subdir='archivetestdata')
30193019
for opt in '-e', '--extract':
30203020
with temp_dir() as extdir:
30213021
out = self.zipfilecmd(opt, zip_name, extdir)
@@ -3036,8 +3036,8 @@ class TestExecutablePrependedZip(unittest.TestCase):
30363036
"""Test our ability to open zip files with an executable prepended."""
30373037

30383038
def setUp(self):
3039-
self.exe_zip = findfile('exe_with_zip', subdir='ziptestdata')
3040-
self.exe_zip64 = findfile('exe_with_z64', subdir='ziptestdata')
3039+
self.exe_zip = findfile('exe_with_zip', subdir='archivetestdata')
3040+
self.exe_zip64 = findfile('exe_with_z64', subdir='archivetestdata')
30413041

30423042
def _test_zip_works(self, name):
30433043
# bpo28494 sanity check: ensure is_zipfile works on these.

Makefile.pre.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,7 @@ LIBSUBDIRS= asyncio \
21692169
TESTSUBDIRS= idlelib/idle_test \
21702170
test \
21712171
test/audiodata \
2172+
test/archivetestdata \
21722173
test/certdata \
21732174
test/certdata/capath \
21742175
test/cjkencodings \
@@ -2283,8 +2284,7 @@ TESTSUBDIRS= idlelib/idle_test \
22832284
test/tracedmodules \
22842285
test/typinganndata \
22852286
test/xmltestdata \
2286-
test/xmltestdata/c14n-20 \
2287-
test/ziptestdata
2287+
test/xmltestdata/c14n-20
22882288

22892289
COMPILEALL_OPTS=-j0
22902290

0 commit comments

Comments
 (0)
0