Pillow/Tests/test_imagepalette.py
Alex Clark bb1b3a532c Cleanup WS, courtesy of @Arfrever
find * -type f "-(" -name "*.bdf" -o -name "*.c" -o -name "*.h" -o -name "*.py" -o -name "*.rst" -o -name "*.txt" "-)" -exec sed -e "s/[[:space:]]*$//" -i {} \;
2013-06-30 18:42:19 -04:00

45 lines
879 B
Python

from tester import *
from PIL import Image
from PIL import ImagePalette
ImagePalette = ImagePalette.ImagePalette
def test_sanity():
assert_no_exception(lambda: ImagePalette("RGB", list(range(256))*3))
assert_exception(ValueError, lambda: ImagePalette("RGB", list(range(256))*2))
def test_getcolor():
palette = ImagePalette()
map = {}
for i in range(256):
map[palette.getcolor((i, i, i))] = i
assert_equal(len(map), 256)
assert_exception(ValueError, lambda: palette.getcolor((1, 2, 3)))
def test_file():
palette = ImagePalette()
file = tempfile("temp.lut")
palette.save(file)
from PIL.ImagePalette import load, raw
p = load(file)
# load returns raw palette information
assert_equal(len(p[0]), 768)
assert_equal(p[1], "RGB")
p = raw(p[1], p[0])
assert_true(isinstance(p, ImagePalette))