Pillow/Tests/test_image_putpalette.py

41 lines
1.0 KiB
Python
Raw Normal View History

import pytest
from PIL import ImagePalette
from .helper import hopper
2014-06-10 13:10:47 +04:00
def test_putpalette():
def palette(mode):
im = hopper(mode).copy()
im.putpalette(list(range(256)) * 3)
p = im.getpalette()
if p:
return im.mode, p[:10]
return im.mode
2019-06-13 18:54:24 +03:00
with pytest.raises(ValueError):
palette("1")
for mode in ["L", "LA", "P", "PA"]:
assert palette(mode) == (
"PA" if "A" in mode else "P",
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
)
with pytest.raises(ValueError):
palette("I")
with pytest.raises(ValueError):
palette("F")
with pytest.raises(ValueError):
palette("RGB")
with pytest.raises(ValueError):
palette("RGBA")
with pytest.raises(ValueError):
palette("YCbCr")
2014-06-10 13:10:47 +04:00
def test_imagepalette():
im = hopper("P")
im.putpalette(ImagePalette.negative())
im.putpalette(ImagePalette.random())
im.putpalette(ImagePalette.sepia())
im.putpalette(ImagePalette.wedge())