2019-02-03 18:34:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2016-12-27 15:53:23 +03:00
|
|
|
from PIL import Image
|
|
|
|
|
2016-03-16 12:23:51 +03:00
|
|
|
import copy
|
|
|
|
|
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
|
2014-09-05 14:03:56 +04:00
|
|
|
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
|
|
|
|
2016-12-27 15:53:23 +03:00
|
|
|
def test_copy_zero(self):
|
2019-06-13 18:54:24 +03:00
|
|
|
im = Image.new("RGB", (0, 0))
|
2016-12-27 15:53:23 +03:00
|
|
|
out = im.copy()
|
|
|
|
self.assertEqual(out.mode, im.mode)
|
|
|
|
self.assertEqual(out.size, im.size)
|