Skip to content

Commit

Permalink
Assert palette is not None
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 23, 2024
1 parent 5d5543b commit 601a56d
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def test_roundtrip_save_all_1(tmp_path: Path) -> None:
def test_loading_multiple_palettes(path: str, mode: str) -> None:
with Image.open(path) as im:
assert im.mode == "P"
assert im.palette is not None
first_frame_colors = im.palette.colors.keys()
px = im.convert("RGB").load()
assert px is not None
Expand Down Expand Up @@ -1325,6 +1326,7 @@ def test_palette_save_all_P(tmp_path: Path) -> None:
with Image.open(out) as im:
# Assert that the frames are correct, and each frame has the same palette
assert_image_equal(im.convert("RGB"), frames[0].convert("RGB"))
assert im.palette is not None
assert im.palette.palette == im.global_palette.palette

im.seek(1)
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,15 @@ def test_subsampling_decode(name: str) -> None:
def test_pclr() -> None:
with Image.open(f"{EXTRA_DIR}/issue104_jpxstream.jp2") as im:
assert im.mode == "P"
assert im.palette is not None
assert len(im.palette.colors) == 256
assert im.palette.colors[(255, 255, 255)] == 0

with Image.open(
f"{EXTRA_DIR}/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2"
) as im:
assert im.mode == "P"
assert im.palette is not None
assert len(im.palette.colors) == 139
assert im.palette.colors[(0, 0, 0, 0)] == 0

Expand Down
1 change: 1 addition & 0 deletions Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_palette_depth_8(tmp_path: Path) -> None:

def test_palette_depth_16(tmp_path: Path) -> None:
with Image.open("Tests/images/p_16.tga") as im:
assert im.palette is not None
assert im.palette.mode == "RGBA"
assert_image_equal_tofile(im.convert("RGBA"), "Tests/images/p_16.png")

Expand Down
1 change: 1 addition & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ def test_remap_palette(self) -> None:
im.putpalette(list(range(256)) * 4, "RGBA")
im_remapped = im.remap_palette(list(range(256)))
assert_image_equal(im, im_remapped)
assert im.palette is not None
assert im.palette.palette == im_remapped.palette.palette

# Test illegal image mode
Expand Down
1 change: 1 addition & 0 deletions Tests/test_image_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ def test_gif_with_rgba_palette_to_p() -> None:
with Image.open("Tests/images/hopper.gif") as im:
im.info["transparency"] = 255
im.load()
assert im.palette is not None
assert im.palette.mode == "RGB"
im_p = im.convert("P")

Expand Down
1 change: 1 addition & 0 deletions Tests/test_image_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_palette(self) -> None:
transformed = im.transform(
im.size, Image.Transform.AFFINE, [1, 0, 0, 0, 1, 0]
)
assert im.palette is not None
assert im.palette.palette == transformed.palette.palette

def test_extent(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions Tests/test_imagepalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_sanity() -> None:
def test_reload() -> None:
with Image.open("Tests/images/hopper.gif") as im:
original = im.copy()
assert im.palette is not None
im.palette.dirty = 1
assert_image_equal(im.convert("RGB"), original.convert("RGB"))

Expand Down

0 comments on commit 601a56d

Please sign in to comment.