mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
4f185329f4
This adds a new test decorator: skip_unless_feature(). The argument is the same as passed to features.check(). If the feature is not supported, the test will be skipped. This removes several kinds of boilerplate copied and pasted around tests so test feature checking is handled and displayed more consistently. Refs #4193
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import pytest
|
|
from PIL import Image, TarIO, features
|
|
|
|
from .helper import is_pypy
|
|
|
|
# Sample tar archive
|
|
TEST_TAR_FILE = "Tests/images/hopper.tar"
|
|
|
|
|
|
def test_sanity():
|
|
for codec, test_path, format in [
|
|
["zlib", "hopper.png", "PNG"],
|
|
["jpg", "hopper.jpg", "JPEG"],
|
|
]:
|
|
if features.check(codec):
|
|
with TarIO.TarIO(TEST_TAR_FILE, test_path) as tar:
|
|
with Image.open(tar) as im:
|
|
im.load()
|
|
assert im.mode == "RGB"
|
|
assert im.size == (128, 128)
|
|
assert im.format == format
|
|
|
|
|
|
@pytest.mark.skipif(is_pypy(), reason="Requires CPython")
|
|
def test_unclosed_file():
|
|
def open():
|
|
TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg")
|
|
|
|
pytest.warns(ResourceWarning, open)
|
|
|
|
|
|
def test_close():
|
|
def open():
|
|
tar = TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg")
|
|
tar.close()
|
|
|
|
pytest.warns(None, open)
|
|
|
|
|
|
def test_contextmanager():
|
|
def open():
|
|
with TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg"):
|
|
pass
|
|
|
|
pytest.warns(None, open)
|