mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-03 03:13:04 +03:00
Merge branch 'main' into bump-pre-commit
This commit is contained in:
commit
092e37a56c
|
@ -254,7 +254,9 @@ class TestFileAvif:
|
|||
assert_image(im, "RGBA", (64, 64))
|
||||
|
||||
# image has 876 transparent pixels
|
||||
assert im.getchannel("A").getcolors()[0] == (876, 0)
|
||||
colors = im.getchannel("A").getcolors()
|
||||
assert colors is not None
|
||||
assert colors[0] == (876, 0)
|
||||
|
||||
def test_save_transparent(self, tmp_path: Path) -> None:
|
||||
im = Image.new("RGBA", (10, 10), (0, 0, 0, 0))
|
||||
|
|
|
@ -540,7 +540,9 @@ def test_dispose_background_transparency() -> None:
|
|||
img.seek(2)
|
||||
px = img.load()
|
||||
assert px is not None
|
||||
assert px[35, 30][3] == 0
|
||||
value = px[35, 30]
|
||||
assert isinstance(value, tuple)
|
||||
assert value[3] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -1424,7 +1426,9 @@ def test_getdata(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
def test_lzw_bits() -> None:
|
||||
# see https://github.com/python-pillow/Pillow/issues/2811
|
||||
with Image.open("Tests/images/issue_2811.gif") as im:
|
||||
assert im.tile[0][3][0] == 11 # LZW bits
|
||||
args = im.tile[0][3]
|
||||
assert isinstance(args, tuple)
|
||||
assert args[0] == 11 # LZW bits
|
||||
# codec error prepatch
|
||||
im.load()
|
||||
|
||||
|
@ -1479,7 +1483,11 @@ def test_saving_rgba(tmp_path: Path) -> None:
|
|||
|
||||
with Image.open(out) as reloaded:
|
||||
reloaded_rgba = reloaded.convert("RGBA")
|
||||
assert reloaded_rgba.load()[0, 0][3] == 0
|
||||
px = reloaded_rgba.load()
|
||||
assert px is not None
|
||||
value = px[0, 0]
|
||||
assert isinstance(value, tuple)
|
||||
assert value[3] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("params", ({}, {"disposal": 2, "optimize": False}))
|
||||
|
|
|
@ -130,21 +130,7 @@ class TestFileJpeg:
|
|||
def test_cmyk(self) -> None:
|
||||
# Test CMYK handling. Thanks to Tim and Charlie for test data,
|
||||
# Michael for getting me to look one more time.
|
||||
f = "Tests/images/pil_sample_cmyk.jpg"
|
||||
with Image.open(f) as im:
|
||||
# the source image has red pixels in the upper left corner.
|
||||
c, m, y, k = (x / 255.0 for x in im.getpixel((0, 0)))
|
||||
assert c == 0.0
|
||||
assert m > 0.8
|
||||
assert y > 0.8
|
||||
assert k == 0.0
|
||||
# the opposite corner is black
|
||||
c, m, y, k = (
|
||||
x / 255.0 for x in im.getpixel((im.size[0] - 1, im.size[1] - 1))
|
||||
)
|
||||
assert k > 0.9
|
||||
# roundtrip, and check again
|
||||
im = self.roundtrip(im)
|
||||
def check(im: ImageFile.ImageFile) -> None:
|
||||
cmyk = im.getpixel((0, 0))
|
||||
assert isinstance(cmyk, tuple)
|
||||
c, m, y, k = (x / 255.0 for x in cmyk)
|
||||
|
@ -152,11 +138,19 @@ class TestFileJpeg:
|
|||
assert m > 0.8
|
||||
assert y > 0.8
|
||||
assert k == 0.0
|
||||
# the opposite corner is black
|
||||
cmyk = im.getpixel((im.size[0] - 1, im.size[1] - 1))
|
||||
assert isinstance(cmyk, tuple)
|
||||
k = cmyk[3] / 255.0
|
||||
assert k > 0.9
|
||||
|
||||
with Image.open("Tests/images/pil_sample_cmyk.jpg") as im:
|
||||
# the source image has red pixels in the upper left corner.
|
||||
check(im)
|
||||
|
||||
# roundtrip, and check again
|
||||
check(self.roundtrip(im))
|
||||
|
||||
def test_rgb(self) -> None:
|
||||
def getchannels(im: JpegImagePlugin.JpegImageFile) -> tuple[int, ...]:
|
||||
return tuple(v[0] for v in im.layer)
|
||||
|
|
|
@ -156,6 +156,7 @@ def test_reload_exif_after_seek() -> None:
|
|||
def test_mp(test_file: str) -> None:
|
||||
with Image.open(test_file) as im:
|
||||
mpinfo = im._getmp()
|
||||
assert mpinfo is not None
|
||||
assert mpinfo[45056] == b"0100"
|
||||
assert mpinfo[45057] == 2
|
||||
|
||||
|
@ -165,6 +166,7 @@ def test_mp_offset() -> None:
|
|||
# in APP2 data, in contrast to normal 8
|
||||
with Image.open("Tests/images/sugarshack_ifd_offset.mpo") as im:
|
||||
mpinfo = im._getmp()
|
||||
assert mpinfo is not None
|
||||
assert mpinfo[45056] == b"0100"
|
||||
assert mpinfo[45057] == 2
|
||||
|
||||
|
@ -181,6 +183,7 @@ def test_mp_no_data() -> None:
|
|||
def test_mp_attribute(test_file: str) -> None:
|
||||
with Image.open(test_file) as im:
|
||||
mpinfo = im._getmp()
|
||||
assert mpinfo is not None
|
||||
for frame_number, mpentry in enumerate(mpinfo[0xB002]):
|
||||
mpattr = mpentry["Attribute"]
|
||||
if frame_number:
|
||||
|
|
|
@ -222,12 +222,16 @@ def test_horizontal_orientations() -> None:
|
|||
with Image.open("Tests/images/rgb32rle_top_right.tga") as im:
|
||||
px = im.load()
|
||||
assert px is not None
|
||||
assert px[90, 90][:3] == (0, 0, 0)
|
||||
value = px[90, 90]
|
||||
assert isinstance(value, tuple)
|
||||
assert value[:3] == (0, 0, 0)
|
||||
|
||||
with Image.open("Tests/images/rgb32rle_bottom_right.tga") as im:
|
||||
px = im.load()
|
||||
assert px is not None
|
||||
assert px[90, 90][:3] == (0, 255, 0)
|
||||
value = px[90, 90]
|
||||
assert isinstance(value, tuple)
|
||||
assert value[:3] == (0, 255, 0)
|
||||
|
||||
|
||||
def test_save_rle(tmp_path: Path) -> None:
|
||||
|
|
|
@ -219,6 +219,7 @@ class TestFileWebp:
|
|||
# Save P mode GIF with background
|
||||
with Image.open("Tests/images/chi.gif") as im:
|
||||
original_value = im.convert("RGB").getpixel((1, 1))
|
||||
assert isinstance(original_value, tuple)
|
||||
|
||||
# Save as WEBP
|
||||
im.save(out_webp, save_all=True)
|
||||
|
@ -230,6 +231,7 @@ class TestFileWebp:
|
|||
|
||||
with Image.open(out_gif) as reread:
|
||||
reread_value = reread.convert("RGB").getpixel((1, 1))
|
||||
assert isinstance(reread_value, tuple)
|
||||
difference = sum(abs(original_value[i] - reread_value[i]) for i in range(3))
|
||||
assert difference < 5
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from packaging.version import parse as parse_version
|
||||
|
@ -13,6 +13,7 @@ numpy = pytest.importorskip("numpy", reason="NumPy not installed")
|
|||
|
||||
im = hopper().resize((128, 100))
|
||||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
import numpy.typing as npt
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -9,6 +8,7 @@ from PIL import Image, _typing
|
|||
|
||||
from .helper import assert_deep_equal, assert_image, hopper, skip_unless_feature
|
||||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
import numpy
|
||||
import numpy.typing as npt
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Union
|
||||
from typing import Union
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -9,6 +9,7 @@ from PIL import Image, ImageQt
|
|||
|
||||
from .helper import assert_image_equal_tofile, assert_image_similar, hopper
|
||||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
import PyQt6
|
||||
import PySide6
|
||||
|
|
|
@ -8,8 +8,8 @@ from __future__ import annotations
|
|||
|
||||
import re
|
||||
import subprocess
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
TYPE_CHECKING = False
|
||||
if TYPE_CHECKING:
|
||||
from sphinx.application import Sphinx
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user