Test all applicable numpy datatypes for Image.fromarray()

This commit is contained in:
Bryant Mairs 2016-04-11 11:13:17 -07:00 committed by wiredfool
parent 30eced6286
commit 51247fb7f0

View File

@ -43,24 +43,38 @@ class TestNumpy(PillowTestCase):
# print dtype, list(i.getdata())
return i
# self.assert_image(to_image(numpy.bool, boolean=1), "1", (10, 10))
# self.assert_image(to_image(numpy.bool8, boolean=1), "1", (10, 10))
# Check supported 1-bit integer formats
self.assertRaises(TypeError, lambda: to_image(numpy.bool))
self.assertRaises(TypeError, lambda: to_image(numpy.bool8))
self.assertRaises(TypeError, lambda: to_image(numpy.uint))
# Check supported 8-bit integer formats
self.assert_image(to_image(numpy.uint8), "L", (10, 10))
self.assertRaises(TypeError, lambda: to_image(numpy.uint16))
self.assertRaises(TypeError, lambda: to_image(numpy.uint32))
self.assertRaises(TypeError, lambda: to_image(numpy.uint64))
self.assert_image(to_image(numpy.uint8, 3), "RGB", (10, 10))
self.assert_image(to_image(numpy.uint8, 4), "RGBA", (10, 10))
self.assert_image(to_image(numpy.int8), "I", (10, 10))
if Image._ENDIAN == '<': # Little endian
self.assert_image(to_image(numpy.int16), "I;16", (10, 10))
# Check non-fixed-size integer types
self.assertRaises(TypeError, lambda: to_image(numpy.uint))
self.assert_image(to_image(numpy.int), "I", (10, 10))
# Check 16-bit integer formats
if Image._ENDIAN == '<':
self.assert_image(to_image(numpy.uint16), "I;16L", (10, 10))
else:
self.assert_image(to_image(numpy.int16), "I;16B", (10, 10))
self.assert_image(to_image(numpy.uint16), "I;16B", (10, 10))
self.assertRaises(TypeError, lambda: to_image(numpy.int16))
# Check 32-bit integer formats
self.assertRaises(TypeError, lambda: to_image(numpy.uint32))
self.assert_image(to_image(numpy.int32), "I", (10, 10))
# Check 64-bit integer formats
self.assertRaises(TypeError, lambda: to_image(numpy.uint64))
self.assertRaises(TypeError, lambda: to_image(numpy.int64))
# Check floating-point formats
self.assert_image(to_image(numpy.float), "F", (10, 10))
self.assertRaises(TypeError, lambda: to_image(numpy.float16))
self.assert_image(to_image(numpy.float32), "F", (10, 10))
self.assert_image(to_image(numpy.float64), "F", (10, 10))