mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 12:17:14 +03:00
4de5477b61
With the introduction and use of pytest, it is simple and easy to execute specific tests in isolation through documented command line arguments. Either by specifying the module path or through the `-k EXPRESSION` argument. There is no longer any need to provide the boilerplate: if __name__ == '__main__': unittest.main() To every test file. It is simply noise. The pattern remains in test files that aren't named with `test_*` as those files are not discovered and executed by pytest by default.
49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
from .helper import PillowTestCase, hopper
|
|
|
|
from PIL import Image
|
|
|
|
|
|
class TestImageQuantize(PillowTestCase):
|
|
|
|
def test_sanity(self):
|
|
image = hopper()
|
|
converted = image.quantize()
|
|
self.assert_image(converted, 'P', converted.size)
|
|
self.assert_image_similar(converted.convert('RGB'), image, 10)
|
|
|
|
image = hopper()
|
|
converted = image.quantize(palette=hopper('P'))
|
|
self.assert_image(converted, 'P', converted.size)
|
|
self.assert_image_similar(converted.convert('RGB'), image, 60)
|
|
|
|
def test_libimagequant_quantize(self):
|
|
image = hopper()
|
|
try:
|
|
converted = image.quantize(100, Image.LIBIMAGEQUANT)
|
|
except ValueError as ex:
|
|
if 'dependency' in str(ex).lower():
|
|
self.skipTest('libimagequant support not available')
|
|
else:
|
|
raise
|
|
self.assert_image(converted, 'P', converted.size)
|
|
self.assert_image_similar(converted.convert('RGB'), image, 15)
|
|
self.assertEqual(len(converted.getcolors()), 100)
|
|
|
|
def test_octree_quantize(self):
|
|
image = hopper()
|
|
converted = image.quantize(100, Image.FASTOCTREE)
|
|
self.assert_image(converted, 'P', converted.size)
|
|
self.assert_image_similar(converted.convert('RGB'), image, 20)
|
|
self.assertEqual(len(converted.getcolors()), 100)
|
|
|
|
def test_rgba_quantize(self):
|
|
image = hopper('RGBA')
|
|
image.quantize()
|
|
self.assertRaises(ValueError, image.quantize, method=0)
|
|
|
|
def test_quantize(self):
|
|
image = Image.open('Tests/images/caption_6_33_22.png').convert('RGB')
|
|
converted = image.quantize()
|
|
self.assert_image(converted, 'P', converted.size)
|
|
self.assert_image_similar(converted.convert('RGB'), image, 1)
|