Pillow/Tests/test_file_tar.py
Hugo van Kemenade 4a4b90c365
Autotype tests (#7756)
* autotyping: --none-return
* autotyping: --scalar-return
* autotyping: --int-param
* autotyping: --float-param
* autotyping: --str-param
* autotyping: --annotate-named-param tmp_path:pathlib.Path
2024-01-31 20:12:58 +11:00

48 lines
1.1 KiB
Python

from __future__ import annotations
import warnings
import pytest
from PIL import Image, TarIO, features
from .helper import is_pypy
# Sample tar archive
TEST_TAR_FILE = "Tests/images/hopper.tar"
@pytest.mark.parametrize(
"codec, test_path, format",
(
("zlib", "hopper.png", "PNG"),
("jpg", "hopper.jpg", "JPEG"),
),
)
def test_sanity(codec, test_path, format) -> None:
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() -> None:
with pytest.warns(ResourceWarning):
TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg")
def test_close() -> None:
with warnings.catch_warnings():
tar = TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg")
tar.close()
def test_contextmanager() -> None:
with warnings.catch_warnings():
with TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg"):
pass