Pillow/Tests/test_image_load.py

41 lines
749 B
Python
Raw Normal View History

import os
2020-01-27 14:46:52 +03:00
import pytest
from PIL import Image
2020-01-27 14:46:52 +03:00
from .helper import hopper
2014-04-18 09:01:55 +04:00
2020-01-27 14:46:52 +03:00
def test_sanity():
im = hopper()
pix = im.load()
2020-01-27 14:46:52 +03:00
assert pix[0, 0] == (20, 20, 70)
2014-04-18 09:01:55 +04:00
2020-01-27 14:46:52 +03:00
def test_close():
im = Image.open("Tests/images/hopper.gif")
im.close()
with pytest.raises(ValueError):
im.load()
with pytest.raises(ValueError):
im.getpixel((0, 0))
2014-04-18 09:01:55 +04:00
2014-06-10 13:10:47 +04:00
2020-01-27 14:46:52 +03:00
def test_contextmanager():
fn = None
with Image.open("Tests/images/hopper.gif") as im:
fn = im.fp.fileno()
os.fstat(fn)
2014-06-10 13:10:47 +04:00
2020-01-27 14:46:52 +03:00
with pytest.raises(OSError):
os.fstat(fn)
2020-01-27 14:46:52 +03:00
def test_contextmanager_non_exclusive_fp():
with open("Tests/images/hopper.gif", "rb") as fp:
with Image.open(fp):
pass
assert not fp.closed