diff mbox series

[15/22] tests/functional: add common zip_extract helper

Message ID 20241129173120.761728-16-berrange@redhat.com (mailing list archive)
State New
Headers show
Series tests/functional: various improvements wrt assets/scratch files | expand

Commit Message

Daniel P. Berrangé Nov. 29, 2024, 5:31 p.m. UTC
This mirrors the existing archive_extract and cpio_extract helpers

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/functional/qemu_test/utils.py | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/tests/functional/qemu_test/utils.py b/tests/functional/qemu_test/utils.py
index 1bf1c410d5..41bd1df666 100644
--- a/tests/functional/qemu_test/utils.py
+++ b/tests/functional/qemu_test/utils.py
@@ -46,6 +46,13 @@  def archive_extract(archive, dest_dir, member=None):
         else:
             tf.extractall(path=dest_dir)
 
+def zip_extract(archive, dest_dir, member=None):
+    with zipfile.ZipFile(archive, 'r') as zf:
+        if member:
+            zf.extract(member=member, path=dest_dir)
+        else:
+            zf.extractall(path=dest_dir)
+
 def gzip_uncompress(gz_path, output_path):
     if os.path.exists(output_path):
         return