Added test for abbreviated Image paste mask syntax

This commit is contained in:
Andrew Murray 2017-01-28 13:50:44 +11:00
parent 581fef2ebd
commit e8495e5917

View File

@ -28,6 +28,15 @@ class TestImagingPaste(PillowTestCase):
]
self.assertEqual(actual, expected)
def assert_9points_paste(self, im, im2, mask, expected):
im3 = im.copy()
im3.paste(im2, (0, 0), mask)
self.assert_9points_image(im3, expected)
# Abbreviated syntax
im.paste(im2, mask)
self.assert_9points_image(im, expected)
@cached_property
def mask_1(self):
mask = Image.new('1', (self.size, self.size))
@ -91,9 +100,7 @@ class TestImagingPaste(PillowTestCase):
im = Image.new(mode, (200, 200), 'white')
im2 = getattr(self, 'gradient_' + mode)
im.paste(im2, (0, 0), self.mask_1)
self.assert_9points_image(im, [
self.assert_9points_paste(im, im2, self.mask_1, [
(255, 255, 255, 255),
(255, 255, 255, 255),
(127, 254, 127, 0),
@ -110,9 +117,7 @@ class TestImagingPaste(PillowTestCase):
im = Image.new(mode, (200, 200), 'white')
im2 = getattr(self, 'gradient_' + mode)
im.paste(im2, (0, 0), self.mask_L)
self.assert_9points_image(im, [
self.assert_9points_paste(im, im2, self.mask_L, [
(128, 191, 255, 191),
(208, 239, 239, 208),
(255, 255, 255, 255),
@ -129,9 +134,7 @@ class TestImagingPaste(PillowTestCase):
im = Image.new(mode, (200, 200), 'white')
im2 = getattr(self, 'gradient_' + mode)
im.paste(im2, (0, 0), self.gradient_RGBA)
self.assert_9points_image(im, [
self.assert_9points_paste(im, im2, self.gradient_RGBA, [
(128, 191, 255, 191),
(208, 239, 239, 208),
(255, 255, 255, 255),
@ -148,9 +151,7 @@ class TestImagingPaste(PillowTestCase):
im = Image.new(mode, (200, 200), 'white')
im2 = getattr(self, 'gradient_' + mode)
im.paste(im2, (0, 0), self.gradient_RGBa)
self.assert_9points_image(im, [
self.assert_9points_paste(im, im2, self.gradient_RGBa, [
(128, 255, 126, 255),
(0, 127, 126, 255),
(126, 253, 126, 255),
@ -180,9 +181,7 @@ class TestImagingPaste(PillowTestCase):
im = Image.new(mode, (200, 200), (50, 60, 70, 80)[:len(mode)])
color = (10, 20, 30, 40)[:len(mode)]
im.paste(color, (0, 0), self.mask_1)
self.assert_9points_image(im, [
self.assert_9points_paste(im, color, self.mask_1, [
(50, 60, 70, 80),
(50, 60, 70, 80),
(10, 20, 30, 40),
@ -199,9 +198,7 @@ class TestImagingPaste(PillowTestCase):
im = getattr(self, 'gradient_' + mode).copy()
color = 'white'
im.paste(color, (0, 0), self.mask_L)
self.assert_9points_image(im, [
self.assert_9points_paste(im, color, self.mask_L, [
(127, 191, 254, 191),
(111, 207, 206, 110),
(127, 254, 127, 0),
@ -218,9 +215,7 @@ class TestImagingPaste(PillowTestCase):
im = getattr(self, 'gradient_' + mode).copy()
color = 'white'
im.paste(color, (0, 0), self.gradient_RGBA)
self.assert_9points_image(im, [
self.assert_9points_paste(im, color, self.gradient_RGBA, [
(127, 191, 254, 191),
(111, 207, 206, 110),
(127, 254, 127, 0),
@ -237,9 +232,7 @@ class TestImagingPaste(PillowTestCase):
im = getattr(self, 'gradient_' + mode).copy()
color = 'white'
im.paste(color, (0, 0), self.gradient_RGBa)
self.assert_9points_image(im, [
self.assert_9points_paste(im, color, self.gradient_RGBa, [
(255, 63, 126, 63),
(47, 143, 142, 46),
(126, 253, 126, 255),