2019-01-13 20:00:12 +03:00
|
|
|
from .helper import unittest, PillowTestCase
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2014-07-19 21:21:18 +04:00
|
|
|
class TestLibImage(PillowTestCase):
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
def test_setmode(self):
|
|
|
|
|
|
|
|
im = Image.new("L", (1, 1), 255)
|
|
|
|
im.im.setmode("1")
|
|
|
|
self.assertEqual(im.im.getpixel((0, 0)), 255)
|
|
|
|
im.im.setmode("L")
|
|
|
|
self.assertEqual(im.im.getpixel((0, 0)), 255)
|
|
|
|
|
|
|
|
im = Image.new("1", (1, 1), 1)
|
|
|
|
im.im.setmode("L")
|
|
|
|
self.assertEqual(im.im.getpixel((0, 0)), 255)
|
|
|
|
im.im.setmode("1")
|
|
|
|
self.assertEqual(im.im.getpixel((0, 0)), 255)
|
|
|
|
|
|
|
|
im = Image.new("RGB", (1, 1), (1, 2, 3))
|
|
|
|
im.im.setmode("RGB")
|
|
|
|
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3))
|
|
|
|
im.im.setmode("RGBA")
|
|
|
|
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3, 255))
|
|
|
|
im.im.setmode("RGBX")
|
|
|
|
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3, 255))
|
|
|
|
im.im.setmode("RGB")
|
|
|
|
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3))
|
|
|
|
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(ValueError, im.im.setmode, "L")
|
|
|
|
self.assertRaises(ValueError, im.im.setmode, "RGBABCDE")
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|