Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Tests/test_file_avif.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ def test_load_transparent_rgb(self) -> None:
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))
Expand Down
14 changes: 11 additions & 3 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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}))
Expand Down
24 changes: 9 additions & 15 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,27 @@ def test_comment_write(self) -> None:
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)
assert c == 0.0
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)
Expand Down
3 changes: 3 additions & 0 deletions Tests/test_file_mpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def test_background_from_gif(self, tmp_path: Path) -> None:
# 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)
Expand All @@ -230,6 +231,7 @@ def test_background_from_gif(self, tmp_path: Path) -> None:

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

Expand Down
Loading