Pillow/Tests/test_image_quantize.py

36 lines
769 B
Python
Raw Normal View History

2014-06-10 13:10:47 +04:00
from helper import unittest, PillowTestCase, tearDownModule, lena
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 = lena()
2014-06-10 13:10:47 +04:00
im = im.quantize()
self.assert_image(im, "P", im.size)
2014-06-10 13:10:47 +04:00
im = lena()
im = im.quantize(palette=lena("P"))
self.assert_image(im, "P", im.size)
2014-06-10 13:10:47 +04:00
def test_octree_quantize(self):
im = lena()
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 = lena('RGBA')
im.quantize()
self.assertRaises(Exception, lambda: im.quantize(method=0))
if __name__ == '__main__':
unittest.main()
# End of file