Converttest_image_load.py

This commit is contained in:
hugovk 2014-06-05 11:39:29 +03:00
parent b7eb1de922
commit d385dd81a7
2 changed files with 35 additions and 27 deletions

View File

@ -1,27 +0,0 @@
from tester import *
from PIL import Image
import os
def test_sanity():
im = lena()
pix = im.load()
assert_equal(pix[0, 0], (223, 162, 133))
def test_close():
im = Image.open("Images/lena.gif")
assert_no_exception(lambda: im.close())
assert_exception(ValueError, lambda: im.load())
assert_exception(ValueError, lambda: im.getpixel((0,0)))
def test_contextmanager():
fn = None
with Image.open("Images/lena.gif") as im:
fn = im.fp.fileno()
assert_no_exception(lambda: os.fstat(fn))
assert_exception(OSError, lambda: os.fstat(fn))

35
test/test_image_load.py Normal file
View File

@ -0,0 +1,35 @@
from helper import unittest, PillowTestCase, lena
from PIL import Image
import os
class TestImageLoad(PillowTestCase):
def test_sanity(self):
im = lena()
pix = im.load()
self.assertEqual(pix[0, 0], (223, 162, 133))
def test_close(self):
im = Image.open("Images/lena.gif")
im.close()
self.assert_exception(ValueError, lambda: im.load())
self.assert_exception(ValueError, lambda: im.getpixel((0, 0)))
def test_contextmanager(self):
fn = None
with Image.open("Images/lena.gif") as im:
fn = im.fp.fileno()
os.fstat(fn)
self.assert_exception(OSError, lambda: os.fstat(fn))
if __name__ == '__main__':
unittest.main()
# End of file