mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +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):
|
||||
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__':
|
||||
unittest.main()
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -35,6 +35,9 @@ class TestImagePoint(PillowTestCase):
|
|||
int_lut = [x//2 for x in range(256)]
|
||||
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__':
|
||||
unittest.main()
|
||||
|
|
|
@ -97,6 +97,9 @@ class TestImagingCoreResize(PillowTestCase):
|
|||
self.assertEqual(r.size, (212, 195))
|
||||
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):
|
||||
|
||||
|
|
|
@ -140,6 +140,10 @@ class TestImageTransform(PillowTestCase):
|
|||
|
||||
self.test_mesh()
|
||||
|
||||
def test_missing_method_data(self):
|
||||
self.assertRaises(ValueError, lambda:
|
||||
hopper().transform((100, 100), None))
|
||||
|
||||
|
||||
class TestImageTransformAffine(PillowTestCase):
|
||||
transform = Image.AFFINE
|
||||
|
|
Loading…
Reference in New Issue
Block a user