diff options
Diffstat (limited to 'Lib/test/archivetestdata')
-rw-r--r-- | Lib/test/archivetestdata/README.md | 36 | ||||
-rwxr-xr-x | Lib/test/archivetestdata/exe_with_z64 | bin | 0 -> 978 bytes | |||
-rwxr-xr-x | Lib/test/archivetestdata/exe_with_zip | bin | 0 -> 990 bytes | |||
-rwxr-xr-x | Lib/test/archivetestdata/header.sh | 24 | ||||
-rw-r--r-- | Lib/test/archivetestdata/recursion.tar | bin | 0 -> 516 bytes | |||
-rw-r--r-- | Lib/test/archivetestdata/testdata_module_inside_zip.py | 2 | ||||
-rw-r--r-- | Lib/test/archivetestdata/testtar.tar | bin | 0 -> 435200 bytes | |||
-rw-r--r-- | Lib/test/archivetestdata/testtar.tar.xz | bin | 0 -> 172 bytes | |||
-rw-r--r-- | Lib/test/archivetestdata/zip_cp437_header.zip | bin | 0 -> 270 bytes | |||
-rw-r--r-- | Lib/test/archivetestdata/zipdir.zip | bin | 0 -> 374 bytes |
10 files changed, 62 insertions, 0 deletions
diff --git a/Lib/test/archivetestdata/README.md b/Lib/test/archivetestdata/README.md new file mode 100644 index 0000000..7b555fa --- /dev/null +++ b/Lib/test/archivetestdata/README.md @@ -0,0 +1,36 @@ +# Test data for `test_zipfile`, `test_tarfile` (and even some others) + +## `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 +installed (`apt install zip` on Debian). + +### Purpose of `exe_with_zip` and `exe_with_z64` + +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 +zipimport machinery (that'd look for `__main__.py`) is not being used. + +### Updating the test executables + +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. + +#### Standard old format (2.0) zip file + +``` +zip -0 zip2.zip testdata_module_inside_zip.py +cat header.sh zip2.zip >exe_with_zip +rm zip2.zip +``` + +#### Modern format (4.5) zip64 file + +Redirecting from stdin forces Info-ZIP's zip tool to create a zip64. + +``` +zip -0 <testdata_module_inside_zip.py >zip64.zip +cat header.sh zip64.zip >exe_with_z64 +rm zip64.zip +``` diff --git a/Lib/test/archivetestdata/exe_with_z64 b/Lib/test/archivetestdata/exe_with_z64 Binary files differnew file mode 100755 index 0000000..82b03cf --- /dev/null +++ b/Lib/test/archivetestdata/exe_with_z64 diff --git a/Lib/test/archivetestdata/exe_with_zip b/Lib/test/archivetestdata/exe_with_zip Binary files differnew file mode 100755 index 0000000..c833cdf --- /dev/null +++ b/Lib/test/archivetestdata/exe_with_zip diff --git a/Lib/test/archivetestdata/header.sh b/Lib/test/archivetestdata/header.sh new file mode 100755 index 0000000..52dc91a --- /dev/null +++ b/Lib/test/archivetestdata/header.sh @@ -0,0 +1,24 @@ +#!/bin/bash +INTERPRETER_UNDER_TEST="$1" +if [[ ! -x "${INTERPRETER_UNDER_TEST}" ]]; then + echo "Interpreter must be the command line argument." + exit 4 +fi +EXECUTABLE="$0" exec "${INTERPRETER_UNDER_TEST}" -E - <<END_OF_PYTHON +import os +import zipfile + +namespace = {} + +filename = os.environ['EXECUTABLE'] +print(f'Opening {filename} as a zipfile.') +with zipfile.ZipFile(filename, mode='r') as exe_zip: + for file_info in exe_zip.infolist(): + data = exe_zip.read(file_info) + exec(data, namespace, namespace) + break # Only use the first file in the archive. + +print('Favorite number in executable:', namespace["FAVORITE_NUMBER"]) + +### Archive contents will be appended after this file. ### +END_OF_PYTHON diff --git a/Lib/test/archivetestdata/recursion.tar b/Lib/test/archivetestdata/recursion.tar Binary files differnew file mode 100644 index 0000000..b823725 --- /dev/null +++ b/Lib/test/archivetestdata/recursion.tar diff --git a/Lib/test/archivetestdata/testdata_module_inside_zip.py b/Lib/test/archivetestdata/testdata_module_inside_zip.py new file mode 100644 index 0000000..6f8dcd6 --- /dev/null +++ b/Lib/test/archivetestdata/testdata_module_inside_zip.py @@ -0,0 +1,2 @@ +# Test data file to be stored within a zip file. +FAVORITE_NUMBER = 5 diff --git a/Lib/test/archivetestdata/testtar.tar b/Lib/test/archivetestdata/testtar.tar Binary files differnew file mode 100644 index 0000000..bb93453 --- /dev/null +++ b/Lib/test/archivetestdata/testtar.tar diff --git a/Lib/test/archivetestdata/testtar.tar.xz b/Lib/test/archivetestdata/testtar.tar.xz Binary files differnew file mode 100644 index 0000000..512fa14 --- /dev/null +++ b/Lib/test/archivetestdata/testtar.tar.xz diff --git a/Lib/test/archivetestdata/zip_cp437_header.zip b/Lib/test/archivetestdata/zip_cp437_header.zip Binary files differnew file mode 100644 index 0000000..f7c6cf1 --- /dev/null +++ b/Lib/test/archivetestdata/zip_cp437_header.zip diff --git a/Lib/test/archivetestdata/zipdir.zip b/Lib/test/archivetestdata/zipdir.zip Binary files differnew file mode 100644 index 0000000..ac21d7a --- /dev/null +++ b/Lib/test/archivetestdata/zipdir.zip |