mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Merge pull request #2379 from radarhere/test
Add tests for several Image operations
This commit is contained in:
commit
7726296a93
|
@ -305,6 +305,16 @@ class TestImage(PillowTestCase):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
Image.core.fill('RGB', (2,-2), (0,0,0))
|
Image.core.fill('RGB', (2,-2), (0,0,0))
|
||||||
|
|
||||||
|
def test_offset_not_implemented(self):
|
||||||
|
# Arrange
|
||||||
|
im = hopper()
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
self.assertRaises(NotImplementedError, lambda: im.offset(None))
|
||||||
|
|
||||||
|
def test_fromstring(self):
|
||||||
|
self.assertRaises(NotImplementedError, Image.fromstring)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -28,6 +28,15 @@ class TestImagingPaste(PillowTestCase):
|
||||||
]
|
]
|
||||||
self.assertEqual(actual, expected)
|
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
|
@cached_property
|
||||||
def mask_1(self):
|
def mask_1(self):
|
||||||
mask = Image.new('1', (self.size, self.size))
|
mask = Image.new('1', (self.size, self.size))
|
||||||
|
@ -91,9 +100,7 @@ class TestImagingPaste(PillowTestCase):
|
||||||
im = Image.new(mode, (200, 200), 'white')
|
im = Image.new(mode, (200, 200), 'white')
|
||||||
im2 = getattr(self, 'gradient_' + mode)
|
im2 = getattr(self, 'gradient_' + mode)
|
||||||
|
|
||||||
im.paste(im2, (0, 0), self.mask_1)
|
self.assert_9points_paste(im, im2, self.mask_1, [
|
||||||
|
|
||||||
self.assert_9points_image(im, [
|
|
||||||
(255, 255, 255, 255),
|
(255, 255, 255, 255),
|
||||||
(255, 255, 255, 255),
|
(255, 255, 255, 255),
|
||||||
(127, 254, 127, 0),
|
(127, 254, 127, 0),
|
||||||
|
@ -110,9 +117,7 @@ class TestImagingPaste(PillowTestCase):
|
||||||
im = Image.new(mode, (200, 200), 'white')
|
im = Image.new(mode, (200, 200), 'white')
|
||||||
im2 = getattr(self, 'gradient_' + mode)
|
im2 = getattr(self, 'gradient_' + mode)
|
||||||
|
|
||||||
im.paste(im2, (0, 0), self.mask_L)
|
self.assert_9points_paste(im, im2, self.mask_L, [
|
||||||
|
|
||||||
self.assert_9points_image(im, [
|
|
||||||
(128, 191, 255, 191),
|
(128, 191, 255, 191),
|
||||||
(208, 239, 239, 208),
|
(208, 239, 239, 208),
|
||||||
(255, 255, 255, 255),
|
(255, 255, 255, 255),
|
||||||
|
@ -129,9 +134,7 @@ class TestImagingPaste(PillowTestCase):
|
||||||
im = Image.new(mode, (200, 200), 'white')
|
im = Image.new(mode, (200, 200), 'white')
|
||||||
im2 = getattr(self, 'gradient_' + mode)
|
im2 = getattr(self, 'gradient_' + mode)
|
||||||
|
|
||||||
im.paste(im2, (0, 0), self.gradient_RGBA)
|
self.assert_9points_paste(im, im2, self.gradient_RGBA, [
|
||||||
|
|
||||||
self.assert_9points_image(im, [
|
|
||||||
(128, 191, 255, 191),
|
(128, 191, 255, 191),
|
||||||
(208, 239, 239, 208),
|
(208, 239, 239, 208),
|
||||||
(255, 255, 255, 255),
|
(255, 255, 255, 255),
|
||||||
|
@ -148,9 +151,7 @@ class TestImagingPaste(PillowTestCase):
|
||||||
im = Image.new(mode, (200, 200), 'white')
|
im = Image.new(mode, (200, 200), 'white')
|
||||||
im2 = getattr(self, 'gradient_' + mode)
|
im2 = getattr(self, 'gradient_' + mode)
|
||||||
|
|
||||||
im.paste(im2, (0, 0), self.gradient_RGBa)
|
self.assert_9points_paste(im, im2, self.gradient_RGBa, [
|
||||||
|
|
||||||
self.assert_9points_image(im, [
|
|
||||||
(128, 255, 126, 255),
|
(128, 255, 126, 255),
|
||||||
(0, 127, 126, 255),
|
(0, 127, 126, 255),
|
||||||
(126, 253, 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)])
|
im = Image.new(mode, (200, 200), (50, 60, 70, 80)[:len(mode)])
|
||||||
color = (10, 20, 30, 40)[:len(mode)]
|
color = (10, 20, 30, 40)[:len(mode)]
|
||||||
|
|
||||||
im.paste(color, (0, 0), self.mask_1)
|
self.assert_9points_paste(im, color, self.mask_1, [
|
||||||
|
|
||||||
self.assert_9points_image(im, [
|
|
||||||
(50, 60, 70, 80),
|
(50, 60, 70, 80),
|
||||||
(50, 60, 70, 80),
|
(50, 60, 70, 80),
|
||||||
(10, 20, 30, 40),
|
(10, 20, 30, 40),
|
||||||
|
@ -199,9 +198,7 @@ class TestImagingPaste(PillowTestCase):
|
||||||
im = getattr(self, 'gradient_' + mode).copy()
|
im = getattr(self, 'gradient_' + mode).copy()
|
||||||
color = 'white'
|
color = 'white'
|
||||||
|
|
||||||
im.paste(color, (0, 0), self.mask_L)
|
self.assert_9points_paste(im, color, self.mask_L, [
|
||||||
|
|
||||||
self.assert_9points_image(im, [
|
|
||||||
(127, 191, 254, 191),
|
(127, 191, 254, 191),
|
||||||
(111, 207, 206, 110),
|
(111, 207, 206, 110),
|
||||||
(127, 254, 127, 0),
|
(127, 254, 127, 0),
|
||||||
|
@ -218,9 +215,7 @@ class TestImagingPaste(PillowTestCase):
|
||||||
im = getattr(self, 'gradient_' + mode).copy()
|
im = getattr(self, 'gradient_' + mode).copy()
|
||||||
color = 'white'
|
color = 'white'
|
||||||
|
|
||||||
im.paste(color, (0, 0), self.gradient_RGBA)
|
self.assert_9points_paste(im, color, self.gradient_RGBA, [
|
||||||
|
|
||||||
self.assert_9points_image(im, [
|
|
||||||
(127, 191, 254, 191),
|
(127, 191, 254, 191),
|
||||||
(111, 207, 206, 110),
|
(111, 207, 206, 110),
|
||||||
(127, 254, 127, 0),
|
(127, 254, 127, 0),
|
||||||
|
@ -237,9 +232,7 @@ class TestImagingPaste(PillowTestCase):
|
||||||
im = getattr(self, 'gradient_' + mode).copy()
|
im = getattr(self, 'gradient_' + mode).copy()
|
||||||
color = 'white'
|
color = 'white'
|
||||||
|
|
||||||
im.paste(color, (0, 0), self.gradient_RGBa)
|
self.assert_9points_paste(im, color, self.gradient_RGBa, [
|
||||||
|
|
||||||
self.assert_9points_image(im, [
|
|
||||||
(255, 63, 126, 63),
|
(255, 63, 126, 63),
|
||||||
(47, 143, 142, 46),
|
(47, 143, 142, 46),
|
||||||
(126, 253, 126, 255),
|
(126, 253, 126, 255),
|
||||||
|
|
|
@ -35,6 +35,9 @@ class TestImagePoint(PillowTestCase):
|
||||||
int_lut = [x//2 for x in range(256)]
|
int_lut = [x//2 for x in range(256)]
|
||||||
self.assert_image_equal(out.convert('L'), im.point(int_lut, 'L'))
|
self.assert_image_equal(out.convert('L'), im.point(int_lut, 'L'))
|
||||||
|
|
||||||
|
def test_f_mode(self):
|
||||||
|
self.assertRaises(ValueError, lambda: hopper('F').point(None))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -97,6 +97,9 @@ class TestImagingCoreResize(PillowTestCase):
|
||||||
self.assertEqual(r.size, (212, 195))
|
self.assertEqual(r.size, (212, 195))
|
||||||
self.assertEqual(r.getdata()[0], (0,0,0))
|
self.assertEqual(r.getdata()[0], (0,0,0))
|
||||||
|
|
||||||
|
def test_unknown_filter(self):
|
||||||
|
self.assertRaises(ValueError, self.resize, hopper(), (10, 10), 9)
|
||||||
|
|
||||||
|
|
||||||
class TestImageResize(PillowTestCase):
|
class TestImageResize(PillowTestCase):
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,10 @@ class TestImageTransform(PillowTestCase):
|
||||||
|
|
||||||
self.test_mesh()
|
self.test_mesh()
|
||||||
|
|
||||||
|
def test_missing_method_data(self):
|
||||||
|
self.assertRaises(ValueError, lambda:
|
||||||
|
hopper().transform((100, 100), None))
|
||||||
|
|
||||||
|
|
||||||
class TestImageTransformAffine(PillowTestCase):
|
class TestImageTransformAffine(PillowTestCase):
|
||||||
transform = Image.AFFINE
|
transform = Image.AFFINE
|
||||||
|
|
Loading…
Reference in New Issue
Block a user