Skip to content
Open
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
2 changes: 2 additions & 0 deletions Tests/test_file_avif.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def test_file_pointer_could_be_reused(self) -> None:
def test_background_from_gif(self, tmp_path: Path) -> None:
with Image.open("Tests/images/chi.gif") as im:
original_value = im.convert("RGB").getpixel((1, 1))
assert isinstance(original_value, tuple)

# Save as AVIF
out_avif = tmp_path / "temp.avif"
Expand All @@ -232,6 +233,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 <= 6

Expand Down
24 changes: 18 additions & 6 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def test_load_transparent_p(self) -> None:
assert_image(im, "RGBA", (162, 150))

# image has 124 unique alpha values
assert len(im.getchannel("A").getcolors()) == 124
colors = im.getchannel("A").getcolors()
assert colors is not None
assert len(colors) == 124

def test_load_transparent_rgb(self) -> None:
test_file = "Tests/images/rgb_trns.png"
Expand All @@ -241,7 +243,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][0] == 876
colors = im.getchannel("A").getcolors()
assert colors is not None
assert colors[0][0] == 876

def test_save_p_transparent_palette(self, tmp_path: Path) -> None:
in_file = "Tests/images/pil123p.png"
Expand All @@ -262,7 +266,9 @@ def test_save_p_transparent_palette(self, tmp_path: Path) -> None:
assert_image(im, "RGBA", (162, 150))

# image has 124 unique alpha values
assert len(im.getchannel("A").getcolors()) == 124
colors = im.getchannel("A").getcolors()
assert colors is not None
assert len(colors) == 124

def test_save_p_single_transparency(self, tmp_path: Path) -> None:
in_file = "Tests/images/p_trns_single.png"
Expand All @@ -285,7 +291,9 @@ def test_save_p_single_transparency(self, tmp_path: Path) -> None:
assert im.getpixel((31, 31)) == (0, 255, 52, 0)

# image has 876 transparent pixels
assert im.getchannel("A").getcolors()[0][0] == 876
colors = im.getchannel("A").getcolors()
assert colors is not None
assert colors[0][0] == 876

def test_save_p_transparent_black(self, tmp_path: Path) -> None:
# check if solid black image with full transparency
Expand Down Expand Up @@ -313,7 +321,9 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
assert im.info["transparency"] == 255

im_rgba = im.convert("RGBA")
assert im_rgba.getchannel("A").getcolors()[0][0] == num_transparent
colors = im_rgba.getchannel("A").getcolors()
assert colors is not None
assert colors[0][0] == num_transparent

test_file = tmp_path / "temp.png"
im.save(test_file)
Expand All @@ -324,7 +334,9 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
assert_image_equal(im, test_im)

test_im_rgba = test_im.convert("RGBA")
assert test_im_rgba.getchannel("A").getcolors()[0][0] == num_transparent
colors = test_im_rgba.getchannel("A").getcolors()
assert colors is not None
assert colors[0][0] == num_transparent

def test_save_rgb_single_transparency(self, tmp_path: Path) -> None:
in_file = "Tests/images/caption_6_33_22.png"
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 @@ -274,13 +274,17 @@ def test_save_l_transparency(tmp_path: Path) -> None:
in_file = "Tests/images/la.tga"
with Image.open(in_file) as im:
assert im.mode == "LA"
assert im.getchannel("A").getcolors()[0][0] == num_transparent
colors = im.getchannel("A").getcolors()
assert colors is not None
assert colors[0][0] == num_transparent

out = tmp_path / "temp.tga"
im.save(out)

with Image.open(out) as test_im:
assert test_im.mode == "LA"
assert test_im.getchannel("A").getcolors()[0][0] == num_transparent
colors = test_im.getchannel("A").getcolors()
assert colors is not None
assert colors[0][0] == num_transparent

assert_image_equal(im, test_im)
9 changes: 7 additions & 2 deletions Tests/test_imagesequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ def test_consecutive() -> None:
def test_palette_mmap() -> None:
# Using mmap in ImageFile can require to reload the palette.
with Image.open("Tests/images/multipage-mmap.tiff") as im:
color1 = im.getpalette()[:3]
palette = im.getpalette()
assert palette is not None
color1 = palette[:3]
im.seek(0)
color2 = im.getpalette()[:3]

palette = im.getpalette()
assert palette is not None
color2 = palette[:3]
assert color1 == color2


Expand Down
Loading