From b6b3b004d8e2132b628635586260a9b275dc2864 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 11 Sep 2017 23:00:35 +0300 Subject: [PATCH] tests for transverse, add to docs --- PIL/Image.py | 4 ++-- Tests/test_image_transpose.py | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 455b9860e..8d4a99bbf 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -2171,8 +2171,8 @@ class Image(object): :param method: One of :py:attr:`PIL.Image.FLIP_LEFT_RIGHT`, :py:attr:`PIL.Image.FLIP_TOP_BOTTOM`, :py:attr:`PIL.Image.ROTATE_90`, - :py:attr:`PIL.Image.ROTATE_180`, :py:attr:`PIL.Image.ROTATE_270` or - :py:attr:`PIL.Image.TRANSPOSE`. + :py:attr:`PIL.Image.ROTATE_180`, :py:attr:`PIL.Image.ROTATE_270`, + :py:attr:`PIL.Image.TRANSPOSE` or :py:attr:`PIL.Image.TRANSVERSE`. :returns: Returns a flipped or rotated copy of this image. """ diff --git a/Tests/test_image_transpose.py b/Tests/test_image_transpose.py index e13fc8605..a6b1191db 100644 --- a/Tests/test_image_transpose.py +++ b/Tests/test_image_transpose.py @@ -2,7 +2,7 @@ import helper from helper import unittest, PillowTestCase from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180, - ROTATE_270, TRANSPOSE) + ROTATE_270, TRANSPOSE, TRANSVERSE) class TestImageTranspose(PillowTestCase): @@ -108,6 +108,22 @@ class TestImageTranspose(PillowTestCase): for mode in ("L", "RGB"): transpose(mode) + def test_tranverse(self): + def transpose(mode): + im = self.hopper[mode] + out = im.transpose(TRANSVERSE) + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, im.size[::-1]) + + x, y = im.size + self.assertEqual(im.getpixel((1, 1)), out.getpixel((y-2, x-2))) + self.assertEqual(im.getpixel((x-2, 1)), out.getpixel((y-2, 1))) + self.assertEqual(im.getpixel((1, y-2)), out.getpixel((1, x-2))) + self.assertEqual(im.getpixel((x-2, y-2)), out.getpixel((1, 1))) + + for mode in ("L", "RGB"): + transpose(mode) + def test_roundtrip(self): im = self.hopper['L'] @@ -124,6 +140,12 @@ class TestImageTranspose(PillowTestCase): im.transpose(TRANSPOSE), transpose(ROTATE_90, FLIP_TOP_BOTTOM)) self.assert_image_equal( im.transpose(TRANSPOSE), transpose(ROTATE_270, FLIP_LEFT_RIGHT)) + self.assert_image_equal( + im.transpose(TRANSVERSE), transpose(ROTATE_90, FLIP_LEFT_RIGHT)) + self.assert_image_equal( + im.transpose(TRANSVERSE), transpose(ROTATE_270, FLIP_TOP_BOTTOM)) + self.assert_image_equal( + im.transpose(TRANSVERSE), transpose(ROTATE_180, TRANSPOSE)) if __name__ == '__main__':