Pillow/Tests/test_decompression_bomb.py

41 lines
1020 B
Python
Raw Normal View History

from helper import unittest, PillowTestCase, tearDownModule
2014-05-27 13:40:52 +04:00
from PIL import Image
test_file = "Images/lena.ppm"
class TestDecompressionBomb(PillowTestCase):
2014-05-27 13:40:52 +04:00
def test_no_warning_small_file(self):
# Implicit assert: no warning.
# A warning would cause a failure.
Image.open(test_file)
2014-05-27 13:40:52 +04:00
def test_no_warning_no_limit(self):
# Arrange
# Turn limit off
Image.MAX_IMAGE_PIXELS = None
self.assertEqual(Image.MAX_IMAGE_PIXELS, None)
2014-05-27 13:40:52 +04:00
# Act / Assert
# Implicit assert: no warning.
# A warning would cause a failure.
Image.open(test_file)
2014-05-27 13:40:52 +04:00
def test_warning(self):
# Arrange
# Set limit to a low, easily testable value
Image.MAX_IMAGE_PIXELS = 10
self.assertEqual(Image.MAX_IMAGE_PIXELS, 10)
2014-05-27 13:40:52 +04:00
# Act / Assert
self.assert_warning(
Image.DecompressionBombWarning,
lambda: Image.open(test_file))
2014-05-27 13:40:52 +04:00
if __name__ == '__main__':
unittest.main()
2014-05-27 13:40:52 +04:00
# End of file