File: test_image_copy.py

package info (click to toggle)
pillow 8.1.2%2Bdfsg-0.3%2Bdeb11u2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 65,628 kB
  • sloc: python: 35,630; ansic: 31,009; makefile: 388; javascript: 114; sh: 77
file content (41 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import copy

from PIL import Image

from .helper import hopper


def test_copy():
    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()
        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(croppedCoordinates).copy()
        assert out.mode == im.mode
        assert out.size == croppedSize

        # Python's copy method on a cropped image
        im = hopper(mode)
        out = copy.copy(im.crop(croppedCoordinates))
        assert out.mode == im.mode
        assert out.size == croppedSize


def test_copy_zero():
    im = Image.new("RGB", (0, 0))
    out = im.copy()
    assert out.mode == im.mode
    assert out.size == im.size