Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_compression.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from __future__ import absolute_import
  2. import sys
  3. from kombu import compression
  4. from .case import Case, SkipTest, mask_modules
  5. class test_compression(Case):
  6. def setUp(self):
  7. try:
  8. import bz2 # noqa
  9. except ImportError:
  10. self.has_bzip2 = False
  11. else:
  12. self.has_bzip2 = True
  13. @mask_modules('bz2')
  14. def test_no_bz2(self):
  15. c = sys.modules.pop('kombu.compression')
  16. try:
  17. import kombu.compression
  18. self.assertFalse(hasattr(kombu.compression, 'bz2'))
  19. finally:
  20. if c is not None:
  21. sys.modules['kombu.compression'] = c
  22. def test_encoders(self):
  23. encoders = compression.encoders()
  24. self.assertIn('application/x-gzip', encoders)
  25. if self.has_bzip2:
  26. self.assertIn('application/x-bz2', encoders)
  27. def test_compress__decompress__zlib(self):
  28. text = b'The Quick Brown Fox Jumps Over The Lazy Dog'
  29. c, ctype = compression.compress(text, 'zlib')
  30. self.assertNotEqual(text, c)
  31. d = compression.decompress(c, ctype)
  32. self.assertEqual(d, text)
  33. def test_compress__decompress__bzip2(self):
  34. if not self.has_bzip2:
  35. raise SkipTest('bzip2 not available')
  36. text = b'The Brown Quick Fox Over The Lazy Dog Jumps'
  37. c, ctype = compression.compress(text, 'bzip2')
  38. self.assertNotEqual(text, c)
  39. d = compression.decompress(c, ctype)
  40. self.assertEqual(d, text)