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

Daniel P. Berrangé posted 22 patches 3 weeks, 5 days ago
There is a newer version of this series
[PATCH 15/22] tests/functional: add common zip_extract helper
Posted by Daniel P. Berrangé 3 weeks, 5 days ago
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 --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
-- 
2.46.0


Re: [PATCH 15/22] tests/functional: add common zip_extract helper
Posted by Thomas Huth 3 weeks, 3 days ago
On 29/11/2024 18.31, Daniel P. Berrangé wrote:
> 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 --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)

Don't you need to "import zipfile" here now, too?

  Thomas


Re: [PATCH 15/22] tests/functional: add common zip_extract helper
Posted by Daniel P. Berrangé 3 weeks, 3 days ago
On Mon, Dec 02, 2024 at 11:04:12AM +0100, Thomas Huth wrote:
> On 29/11/2024 18.31, Daniel P. Berrangé wrote:
> > 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 --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)
> 
> Don't you need to "import zipfile" here now, too?

Yes, now I'm wondering how my testing passed - wonder if this is only
being used from some skipped tests that I forgot to exercise.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|