mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 02:46:18 +03:00
d50445ff30
Similar to the recent adoption of Black. isort is a Python utility to sort imports alphabetically and automatically separate into sections. By using isort, contributors can quickly and automatically conform to the projects style without thinking. Just let the tool do it. Uses the configuration recommended by the Black to avoid conflicts of style. Rewrite TestImageQt.test_deprecated to no rely on import order.
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from PIL import Image
|
|
|
|
from .helper import PillowTestCase
|
|
|
|
|
|
class TestImagePutAlpha(PillowTestCase):
|
|
def test_interface(self):
|
|
|
|
im = Image.new("RGBA", (1, 1), (1, 2, 3, 0))
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2, 3, 0))
|
|
|
|
im = Image.new("RGBA", (1, 1), (1, 2, 3))
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2, 3, 255))
|
|
|
|
im.putalpha(Image.new("L", im.size, 4))
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2, 3, 4))
|
|
|
|
im.putalpha(5)
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2, 3, 5))
|
|
|
|
def test_promote(self):
|
|
|
|
im = Image.new("L", (1, 1), 1)
|
|
self.assertEqual(im.getpixel((0, 0)), 1)
|
|
|
|
im.putalpha(2)
|
|
self.assertEqual(im.mode, "LA")
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2))
|
|
|
|
im = Image.new("P", (1, 1), 1)
|
|
self.assertEqual(im.getpixel((0, 0)), 1)
|
|
|
|
im.putalpha(2)
|
|
self.assertEqual(im.mode, "PA")
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2))
|
|
|
|
im = Image.new("RGB", (1, 1), (1, 2, 3))
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2, 3))
|
|
|
|
im.putalpha(4)
|
|
self.assertEqual(im.mode, "RGBA")
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2, 3, 4))
|
|
|
|
def test_readonly(self):
|
|
|
|
im = Image.new("RGB", (1, 1), (1, 2, 3))
|
|
im.readonly = 1
|
|
|
|
im.putalpha(4)
|
|
self.assertFalse(im.readonly)
|
|
self.assertEqual(im.mode, "RGBA")
|
|
self.assertEqual(im.getpixel((0, 0)), (1, 2, 3, 4))
|