mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
use not square image for test, fix tests
This commit is contained in:
parent
4cf2f158b6
commit
9e5ee5a5bf
|
@ -6,9 +6,14 @@ from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180,
|
|||
|
||||
class TestImageTranspose(PillowTestCase):
|
||||
|
||||
hopper = {
|
||||
'L': hopper('L').crop((0, 0, 121, 127)).copy(),
|
||||
'RGB': hopper('RGB').crop((0, 0, 121, 127)).copy(),
|
||||
}
|
||||
|
||||
def test_flip_left_right(self):
|
||||
def transpose(mode):
|
||||
im = hopper(mode)
|
||||
im = self.hopper[mode]
|
||||
out = im.transpose(FLIP_LEFT_RIGHT)
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertEqual(out.size, im.size)
|
||||
|
@ -24,7 +29,7 @@ class TestImageTranspose(PillowTestCase):
|
|||
|
||||
def test_flip_top_bottom(self):
|
||||
def transpose(mode):
|
||||
im = hopper(mode)
|
||||
im = self.hopper[mode]
|
||||
out = im.transpose(FLIP_TOP_BOTTOM)
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertEqual(out.size, im.size)
|
||||
|
@ -40,23 +45,23 @@ class TestImageTranspose(PillowTestCase):
|
|||
|
||||
def test_rotate_90(self):
|
||||
def transpose(mode):
|
||||
im = hopper(mode)
|
||||
im = self.hopper[mode]
|
||||
out = im.transpose(ROTATE_90)
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertEqual(out.size, im.size[::-1])
|
||||
|
||||
x, y = im.size
|
||||
self.assertEqual(im.getpixel((1, 1)), out.getpixel((1, y-2)))
|
||||
self.assertEqual(im.getpixel((1, 1)), out.getpixel((1, x-2)))
|
||||
self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((1, 1)))
|
||||
self.assertEqual(im.getpixel((1, y-2)), out.getpixel((x-2, y-2)))
|
||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((x-2, 1)))
|
||||
self.assertEqual(im.getpixel((1, y-2)), out.getpixel((y-2, x-2)))
|
||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((y-2, 1)))
|
||||
|
||||
for mode in ("L", "RGB"):
|
||||
transpose(mode)
|
||||
|
||||
def test_rotate_180(self):
|
||||
def transpose(mode):
|
||||
im = hopper(mode)
|
||||
im = self.hopper[mode]
|
||||
out = im.transpose(ROTATE_180)
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertEqual(out.size, im.size)
|
||||
|
@ -72,38 +77,38 @@ class TestImageTranspose(PillowTestCase):
|
|||
|
||||
def test_rotate_270(self):
|
||||
def transpose(mode):
|
||||
im = hopper(mode)
|
||||
im = self.hopper[mode]
|
||||
out = im.transpose(ROTATE_270)
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertEqual(out.size, im.size[::-1])
|
||||
|
||||
x, y = im.size
|
||||
self.assertEqual(im.getpixel((1, 1)), out.getpixel((x-2, 1)))
|
||||
self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((x-2, y-2)))
|
||||
self.assertEqual(im.getpixel((1, 1)), out.getpixel((y-2, 1)))
|
||||
self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((y-2, x-2)))
|
||||
self.assertEqual(im.getpixel((1, y-2)), out.getpixel((1, 1)))
|
||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, y-2)))
|
||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, x-2)))
|
||||
|
||||
for mode in ("L", "RGB"):
|
||||
transpose(mode)
|
||||
|
||||
def test_transpose(self):
|
||||
def transpose(mode):
|
||||
im = hopper(mode)
|
||||
im = self.hopper[mode]
|
||||
out = im.transpose(TRANSPOSE)
|
||||
self.assertEqual(out.mode, mode)
|
||||
self.assertEqual(out.size, im.size[::-1])
|
||||
|
||||
x, y = im.size
|
||||
self.assertEqual(im.getpixel((1, 1)), out.getpixel((1, 1)))
|
||||
self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((1, y-2)))
|
||||
self.assertEqual(im.getpixel((1, y-2)), out.getpixel((x-2, 1)))
|
||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((x-2, y-2)))
|
||||
self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((1, x-2)))
|
||||
self.assertEqual(im.getpixel((1, y-2)), out.getpixel((y-2, 1)))
|
||||
self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((y-2, x-2)))
|
||||
|
||||
for mode in ("L", "RGB"):
|
||||
transpose(mode)
|
||||
|
||||
def test_roundtrip(self):
|
||||
im = hopper()
|
||||
im = self.hopper['L']
|
||||
|
||||
def transpose(first, second):
|
||||
return im.transpose(first).transpose(second)
|
||||
|
|
Loading…
Reference in New Issue
Block a user