Pillow/Tests/test_image_quantize.py

36 lines
765 B
Python
Raw Normal View History

from helper import unittest, PillowTestCase, hopper
from PIL import Image
2014-06-10 13:10:47 +04:00
class TestImageQuantize(PillowTestCase):
2014-06-10 13:10:47 +04:00
def test_sanity(self):
im = hopper()
2014-06-10 13:10:47 +04:00
im = im.quantize()
self.assert_image(im, "P", im.size)
im = hopper()
im = im.quantize(palette=hopper("P"))
2014-06-10 13:10:47 +04:00
self.assert_image(im, "P", im.size)
2014-06-10 13:10:47 +04:00
def test_octree_quantize(self):
im = hopper()
2014-06-10 13:10:47 +04:00
im = im.quantize(100, Image.FASTOCTREE)
self.assert_image(im, "P", im.size)
2014-03-26 08:42:04 +04:00
2014-06-10 13:10:47 +04:00
assert len(im.getcolors()) == 100
def test_rgba_quantize(self):
im = hopper('RGBA')
2014-06-10 13:10:47 +04:00
im.quantize()
self.assertRaises(Exception, lambda: im.quantize(method=0))
if __name__ == '__main__':
unittest.main()
# End of file