2022-04-14 11:02:52 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2019-02-08 11:26:15 +00:00
|
|
|
import sys
|
|
|
|
|
2021-03-15 17:08:45 +00:00
|
|
|
import pytest
|
2019-02-08 11:26:15 +00:00
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
from kombu import compression
|
2010-11-09 14:27:43 +00:00
|
|
|
|
|
|
|
|
2016-08-22 18:17:59 +00:00
|
|
|
class test_compression:
|
2010-11-09 14:27:43 +00:00
|
|
|
|
2016-04-05 21:57:00 +00:00
|
|
|
def test_encoders__gzip(self):
|
2016-08-22 18:17:59 +00:00
|
|
|
assert 'application/x-gzip' in compression.encoders()
|
2016-04-05 21:57:00 +00:00
|
|
|
|
|
|
|
def test_encoders__bz2(self):
|
2020-08-16 19:54:10 +00:00
|
|
|
pytest.importorskip('bz2')
|
2016-08-22 18:17:59 +00:00
|
|
|
assert 'application/x-bz2' in compression.encoders()
|
2010-11-09 14:27:43 +00:00
|
|
|
|
2019-01-09 17:05:02 +00:00
|
|
|
def test_encoders__brotli(self):
|
|
|
|
pytest.importorskip('brotli')
|
|
|
|
|
|
|
|
assert 'application/x-brotli' in compression.encoders()
|
|
|
|
|
2019-01-10 09:00:37 +00:00
|
|
|
def test_encoders__lzma(self):
|
|
|
|
pytest.importorskip('lzma')
|
|
|
|
|
|
|
|
assert 'application/x-lzma' in compression.encoders()
|
|
|
|
|
2019-01-13 07:44:44 +00:00
|
|
|
def test_encoders__zstd(self):
|
|
|
|
pytest.importorskip('zstandard')
|
|
|
|
|
|
|
|
assert 'application/zstd' in compression.encoders()
|
|
|
|
|
2010-11-09 14:27:43 +00:00
|
|
|
def test_compress__decompress__zlib(self):
|
2014-04-01 11:00:12 +00:00
|
|
|
text = b'The Quick Brown Fox Jumps Over The Lazy Dog'
|
2012-06-15 17:32:40 +00:00
|
|
|
c, ctype = compression.compress(text, 'zlib')
|
2016-08-22 18:17:59 +00:00
|
|
|
assert text != c
|
2010-11-09 14:27:43 +00:00
|
|
|
d = compression.decompress(c, ctype)
|
2016-08-22 18:17:59 +00:00
|
|
|
assert d == text
|
2010-11-09 14:27:43 +00:00
|
|
|
|
|
|
|
def test_compress__decompress__bzip2(self):
|
2014-04-01 11:00:12 +00:00
|
|
|
text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
|
2012-06-15 17:32:40 +00:00
|
|
|
c, ctype = compression.compress(text, 'bzip2')
|
2016-08-22 18:17:59 +00:00
|
|
|
assert text != c
|
2010-11-09 14:27:43 +00:00
|
|
|
d = compression.decompress(c, ctype)
|
2016-08-22 18:17:59 +00:00
|
|
|
assert d == text
|
2019-01-09 17:05:02 +00:00
|
|
|
|
|
|
|
def test_compress__decompress__brotli(self):
|
|
|
|
pytest.importorskip('brotli')
|
|
|
|
|
|
|
|
text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
|
|
|
|
c, ctype = compression.compress(text, 'brotli')
|
2019-01-10 09:00:37 +00:00
|
|
|
assert text != c
|
|
|
|
d = compression.decompress(c, ctype)
|
|
|
|
assert d == text
|
|
|
|
|
2021-03-15 17:08:45 +00:00
|
|
|
def test_compress__decompress__lzma(self):
|
|
|
|
pytest.importorskip('lzma')
|
2019-01-10 09:00:37 +00:00
|
|
|
|
|
|
|
text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
|
|
|
|
c, ctype = compression.compress(text, 'lzma')
|
2019-01-09 17:05:02 +00:00
|
|
|
assert text != c
|
|
|
|
d = compression.decompress(c, ctype)
|
|
|
|
assert d == text
|
2019-01-13 07:44:44 +00:00
|
|
|
|
|
|
|
def test_compress__decompress__zstd(self):
|
|
|
|
pytest.importorskip('zstandard')
|
|
|
|
|
|
|
|
text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
|
|
|
|
c, ctype = compression.compress(text, 'zstd')
|
|
|
|
assert text != c
|
|
|
|
d = compression.decompress(c, ctype)
|
|
|
|
assert d == text
|
2019-02-08 11:26:15 +00:00
|
|
|
|
2021-09-15 15:00:08 +00:00
|
|
|
@pytest.mark.masked_modules('bz2')
|
|
|
|
def test_no_bz2(self, mask_modules):
|
2019-02-08 11:26:15 +00:00
|
|
|
c = sys.modules.pop('kombu.compression')
|
|
|
|
try:
|
|
|
|
import kombu.compression
|
|
|
|
assert not hasattr(kombu.compression, 'bz2')
|
|
|
|
finally:
|
|
|
|
if c is not None:
|
|
|
|
sys.modules['kombu.compression'] = c
|
2021-03-15 17:08:45 +00:00
|
|
|
|
2021-09-15 15:00:08 +00:00
|
|
|
@pytest.mark.masked_modules('lzma')
|
|
|
|
def test_no_lzma(self, mask_modules):
|
2021-03-15 17:08:45 +00:00
|
|
|
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
|