2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase, lena
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2014-04-18 09:01:55 +04:00
|
|
|
import os
|
|
|
|
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageLoad(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
|
|
|
im = lena()
|
2014-04-18 09:01:55 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
pix = im.load()
|
2014-04-18 09:01:55 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(pix[0, 0], (223, 162, 133))
|
2014-04-18 09:01:55 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_close(self):
|
2014-06-23 10:19:29 +04:00
|
|
|
im = Image.open("Tests/images/lena.gif")
|
2014-06-10 13:10:47 +04:00
|
|
|
im.close()
|
|
|
|
self.assertRaises(ValueError, lambda: im.load())
|
|
|
|
self.assertRaises(ValueError, lambda: im.getpixel((0, 0)))
|
|
|
|
|
|
|
|
def test_contextmanager(self):
|
|
|
|
fn = None
|
2014-06-23 10:19:29 +04:00
|
|
|
with Image.open("Tests/images/lena.gif") as im:
|
2014-06-10 13:10:47 +04:00
|
|
|
fn = im.fp.fileno()
|
|
|
|
os.fstat(fn)
|
|
|
|
|
|
|
|
self.assertRaises(OSError, lambda: os.fstat(fn))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|