Pillow/Tests/test_imagepalette.py

51 lines
1.1 KiB
Python
Raw Normal View History

2014-06-10 13:10:47 +04:00
from helper import unittest, PillowTestCase, tearDownModule
from PIL import ImagePalette
ImagePalette = ImagePalette.ImagePalette
2014-06-10 13:10:47 +04:00
class TestImagePalette(PillowTestCase):
2014-06-10 13:10:47 +04:00
def test_sanity(self):
2014-06-10 13:10:47 +04:00
ImagePalette("RGB", list(range(256))*3)
self.assertRaises(
ValueError, lambda: ImagePalette("RGB", list(range(256))*2))
2014-06-10 13:10:47 +04:00
def test_getcolor(self):
2014-06-10 13:10:47 +04:00
palette = ImagePalette()
2014-06-10 13:10:47 +04:00
map = {}
for i in range(256):
map[palette.getcolor((i, i, i))] = i
2014-06-10 13:10:47 +04:00
self.assertEqual(len(map), 256)
self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3)))
2014-06-10 13:10:47 +04:00
def test_file(self):
2014-06-10 13:10:47 +04:00
palette = ImagePalette()
2014-06-10 13:10:47 +04:00
file = self.tempfile("temp.lut")
2014-06-10 13:10:47 +04:00
palette.save(file)
2014-06-10 13:10:47 +04:00
from PIL.ImagePalette import load, raw
2014-06-10 13:10:47 +04:00
p = load(file)
2014-06-10 13:10:47 +04:00
# load returns raw palette information
self.assertEqual(len(p[0]), 768)
self.assertEqual(p[1], "RGB")
2014-06-10 13:10:47 +04:00
p = raw(p[1], p[0])
self.assertIsInstance(p, ImagePalette)
2014-06-10 13:10:47 +04:00
if __name__ == '__main__':
unittest.main()
# End of file