From 1e20625d7b7c707b966d6450a32e2d7e58d8da6a Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 15 Mar 2021 19:08:45 +0200 Subject: Drop support for the lzma backport. --- kombu/compression.py | 20 +++++++------------- t/unit/test_compression.py | 28 +++++++++++++--------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/kombu/compression.py b/kombu/compression.py index b5242672..d9438539 100644 --- a/kombu/compression.py +++ b/kombu/compression.py @@ -1,17 +1,8 @@ """Compression utilities.""" -from kombu.utils.encoding import ensure_bytes - import zlib -try: - import lzma -except ImportError: # pragma: no cover - # TODO: Drop fallback to backports once we drop Python 2.7 support - try: - from backports import lzma - except ImportError: # pragma: no cover - lzma = None +from kombu.utils.encoding import ensure_bytes _aliases = {} _encoders = {} @@ -82,7 +73,7 @@ register(zlib.compress, try: import bz2 -except ImportError: +except ImportError: # pragma: no cover pass # No bz2 support else: register(bz2.compress, @@ -98,8 +89,11 @@ else: brotli.decompress, 'application/x-brotli', aliases=['brotli']) -# TODO: Drop condition once we drop Python 2.7 support -if lzma: # pragma: no cover +try: + import lzma +except ImportError: # pragma: no cover + pass # no lzma support +else: register(lzma.compress, lzma.decompress, 'application/x-lzma', aliases=['lzma', 'xz']) diff --git a/t/unit/test_compression.py b/t/unit/test_compression.py index 9c94c79c..d62444af 100644 --- a/t/unit/test_compression.py +++ b/t/unit/test_compression.py @@ -1,7 +1,6 @@ -import pytest - import sys +import pytest from case import mock from kombu import compression @@ -26,11 +25,6 @@ class test_compression: assert 'application/x-lzma' in compression.encoders() - def test_encoders__backports_lzma(self): - pytest.importorskip('backports.lzma') - - assert 'application/x-lzma' in compression.encoders() - def test_encoders__zstd(self): pytest.importorskip('zstandard') @@ -55,18 +49,12 @@ class test_compression: text = b'The Brown Quick Fox Over The Lazy Dog Jumps' c, ctype = compression.compress(text, 'brotli') - - def test_compress__decompress__lzma(self): - pytest.importorskip('lzma') - - text = b'The Brown Quick Fox Over The Lazy Dog Jumps' - c, ctype = compression.compress(text, 'lzma') assert text != c d = compression.decompress(c, ctype) assert d == text - def test_compress__decompress__backports_lzma(self): - pytest.importorskip('backports.lzma') + def test_compress__decompress__lzma(self): + pytest.importorskip('lzma') text = b'The Brown Quick Fox Over The Lazy Dog Jumps' c, ctype = compression.compress(text, 'lzma') @@ -92,3 +80,13 @@ class test_compression: finally: if c is not None: sys.modules['kombu.compression'] = c + + @mock.mask_modules('lzma') + def test_no_lzma(self): + c = sys.modules.pop('kombu.compression') + try: + import kombu.compression + assert not hasattr(kombu.compression, 'lzma') + finally: + if c is not None: + sys.modules['kombu.compression'] = c -- cgit v1.2.1