2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
import copy
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2022-08-23 14:41:32 +03:00
|
|
|
import pytest
|
|
|
|
|
2016-12-27 15:53:23 +03:00
|
|
|
from PIL import Image
|
|
|
|
|
2023-04-22 04:18:56 +03:00
|
|
|
from .helper import hopper, skip_unless_feature
|
2020-01-27 14:46:52 +03:00
|
|
|
|
|
|
|
|
2022-08-23 14:41:32 +03:00
|
|
|
@pytest.mark.parametrize("mode", ("1", "P", "L", "RGB", "I", "F"))
|
2024-01-25 14:18:46 +03:00
|
|
|
def test_copy(mode: str) -> None:
|
2022-04-10 21:23:31 +03:00
|
|
|
cropped_coordinates = (10, 10, 20, 20)
|
|
|
|
cropped_size = (10, 10)
|
2022-08-23 14:41:32 +03:00
|
|
|
|
|
|
|
# Internal copy method
|
|
|
|
im = hopper(mode)
|
|
|
|
out = im.copy()
|
|
|
|
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)
|
|
|
|
out = im.crop(cropped_coordinates).copy()
|
|
|
|
assert out.mode == im.mode
|
|
|
|
assert out.size == cropped_size
|
|
|
|
|
|
|
|
# Python's copy method on a cropped image
|
|
|
|
im = hopper(mode)
|
|
|
|
out = copy.copy(im.crop(cropped_coordinates))
|
|
|
|
assert out.mode == im.mode
|
|
|
|
assert out.size == cropped_size
|
2020-01-27 14:46:52 +03:00
|
|
|
|
|
|
|
|
2024-01-25 14:18:46 +03:00
|
|
|
def test_copy_zero() -> None:
|
2020-01-27 14:46:52 +03:00
|
|
|
im = Image.new("RGB", (0, 0))
|
|
|
|
out = im.copy()
|
|
|
|
assert out.mode == im.mode
|
|
|
|
assert out.size == im.size
|
2023-04-22 04:18:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
@skip_unless_feature("libtiff")
|
2024-01-25 14:18:46 +03:00
|
|
|
def test_deepcopy() -> None:
|
2023-04-22 04:18:56 +03:00
|
|
|
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
2024-09-18 13:26:06 +03:00
|
|
|
assert im.size == (590, 88)
|
|
|
|
|
2023-04-22 04:18:56 +03:00
|
|
|
out = copy.deepcopy(im)
|
|
|
|
assert out.size == (590, 88)
|