From 123fe38ef73e5dc7485e14d1d35a47e93fa680b0 Mon Sep 17 00:00:00 2001 From: hugovk Date: Tue, 15 Jul 2014 00:42:31 +0300 Subject: [PATCH] Test Image's __ne__ and alpha_composite --- Tests/test_image.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Tests/test_image.py b/Tests/test_image.py index c1c2c3d86..85b0bba0e 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -102,6 +102,44 @@ class TestImage(PillowTestCase): # Assert self.assertEqual(bbox, (0, 0, 128, 128)) + def test_ne(self): + # Arrange + im1 = Image.new('RGB', (25, 25), 'black') + im2 = Image.new('RGB', (25, 25), 'white') + + # Act / Assert + self.assertTrue(im1 != im2) + + def test_alpha_composite(self): + # http://stackoverflow.com/questions/3374878 + # Arrange + import ImageDraw + + expected_colors = sorted([ + (1122, (128, 127, 0, 255)), + (1089, (0, 255, 0, 255)), + (3300, (255, 0, 0, 255)), + (1156, (170, 85, 0, 192)), + (1122, (0, 255, 0, 128)), + (1122, (255, 0, 0, 128)), + (1089, (0, 255, 0, 0))]) + + dst = Image.new('RGBA', size=(100, 100), color=(0, 255, 0, 255)) + draw = ImageDraw.Draw(dst) + draw.rectangle((0, 33, 100, 66), fill=(0, 255, 0, 128)) + draw.rectangle((0, 67, 100, 100), fill=(0, 255, 0, 0)) + src = Image.new('RGBA', size=(100, 100), color=(255, 0, 0, 255)) + draw = ImageDraw.Draw(src) + draw.rectangle((33, 0, 66, 100), fill=(255, 0, 0, 128)) + draw.rectangle((67, 0, 100, 100), fill=(255, 0, 0, 0)) + + # Act + img = Image.alpha_composite(dst, src) + + # Assert + img_colors = sorted(img.getcolors()) + self.assertEqual(img_colors, expected_colors) + if __name__ == '__main__': unittest.main()