[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 7/8] tests/pytest: Add a function for extracting files from a
From: |
Thomas Huth |
Subject: |
[RFC PATCH 7/8] tests/pytest: Add a function for extracting files from an archive |
Date: |
Thu, 11 Jul 2024 13:55:45 +0200 |
Some Avocado-based tests use the "archive" module from avocado.utils
to extract files from an archive. To be able to use these tests
without Avocado, we have to provide our own function for extracting
files. Fortunately, there is already the tarfile module that will
provide us with this functionality, so let's just add a nice wrapper
function around that.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/pytest/qemu_pytest/utils.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 tests/pytest/qemu_pytest/utils.py
diff --git a/tests/pytest/qemu_pytest/utils.py
b/tests/pytest/qemu_pytest/utils.py
new file mode 100644
index 0000000000..4eb5e5d5e5
--- /dev/null
+++ b/tests/pytest/qemu_pytest/utils.py
@@ -0,0 +1,21 @@
+# Utilities for python-based QEMU tests
+#
+# Copyright 2024 Red Hat, Inc.
+#
+# Authors:
+# Thomas Huth <thuth@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later. See the COPYING file in the top-level directory.
+
+import tarfile
+
+def archive_extract(archive, dest_dir, member=None):
+ with tarfile.open(archive) as tf:
+ if hasattr(tarfile, 'data_filter'):
+ tf.extraction_filter = getattr(tarfile, 'data_filter',
+ (lambda member, path: member))
+ if member:
+ tf.extract(member=member, path=dest_dir)
+ else:
+ tf.extractall(path=dest_dir)
--
2.45.2
Re: [RFC PATCH 5/8] tests_pytest: Implement fetch_asset() method for downloading assets, Daniel P . Berrangé, 2024/07/12
[RFC PATCH 8/8] tests/pytest: Convert avocado test that needed avocado.utils.archive, Thomas Huth, 2024/07/11
[RFC PATCH 7/8] tests/pytest: Add a function for extracting files from an archive,
Thomas Huth <=
[RFC PATCH 6/8] tests/pytest: Convert some tests that download files via fetch_asset(), Thomas Huth, 2024/07/11
Re: [RFC PATCH 0/8] Convert avocado tests to normal Python unittests, Daniel P . Berrangé, 2024/07/11
Re: [RFC PATCH 0/8] Convert avocado tests to normal Python unittests, Fabiano Rosas, 2024/07/11