summaryrefslogtreecommitdiff
path: root/tests/utils_tests/test_archive.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-02-04 14:08:43 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-10-05 11:00:25 +0200
commitfaeae84dad15c3fe9dc989aa540f0556b7904a95 (patch)
treea937af02f2cd1db3a53f5a6088b39bcbd790104a /tests/utils_tests/test_archive.py
parent329311ecbdb2387edc9dda20c586a8d971784376 (diff)
[3.2.x] Skipped test_archive tests when bz2/lzma module is not installed.
Backport of ae48601e6d88410626c7d28572f969ab57b33598 from main
Diffstat (limited to 'tests/utils_tests/test_archive.py')
-rw-r--r--tests/utils_tests/test_archive.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/utils_tests/test_archive.py b/tests/utils_tests/test_archive.py
index 8fdf3ec445..4eb47d2fad 100644
--- a/tests/utils_tests/test_archive.py
+++ b/tests/utils_tests/test_archive.py
@@ -8,6 +8,18 @@ from django.core.exceptions import SuspiciousOperation
from django.test import SimpleTestCase
from django.utils import archive
+try:
+ import bz2 # NOQA
+ HAS_BZ2 = True
+except ImportError:
+ HAS_BZ2 = False
+
+try:
+ import lzma # NOQA
+ HAS_LZMA = True
+except ImportError:
+ HAS_LZMA = False
+
class TestArchive(unittest.TestCase):
@@ -22,6 +34,11 @@ class TestArchive(unittest.TestCase):
def test_extract_function(self):
for entry in os.scandir(self.testdir):
with self.subTest(entry.name), tempfile.TemporaryDirectory() as tmpdir:
+ if (
+ (entry.name.endswith('.bz2') and not HAS_BZ2) or
+ (entry.name.endswith(('.lzma', '.xz')) and not HAS_LZMA)
+ ):
+ continue
archive.extract(entry.path, tmpdir)
self.assertTrue(os.path.isfile(os.path.join(tmpdir, '1')))
self.assertTrue(os.path.isfile(os.path.join(tmpdir, '2')))
@@ -37,7 +54,11 @@ class TestArchive(unittest.TestCase):
umask = os.umask(0)
os.umask(umask) # Restore the original umask.
for entry in os.scandir(self.testdir):
- if entry.name.startswith('leadpath_'):
+ if (
+ entry.name.startswith('leadpath_') or
+ (entry.name.endswith('.bz2') and not HAS_BZ2) or
+ (entry.name.endswith(('.lzma', '.xz')) and not HAS_LZMA)
+ ):
continue
with self.subTest(entry.name), tempfile.TemporaryDirectory() as tmpdir:
archive.extract(entry.path, tmpdir)