summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_shutil.py23
-rw-r--r--Lib/zipfile.py4
2 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 673d36b..d2d4d03 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -1099,6 +1099,29 @@ class TestShutil(unittest.TestCase):
names2 = zf.namelist()
self.assertEqual(sorted(names), sorted(names2))
+ @requires_zlib
+ @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
+ @unittest.skipUnless(shutil.which('unzip'),
+ 'Need the unzip command to run')
+ def test_unzip_zipfile(self):
+ root_dir, base_dir = self._create_files()
+ base_name = os.path.join(self.mkdtemp(), 'archive')
+ archive = make_archive(base_name, 'zip', root_dir, base_dir)
+
+ # check if ZIP file was created
+ self.assertEqual(archive, base_name + '.zip')
+ self.assertTrue(os.path.isfile(archive))
+
+ # now check the ZIP file using `unzip -t`
+ zip_cmd = ['unzip', '-t', archive]
+ with support.change_cwd(root_dir):
+ try:
+ subprocess.check_output(zip_cmd, stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError as exc:
+ details = exc.output.decode(errors="replace")
+ msg = "{}\n\n**Unzip Output**\n{}"
+ self.fail(msg.format(exc, details))
+
def test_make_archive(self):
tmpdir = self.mkdtemp()
base_name = os.path.join(tmpdir, 'archive')
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index bda6134..11d7cf9 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1337,7 +1337,9 @@ class ZipFile:
arcname += '/'
zinfo = ZipInfo(arcname, date_time)
zinfo.external_attr = (st[0] & 0xFFFF) << 16 # Unix attributes
- if compress_type is None:
+ if isdir:
+ zinfo.compress_type = ZIP_STORED
+ elif compress_type is None:
zinfo.compress_type = self.compression
else:
zinfo.compress_type = compress_type