Skip to content

Commit

Permalink
[3.2.x] Skipped test_archive tests when bz2/lzma module is not instal…
Browse files Browse the repository at this point in the history
…led.

Backport of ae48601 from main
  • Loading branch information
felixxm committed Oct 5, 2021
1 parent 329311e commit faeae84
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/utils_tests/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
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):

Expand All @@ -22,6 +34,11 @@ def tearDown(self):
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')))
Expand All @@ -37,7 +54,11 @@ def test_extract_file_permissions(self):
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)
Expand Down

0 comments on commit faeae84

Please sign in to comment.