Add tests for wrong types

This commit is contained in:
Alexander 2018-04-22 19:51:57 +03:00
parent f826dc37d1
commit 101c095e99
2 changed files with 21 additions and 5 deletions

View File

@ -1,8 +1,7 @@
# Test the ImageMorphology functionality
from helper import unittest, PillowTestCase, hopper
from PIL import Image
from PIL import ImageMorph
from PIL import Image, ImageMorph, _imagingmorph
class MorphTests(PillowTestCase):
@ -284,6 +283,23 @@ class MorphTests(PillowTestCase):
# Assert
self.assertEqual(mop.lut, lut)
def test_wrong_mode(self):
lut = ImageMorph.LutBuilder(op_name='corner').build_lut()
imrgb = Image.new('RGB', (10, 10))
iml = Image.new('L', (10, 10))
with self.assertRaises(ValueError):
_imagingmorph.apply(bytes(lut), imrgb.im.id, iml.im.id)
with self.assertRaises(ValueError):
_imagingmorph.apply(bytes(lut), iml.im.id, imrgb.im.id)
with self.assertRaises(ValueError):
_imagingmorph.match(bytes(lut), imrgb.im.id)
# Should not raise
_imagingmorph.match(bytes(lut), iml.im.id)
if __name__ == '__main__':
unittest.main()

View File

@ -66,12 +66,12 @@ apply(PyObject *self, PyObject* args)
if (imgin->type != IMAGING_TYPE_UINT8 ||
imgin->bands != 1) {
PyErr_SetString(PyExc_RuntimeError, "Unsupported image type");
PyErr_SetString(PyExc_ValueError, "Unsupported image type");
return NULL;
}
if (imgout->type != IMAGING_TYPE_UINT8 ||
imgout->bands != 1) {
PyErr_SetString(PyExc_RuntimeError, "Unsupported image type");
PyErr_SetString(PyExc_ValueError, "Unsupported image type");
return NULL;
}
@ -169,7 +169,7 @@ match(PyObject *self, PyObject* args)
if (imgin->type != IMAGING_TYPE_UINT8 ||
imgin->bands != 1) {
PyErr_SetString(PyExc_RuntimeError, "Unsupported image type");
PyErr_SetString(PyExc_ValueError, "Unsupported image type");
return NULL;
}