Pillow/Tests/test_file_tar.py
Jon Dufresne f72e64b90b Remove unnecessary setup_module() from test_file_tar.py
The test_sanity() already checks the decorder exists and the other tests
can run without zlib/jpeg installed.
2020-02-18 13:02:30 -08:00

48 lines
1.1 KiB
Python

import pytest
from PIL import Image, TarIO
from .helper import is_pypy
codecs = dir(Image.core)
# Sample tar archive
TEST_TAR_FILE = "Tests/images/hopper.tar"
def test_sanity():
for codec, test_path, format in [
["zip_decoder", "hopper.png", "PNG"],
["jpeg_decoder", "hopper.jpg", "JPEG"],
]:
if codec in codecs:
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)