2014-09-05 14:03:56 +04:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
2015-08-05 17:23:14 +03:00
|
|
|
from PIL import Image
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
|
|
|
|
class TestImageRotate(PillowTestCase):
|
|
|
|
|
|
|
|
def test_rotate(self):
|
2015-08-05 17:23:14 +03:00
|
|
|
def rotate(im, mode, angle):
|
|
|
|
out = im.rotate(angle)
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(out.mode, mode)
|
|
|
|
self.assertEqual(out.size, im.size) # default rotate clips output
|
2015-08-05 17:23:14 +03:00
|
|
|
out = im.rotate(angle, expand=1)
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(out.mode, mode)
|
2016-08-05 19:20:02 +03:00
|
|
|
if angle % 180 == 0:
|
|
|
|
self.assertEqual(out.size, im.size)
|
2016-12-31 16:31:51 +03:00
|
|
|
elif im.size == (0, 0):
|
|
|
|
self.assertEqual(out.size, im.size)
|
2016-08-05 19:20:02 +03:00
|
|
|
else:
|
|
|
|
self.assertNotEqual(out.size, im.size)
|
2016-12-31 16:31:51 +03:00
|
|
|
|
2016-12-31 16:08:00 +03:00
|
|
|
|
|
|
|
for mode in ("1", "P", "L", "RGB", "I", "F"):
|
2015-08-05 17:23:14 +03:00
|
|
|
im = hopper(mode)
|
|
|
|
rotate(im, mode, 45)
|
2016-12-31 16:08:00 +03:00
|
|
|
|
|
|
|
for angle in (0, 90, 180, 270):
|
2015-08-05 17:23:14 +03:00
|
|
|
im = Image.open('Tests/images/test-card.png')
|
|
|
|
rotate(im, im.mode, angle)
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2016-12-31 16:08:00 +03:00
|
|
|
for angle in (0, 45, 90, 180, 270):
|
|
|
|
im = Image.new('RGB',(0,0))
|
|
|
|
rotate(im, im.mode, angle)
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|