Pillow/Tests/test_image_getdata.py

36 lines
1.0 KiB
Python
Raw Normal View History

2014-06-10 13:10:47 +04:00
from helper import unittest, PillowTestCase, tearDownModule, lena
2014-06-10 13:10:47 +04:00
class TestImageGetData(PillowTestCase):
2014-06-10 13:10:47 +04:00
def test_sanity(self):
2014-06-10 13:10:47 +04:00
data = lena().getdata()
2014-06-10 13:10:47 +04:00
len(data)
list(data)
2014-06-10 13:10:47 +04:00
self.assertEqual(data[0], (223, 162, 133))
2014-06-10 13:10:47 +04:00
def test_roundtrip(self):
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