2019-07-06 23:40:53 +03:00
|
|
|
import copy
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2016-12-27 15:53:23 +03:00
|
|
|
from PIL import Image
|
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
from .helper import hopper
|
|
|
|
|
|
|
|
|
|
|
|
def test_copy():
|
2022-04-10 21:23:31 +03:00
|
|
|
cropped_coordinates = (10, 10, 20, 20)
|
|
|
|
cropped_size = (10, 10)
|
2020-01-27 14:46:52 +03:00
|
|
|
for mode in "1", "P", "L", "RGB", "I", "F":
|
|
|
|
# Internal copy method
|
|
|
|
im = hopper(mode)
|
2016-12-27 15:53:23 +03:00
|
|
|
out = im.copy()
|
2020-01-27 14:46:52 +03:00
|
|
|
assert out.mode == im.mode
|
|
|
|
assert out.size == im.size
|
|
|
|
|
|
|
|
# Python's copy method
|
|
|
|
im = hopper(mode)
|
|
|
|
out = copy.copy(im)
|
|
|
|
assert out.mode == im.mode
|
|
|
|
assert out.size == im.size
|
|
|
|
|
|
|
|
# Internal copy method on a cropped image
|
|
|
|
im = hopper(mode)
|
2022-04-10 21:23:31 +03:00
|
|
|
out = im.crop(cropped_coordinates).copy()
|
2020-01-27 14:46:52 +03:00
|
|
|
assert out.mode == im.mode
|
2022-04-10 21:23:31 +03:00
|
|
|
assert out.size == cropped_size
|
2020-01-27 14:46:52 +03:00
|
|
|
|
|
|
|
# Python's copy method on a cropped image
|
|
|
|
im = hopper(mode)
|
2022-04-10 21:23:31 +03:00
|
|
|
out = copy.copy(im.crop(cropped_coordinates))
|
2020-01-27 14:46:52 +03:00
|
|
|
assert out.mode == im.mode
|
2022-04-10 21:23:31 +03:00
|
|
|
assert out.size == cropped_size
|
2020-01-27 14:46:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_copy_zero():
|
|
|
|
im = Image.new("RGB", (0, 0))
|
|
|
|
out = im.copy()
|
|
|
|
assert out.mode == im.mode
|
|
|
|
assert out.size == im.size
|