Skip to content

Commit e08f910

Browse files
authored
Improve PaletteFile coverage (#9396)
2 parents d1974d7 + 2e9d548 commit e08f910

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Tests/test_imagepalette.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

3+
from io import BytesIO
34
from pathlib import Path
45

56
import pytest
67

7-
from PIL import Image, ImagePalette
8+
from PIL import Image, ImagePalette, PaletteFile
89

910
from .helper import assert_image_equal, assert_image_equal_tofile
1011

@@ -202,6 +203,19 @@ def test_2bit_palette(tmp_path: Path) -> None:
202203
assert_image_equal_tofile(img, outfile)
203204

204205

206+
def test_getpalette() -> None:
207+
b = BytesIO(b"0 1\n1 2 3 4")
208+
p = PaletteFile.PaletteFile(b)
209+
210+
palette, rawmode = p.getpalette()
211+
assert palette[:6] == b"\x01\x01\x01\x02\x03\x04"
212+
assert rawmode == "RGB"
213+
214+
205215
def test_invalid_palette() -> None:
206216
with pytest.raises(OSError):
207217
ImagePalette.load("Tests/images/hopper.jpg")
218+
219+
b = BytesIO(b"1" * 101)
220+
with pytest.raises(SyntaxError, match="bad palette file"):
221+
PaletteFile.PaletteFile(b)

0 commit comments

Comments
 (0)