Pillow/Tests/test_image_resample.py

38 lines
1.2 KiB
Python
Raw Normal View History

2016-02-04 15:17:00 +03:00
from helper import unittest, PillowTestCase, hopper
from PIL import Image
2016-02-05 01:57:13 +03:00
2016-02-04 15:17:00 +03:00
class TestImagingCoreResize(PillowTestCase):
2016-02-05 01:57:13 +03:00
# see https://github.com/python-pillow/Pillow/issues/1710
2016-02-04 15:17:00 +03:00
def test_overflow(self):
im = hopper('L')
xsize = 0x100000008 // 4
2016-02-05 01:57:13 +03:00
ysize = 1000 # unimportant
2016-02-04 15:17:00 +03:00
try:
2016-02-04 17:57:57 +03:00
# any resampling filter will do here
2016-02-05 01:57:13 +03:00
im.im.resize((xsize, ysize), Image.LINEAR)
2016-02-04 15:17:00 +03:00
self.fail("Resize should raise MemoryError on invalid xsize")
except MemoryError:
self.assertTrue(True, "Should raise MemoryError")
2016-02-04 17:57:57 +03:00
def test_invalid_size(self):
im = hopper()
2016-02-05 01:57:13 +03:00
im.resize((100, 100))
2016-02-04 17:57:57 +03:00
self.assertTrue(True, "Should not Crash")
2016-02-05 01:57:13 +03:00
2016-02-04 17:57:57 +03:00
try:
2016-02-05 01:57:13 +03:00
im.resize((-100, 100))
2016-02-04 17:57:57 +03:00
self.fail("Resize should raise a value error on x negative size")
except ValueError:
self.assertTrue(True, "Should raise ValueError")
try:
2016-02-05 01:57:13 +03:00
im.resize((100, -100))
2016-02-04 17:57:57 +03:00
self.fail("Resize should raise a value error on y negative size")
except ValueError:
self.assertTrue(True, "Should raise ValueError")
2016-02-04 15:17:00 +03:00
if __name__ == '__main__':
unittest.main()