mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +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.
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
from .helper import PillowTestCase, hopper
|
|
|
|
from PIL import Image
|
|
from PIL import ImageEnhance
|
|
|
|
|
|
class TestImageEnhance(PillowTestCase):
|
|
|
|
def test_sanity(self):
|
|
|
|
# FIXME: assert_image
|
|
# Implicit asserts no exception:
|
|
ImageEnhance.Color(hopper()).enhance(0.5)
|
|
ImageEnhance.Contrast(hopper()).enhance(0.5)
|
|
ImageEnhance.Brightness(hopper()).enhance(0.5)
|
|
ImageEnhance.Sharpness(hopper()).enhance(0.5)
|
|
|
|
def test_crash(self):
|
|
|
|
# crashes on small images
|
|
im = Image.new("RGB", (1, 1))
|
|
ImageEnhance.Sharpness(im).enhance(0.5)
|
|
|
|
def _half_transparent_image(self):
|
|
# returns an image, half transparent, half solid
|
|
im = hopper('RGB')
|
|
|
|
transparent = Image.new('L', im.size, 0)
|
|
solid = Image.new('L', (im.size[0]//2, im.size[1]), 255)
|
|
transparent.paste(solid, (0, 0))
|
|
im.putalpha(transparent)
|
|
|
|
return im
|
|
|
|
def _check_alpha(self, im, original, op, amount):
|
|
self.assertEqual(im.getbands(), original.getbands())
|
|
self.assert_image_equal(im.getchannel('A'), original.getchannel('A'),
|
|
"Diff on %s: %s" % (op, amount))
|
|
|
|
def test_alpha(self):
|
|
# Issue https://github.com/python-pillow/Pillow/issues/899
|
|
# Is alpha preserved through image enhancement?
|
|
|
|
original = self._half_transparent_image()
|
|
|
|
for op in ['Color', 'Brightness', 'Contrast', 'Sharpness']:
|
|
for amount in [0, 0.5, 1.0]:
|
|
self._check_alpha(
|
|
getattr(ImageEnhance, op)(original).enhance(amount),
|
|
original, op, amount)
|