diff mbox series

[v2,25/31] tests/functional: add 'uncompress' to QemuBaseTest

Message ID 20241211172648.2893097-26-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é Dec. 11, 2024, 5:26 p.m. UTC
This helper wrappers utils.uncompress, forcing the use of the scratch
directory, to ensure any uncompressed files are cleaned at test
termination.

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

Comments

Thomas Huth Dec. 12, 2024, 10:43 a.m. UTC | #1
On 11/12/2024 18.26, Daniel P. Berrangé wrote:
> This helper wrappers utils.uncompress, forcing the use of the scratch
> directory, to ensure any uncompressed files are cleaned at test
> termination.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/functional/qemu_test/testcase.py | 25 +++++++++++++++++++++++++
>   1 file changed, 25 insertions(+)
> 
> diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> index 19fb1d0c07..684c94d45f 100644
> --- a/tests/functional/qemu_test/testcase.py
> +++ b/tests/functional/qemu_test/testcase.py
> @@ -29,6 +29,7 @@
>   from .asset import Asset
>   from .cmd import run_cmd
>   from .config import BUILD_DIR
> +from .uncompress import uncompress
>   
>   
>   class QemuBaseTest(unittest.TestCase):
> @@ -40,6 +41,30 @@ class QemuBaseTest(unittest.TestCase):
>       log = None
>       logdir = None
>   
> +    '''
> +    @params compressed: filename, Asset, or file-like object to uncompress
> +    @params format: optional compression format (gzip, lzma)
> +
> +    Uncompresses @compressed into the scratch directory.
> +
> +    If @format is None, heuristics will be applied to guess the format
> +    from the filename or Asset URL. @format must be non-None if @uncompressed
> +    is a file-like object.
> +
> +    Returns the fully qualified path to the uncompessed file

s/uncompessed/uncompressed/

With the typo fixed:
Reviewed-by: Thomas Huth <thuth@redhat.com>
diff mbox series

Patch

diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index 19fb1d0c07..684c94d45f 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -29,6 +29,7 @@ 
 from .asset import Asset
 from .cmd import run_cmd
 from .config import BUILD_DIR
+from .uncompress import uncompress
 
 
 class QemuBaseTest(unittest.TestCase):
@@ -40,6 +41,30 @@  class QemuBaseTest(unittest.TestCase):
     log = None
     logdir = None
 
+    '''
+    @params compressed: filename, Asset, or file-like object to uncompress
+    @params format: optional compression format (gzip, lzma)
+
+    Uncompresses @compressed into the scratch directory.
+
+    If @format is None, heuristics will be applied to guess the format
+    from the filename or Asset URL. @format must be non-None if @uncompressed
+    is a file-like object.
+
+    Returns the fully qualified path to the uncompessed file
+    '''
+    def uncompress(self, compressed, format=None):
+        self.log.debug(f"Uncompress {compressed} format={format}")
+        if type(compressed) == Asset:
+            compressed.fetch()
+
+        (name, ext) = os.path.splitext(str(compressed))
+        uncompressed = self.scratch_file(os.path.basename(name))
+
+        uncompress(compressed, uncompressed, format)
+
+        return uncompressed
+
     '''
     @params archive: filename, Asset, or file-like object to extract
     @params format: optional archive format (tar, zip, deb, cpio)