diff --git a/Tests/test_file_avif.py b/Tests/test_file_avif.py index b2e586637..6d0cc74f9 100644 --- a/Tests/test_file_avif.py +++ b/Tests/test_file_avif.py @@ -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)) diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 20d58a9dd..e418af45c 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -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( @@ -1422,7 +1424,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() @@ -1477,7 +1481,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})) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 614044d97..d13b8aa81 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -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) diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index 73838ef44..462c95535 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -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: diff --git a/Tests/test_file_tga.py b/Tests/test_file_tga.py index 8b6ed3ed2..d3cceb37f 100644 --- a/Tests/test_file_tga.py +++ b/Tests/test_file_tga.py @@ -220,12 +220,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: diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index f61e2c82e..4ea7629d1 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -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