2019-07-06 23:40:53 +03:00
|
|
|
import os
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
2014-04-18 09:01:55 +04:00
|
|
|
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageLoad(PillowTestCase):
|
|
|
|
def test_sanity(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-04 09:44:46 +04:00
|
|
|
im = hopper()
|
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-09-04 09:44:46 +04:00
|
|
|
self.assertEqual(pix[0, 0], (20, 20, 70))
|
2014-04-18 09:01:55 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_close(self):
|
2014-09-04 09:44:46 +04:00
|
|
|
im = Image.open("Tests/images/hopper.gif")
|
2014-06-10 13:10:47 +04:00
|
|
|
im.close()
|
2015-04-02 10:08:14 +03:00
|
|
|
self.assertRaises(ValueError, im.load)
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(ValueError, im.getpixel, (0, 0))
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
def test_contextmanager(self):
|
|
|
|
fn = None
|
2014-09-04 09:44:46 +04:00
|
|
|
with Image.open("Tests/images/hopper.gif") as im:
|
2014-06-10 13:10:47 +04:00
|
|
|
fn = im.fp.fileno()
|
|
|
|
os.fstat(fn)
|
|
|
|
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(OSError, os.fstat, fn)
|
2019-03-06 13:55:32 +03:00
|
|
|
|
|
|
|
def test_contextmanager_non_exclusive_fp(self):
|
|
|
|
with open("Tests/images/hopper.gif", "rb") as fp:
|
|
|
|
with Image.open(fp):
|
|
|
|
pass
|
|
|
|
|
|
|
|
self.assertFalse(fp.closed)
|