Pillow/Tests/test_image_getdata.py

36 lines
1015 B
Python
Raw Normal View History

2014-07-07 21:03:50 +04:00
from helper import unittest, PillowTestCase, 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