From 9c3bd46b365f534dfb51787361e2a33d5c284c13 Mon Sep 17 00:00:00 2001 From: homm Date: Thu, 30 Jun 2016 16:59:04 +0300 Subject: [PATCH] improve test: compare all pixels, do not take color into account --- Tests/test_image_convert.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Tests/test_image_convert.py b/Tests/test_image_convert.py index 900be8babba..6b15c4a9db9 100644 --- a/Tests/test_image_convert.py +++ b/Tests/test_image_convert.py @@ -123,25 +123,14 @@ def test_trns_RGB(self): self.assertNotIn('transparency', p.info) p.save(f) - # ref https://github.com/python-pillow/Pillow/issues/1979 - def test_p_la(self): - def L(rgb): - return int((rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000) - - def convert_to_gray(im, pixel): - if im.mode == 'P': - color_id = im.getpixel(pixel) - color = im.getpalette()[color_id * 3:(color_id+1)*3] - return L(color) - elif im.mode == 'LA': - color = im.getpixel(pixel) - return color[0] - - im_p = hopper('P') - im_la = im_p.convert('LA') - self.assertEqual(convert_to_gray(im_p, (5, 5)), - convert_to_gray(im_la, (5, 5))) + im = hopper('RGBA') + alpha = hopper('L') + im.putalpha(alpha) + + comparable = im.convert('P').convert('LA').split()[1] + + self.assert_image_similar(alpha, comparable, 5) if __name__ == '__main__':