import io import os import shutil import tempfile import unittest import pytest from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError from .helper import ( PillowTestCase, assert_image_equal, assert_image_similar, assert_not_all_same, hopper, is_win32, ) class TestImage(PillowTestCase): def test_image_modes_success(self): for mode in [ "1", "P", "PA", "L", "LA", "La", "F", "I", "I;16", "I;16L", "I;16B", "I;16N", "RGB", "RGBX", "RGBA", "RGBa", "CMYK", "YCbCr", "LAB", "HSV", ]: Image.new(mode, (1, 1)) def test_image_modes_fail(self): for mode in [ "", "bad", "very very long", "BGR;15", "BGR;16", "BGR;24", "BGR;32", ]: with self.assertRaises(ValueError) as e: Image.new(mode, (1, 1)) self.assertEqual(str(e.exception), "unrecognized image mode") def test_exception_inheritance(self): self.assertTrue(issubclass(UnidentifiedImageError, IOError)) def test_sanity(self): im = Image.new("L", (100, 100)) self.assertEqual(repr(im)[:45], "