Pillow/Tests/test_image_copy.py

42 lines
1.3 KiB
Python
Raw Normal View History

import copy
from PIL import Image
from .helper import PillowTestCase, hopper
2016-03-16 12:23:51 +03:00
2014-06-10 13:10:47 +04:00
class TestImageCopy(PillowTestCase):
def test_copy(self):
2016-03-16 12:23:51 +03:00
croppedCoordinates = (10, 10, 20, 20)
croppedSize = (10, 10)
for mode in "1", "P", "L", "RGB", "I", "F":
# Internal copy method
im = hopper(mode)
2014-06-10 13:10:47 +04:00
out = im.copy()
2016-03-16 12:23:51 +03:00
self.assertEqual(out.mode, im.mode)
2014-06-10 13:10:47 +04:00
self.assertEqual(out.size, im.size)
2016-03-16 12:23:51 +03:00
# Python's copy method
im = hopper(mode)
out = copy.copy(im)
self.assertEqual(out.mode, im.mode)
self.assertEqual(out.size, im.size)
# Internal copy method on a cropped image
im = hopper(mode)
out = im.crop(croppedCoordinates).copy()
self.assertEqual(out.mode, im.mode)
self.assertEqual(out.size, croppedSize)
# Python's copy method on a cropped image
im = hopper(mode)
out = copy.copy(im.crop(croppedCoordinates))
self.assertEqual(out.mode, im.mode)
self.assertEqual(out.size, croppedSize)
2014-06-10 13:10:47 +04:00
def test_copy_zero(self):
2019-06-13 18:54:24 +03:00
im = Image.new("RGB", (0, 0))
out = im.copy()
self.assertEqual(out.mode, im.mode)
self.assertEqual(out.size, im.size)