mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-04 11:53:32 +03:00
Added test for crop operation with no argument
This commit is contained in:
parent
296fb5fe1d
commit
c5265e2100
|
@ -7,9 +7,12 @@ class TestImageCrop(PillowTestCase):
|
||||||
|
|
||||||
def test_crop(self):
|
def test_crop(self):
|
||||||
def crop(mode):
|
def crop(mode):
|
||||||
out = hopper(mode).crop((50, 50, 100, 100))
|
im = hopper(mode)
|
||||||
self.assertEqual(out.mode, mode)
|
self.assert_image_equal(im.crop(), im)
|
||||||
self.assertEqual(out.size, (50, 50))
|
|
||||||
|
cropped = im.crop((50, 50, 100, 100))
|
||||||
|
self.assertEqual(cropped.mode, mode)
|
||||||
|
self.assertEqual(cropped.size, (50, 50))
|
||||||
for mode in "1", "P", "L", "RGB", "I", "F":
|
for mode in "1", "P", "L", "RGB", "I", "F":
|
||||||
crop(mode)
|
crop(mode)
|
||||||
|
|
||||||
|
@ -70,23 +73,23 @@ class TestImageCrop(PillowTestCase):
|
||||||
#Image.crop crashes prepatch with an access violation
|
#Image.crop crashes prepatch with an access violation
|
||||||
#apparently a use after free on windows, see
|
#apparently a use after free on windows, see
|
||||||
#https://github.com/python-pillow/Pillow/issues/1077
|
#https://github.com/python-pillow/Pillow/issues/1077
|
||||||
|
|
||||||
test_img = 'Tests/images/bmp/g/pal8-0.bmp'
|
test_img = 'Tests/images/bmp/g/pal8-0.bmp'
|
||||||
extents = (1,1,10,10)
|
extents = (1,1,10,10)
|
||||||
#works prepatch
|
#works prepatch
|
||||||
img = Image.open(test_img)
|
img = Image.open(test_img)
|
||||||
img2 = img.crop(extents)
|
img2 = img.crop(extents)
|
||||||
img2.load()
|
img2.load()
|
||||||
|
|
||||||
# fail prepatch
|
# fail prepatch
|
||||||
img = Image.open(test_img)
|
img = Image.open(test_img)
|
||||||
img = img.crop(extents)
|
img = img.crop(extents)
|
||||||
img.load()
|
img.load()
|
||||||
|
|
||||||
def test_crop_zero(self):
|
def test_crop_zero(self):
|
||||||
|
|
||||||
im = Image.new('RGB', (0, 0), 'white')
|
im = Image.new('RGB', (0, 0), 'white')
|
||||||
|
|
||||||
cropped = im.crop((0, 0, 0, 0))
|
cropped = im.crop((0, 0, 0, 0))
|
||||||
self.assertEqual(cropped.size, (0, 0))
|
self.assertEqual(cropped.size, (0, 0))
|
||||||
|
|
||||||
|
@ -95,7 +98,7 @@ class TestImageCrop(PillowTestCase):
|
||||||
self.assertEqual(cropped.getdata()[0], (0, 0, 0))
|
self.assertEqual(cropped.getdata()[0], (0, 0, 0))
|
||||||
|
|
||||||
im = Image.new('RGB', (0, 0))
|
im = Image.new('RGB', (0, 0))
|
||||||
|
|
||||||
cropped = im.crop((10, 10, 20, 20))
|
cropped = im.crop((10, 10, 20, 20))
|
||||||
self.assertEqual(cropped.size, (10, 10))
|
self.assertEqual(cropped.size, (10, 10))
|
||||||
self.assertEqual(cropped.getdata()[2], (0, 0, 0))
|
self.assertEqual(cropped.getdata()[2], (0, 0, 0))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user