2014-06-10 13:10:47 +04:00
|
|
|
from helper import unittest, PillowTestCase, tearDownModule, lena
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageGetData(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
data = lena().getdata()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
len(data)
|
|
|
|
list(data)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(data[0], (223, 162, 133))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_roundtrip(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def getdata(mode):
|
|
|
|
im = lena(mode).resize((32, 30))
|
|
|
|
data = im.getdata()
|
|
|
|
return data[0], len(data), len(list(data))
|
|
|
|
|
|
|
|
self.assertEqual(getdata("1"), (255, 960, 960))
|
|
|
|
self.assertEqual(getdata("L"), (176, 960, 960))
|
|
|
|
self.assertEqual(getdata("I"), (176, 960, 960))
|
|
|
|
self.assertEqual(getdata("F"), (176.0, 960, 960))
|
|
|
|
self.assertEqual(getdata("RGB"), ((223, 162, 133), 960, 960))
|
|
|
|
self.assertEqual(getdata("RGBA"), ((223, 162, 133, 255), 960, 960))
|
|
|
|
self.assertEqual(getdata("CMYK"), ((32, 93, 122, 0), 960, 960))
|
|
|
|
self.assertEqual(getdata("YCbCr"), ((176, 103, 160), 960, 960))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|