mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
add tests for Image.new modes
This commit is contained in:
parent
ab92adf7c9
commit
6b50ba07fd
|
@ -7,6 +7,25 @@ import sys
|
|||
|
||||
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(e.exception.message, 'unrecognized image mode')
|
||||
|
||||
def test_sanity(self):
|
||||
|
||||
im = Image.new("L", (100, 100))
|
||||
|
|
|
@ -205,7 +205,7 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size)
|
|||
|
||||
} else {
|
||||
free(im);
|
||||
return (Imaging) ImagingError_ValueError("unrecognized mode");
|
||||
return (Imaging) ImagingError_ValueError("unrecognized image mode");
|
||||
}
|
||||
|
||||
/* Setup image descriptor */
|
||||
|
@ -387,16 +387,13 @@ ImagingNew(const char* mode, int xsize, int ysize)
|
|||
int bytes;
|
||||
Imaging im;
|
||||
|
||||
if (strcmp(mode, "") == 0)
|
||||
return (Imaging) ImagingError_ValueError("empty mode");
|
||||
|
||||
if (strlen(mode) == 1) {
|
||||
if (mode[0] == 'F' || mode[0] == 'I')
|
||||
bytes = 4;
|
||||
else
|
||||
bytes = 1;
|
||||
} else
|
||||
bytes = strlen(mode); /* close enough */
|
||||
bytes = strlen(mode) || 1; /* close enough */
|
||||
|
||||
if (xsize < 0 || ysize < 0) {
|
||||
return (Imaging) ImagingError_ValueError("bad image size");
|
||||
|
|
Loading…
Reference in New Issue
Block a user