MCPcopy
hub / github.com/python-pillow/Pillow / test_basic

Function test_basic

Tests/test_mode_i16.py:32–79  ·  view source on GitHub ↗
(tmp_path: Path, mode: str)

Source from the content-addressed store, hash-verified

30
31@pytest.mark.parametrize("mode", ("L", "I;16", "I;16B", "I;16L", "I"))
32def test_basic(tmp_path: Path, mode: str) -> None:
33 # PIL 1.1 has limited support for 16-bit image data. Check that
34 # create/copy/transform and save works as expected.
35
36 im_in = original.convert(mode)
37 verify(im_in)
38
39 w, h = im_in.size
40
41 im_out = im_in.copy()
42 verify(im_out) # copy
43
44 im_out = im_in.transform((w, h), Image.Transform.EXTENT, (0, 0, w, h))
45 verify(im_out) # transform
46
47 filename = tmp_path / "temp.im"
48 im_in.save(filename)
49
50 with Image.open(filename) as im_out:
51 verify(im_in)
52 verify(im_out)
53
54 im_out = im_in.crop((0, 0, w, h))
55 verify(im_out)
56
57 im_out = Image.new(mode, (w, h), None)
58 im_out.paste(im_in.crop((0, 0, w // 2, h)), (0, 0))
59 im_out.paste(im_in.crop((w // 2, 0, w, h)), (w // 2, 0))
60
61 verify(im_in)
62 verify(im_out)
63
64 im_in = Image.new(mode, (1, 1), 1)
65 assert im_in.getpixel((0, 0)) == 1
66
67 im_in.putpixel((0, 0), 2)
68 assert im_in.getpixel((0, 0)) == 2
69
70 if mode == "L":
71 maximum = 255
72 else:
73 maximum = 32767
74
75 im_in = Image.new(mode, (1, 1), 256)
76 assert im_in.getpixel((0, 0)) == min(256, maximum)
77
78 im_in.putpixel((0, 0), 512)
79 assert im_in.getpixel((0, 0)) == min(512, maximum)
80
81
82def test_tobytes() -> None:

Callers

nothing calls this directly

Calls 11

verifyFunction · 0.85
convertMethod · 0.80
cropMethod · 0.80
newMethod · 0.80
getpixelMethod · 0.80
putpixelMethod · 0.80
copyMethod · 0.45
transformMethod · 0.45
saveMethod · 0.45
openMethod · 0.45
pasteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…