File: test_file_tar.py

package info (click to toggle)
pillow 8.1.2%2Bdfsg-0.3%2Bdeb11u2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 65,628 kB
  • sloc: python: 35,630; ansic: 31,009; makefile: 388; javascript: 114; sh: 77
file content (46 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)