diff mbox series

[21/22] tests/functional: add 'uncompress' to QemuBaseTest

Message ID 20241129173120.761728-22-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 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 | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index 31d06f0172..5c088a2442 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -29,7 +29,8 @@ 
 from .cmd import run_cmd
 from .config import BUILD_DIR
 from .utils import (archive_extract as utils_archive_extract,
-                    guess_archive_format)
+                    uncompress as utils_uncompress,
+                    guess_archive_format, guess_uncompress_format)
 
 
 class QemuBaseTest(unittest.TestCase):
@@ -41,6 +42,21 @@  class QemuBaseTest(unittest.TestCase):
     log = None
     logdir = None
 
+    def uncompress(self, input_path, format=None):
+        if type(input_path) == Asset:
+            if format is None:
+                format = guess_uncompress_format(input_path.url)
+            input_path = input_path.fetch()
+        elif format is None:
+            format = guess_uncompress_format(input_path)
+
+        (name, ext) = os.path.splitext(input_path)
+        output_path = self.scratch_file(os.path.basename(name))
+
+        utils_uncompress(input_path, output_path)
+
+        return output_path
+
     '''
     @params archive: filename, Asset, or file-like object to extract
     @params sub_dir: optional sub-directory to extract into