Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added __copy__ method to Image #1772

Merged
merged 1 commit into from Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions PIL/Image.py
Expand Up @@ -1012,6 +1012,8 @@ def copy(self):
im = self.im.copy()
return self._new(im)

__copy__ = copy

def crop(self, box=None):
"""
Returns a rectangular region from this image. The box is a
Expand Down
29 changes: 25 additions & 4 deletions Tests/test_image_copy.py
@@ -1,16 +1,37 @@
from helper import unittest, PillowTestCase, hopper

import copy


class TestImageCopy(PillowTestCase):

def test_copy(self):
def copy(mode):
croppedCoordinates = (10, 10, 20, 20)
croppedSize = (10, 10)
for mode in "1", "P", "L", "RGB", "I", "F":
# Internal copy method
im = hopper(mode)
out = im.copy()
self.assertEqual(out.mode, mode)
self.assertEqual(out.mode, im.mode)
self.assertEqual(out.size, im.size)
for mode in "1", "P", "L", "RGB", "I", "F":
copy(mode)

# 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)

if __name__ == '__main__':
unittest.main()
Expand Down