2020-01-27 14:46:52 +03:00
|
|
|
import pytest
|
2020-08-07 13:28:33 +03:00
|
|
|
|
2012-10-16 00:26:38 +04:00
|
|
|
from PIL import Image
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
def test_setmode():
|
|
|
|
im = Image.new("L", (1, 1), 255)
|
|
|
|
im.im.setmode("1")
|
|
|
|
assert im.im.getpixel((0, 0)) == 255
|
|
|
|
im.im.setmode("L")
|
|
|
|
assert im.im.getpixel((0, 0)) == 255
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
im = Image.new("1", (1, 1), 1)
|
|
|
|
im.im.setmode("L")
|
|
|
|
assert im.im.getpixel((0, 0)) == 255
|
|
|
|
im.im.setmode("1")
|
|
|
|
assert im.im.getpixel((0, 0)) == 255
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
im = Image.new("RGB", (1, 1), (1, 2, 3))
|
|
|
|
im.im.setmode("RGB")
|
|
|
|
assert im.im.getpixel((0, 0)) == (1, 2, 3)
|
|
|
|
im.im.setmode("RGBA")
|
|
|
|
assert im.im.getpixel((0, 0)) == (1, 2, 3, 255)
|
|
|
|
im.im.setmode("RGBX")
|
|
|
|
assert im.im.getpixel((0, 0)) == (1, 2, 3, 255)
|
|
|
|
im.im.setmode("RGB")
|
|
|
|
assert im.im.getpixel((0, 0)) == (1, 2, 3)
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2020-01-27 14:46:52 +03:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
im.im.setmode("L")
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
im.im.setmode("RGBABCDE")
|