Merge pull request #719 from wiredfool/imagepalette

Tests for Imagepalette.save()
This commit is contained in:
Alex Clark ☺ 2014-06-24 13:41:32 -04:00
commit 7d232a3c32
2 changed files with 10 additions and 7 deletions

View File

@ -101,8 +101,11 @@ class ImagePalette:
fp.write("# Mode: %s\n" % self.mode)
for i in range(256):
fp.write("%d" % i)
for j in range(i, len(self.palette), 256):
fp.write(" %d" % self.palette[j])
for j in range(i*len(self.mode), (i+1)*len(self.mode)):
try:
fp.write(" %d" % self.palette[j])
except IndexError:
fp.write(" 0")
fp.write("\n")
fp.close()

View File

@ -26,15 +26,15 @@ class TestImagePalette(PillowTestCase):
def test_file(self):
palette = ImagePalette()
palette = ImagePalette("RGB", list(range(256))*3)
file = self.tempfile("temp.lut")
f = self.tempfile("temp.lut")
palette.save(file)
palette.save(f)
from PIL.ImagePalette import load, raw
p = load(file)
p = load(f)
# load returns raw palette information
self.assertEqual(len(p[0]), 768)
@ -42,7 +42,7 @@ class TestImagePalette(PillowTestCase):
p = raw(p[1], p[0])
self.assertIsInstance(p, ImagePalette)
self.assertEqual(p.palette, palette.tobytes())
if __name__ == '__main__':
unittest.main()