Pillow/Tests/test_file_libtiff_small.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.5 KiB
Python
Raw Normal View History

from __future__ import annotations
from io import BytesIO
2013-04-22 00:53:43 +04:00
from PIL import Image
from .test_file_libtiff import LibTiffTestCase
2013-04-22 00:53:43 +04:00
class TestFileLibTiffSmall(LibTiffTestCase):
2013-04-22 00:53:43 +04:00
2020-08-31 00:37:17 +03:00
"""The small lena image was failing on open in the libtiff
decoder because the file pointer was set to the wrong place
by a spurious seek. It wasn't failing with the byteio method.
2013-04-22 00:53:43 +04:00
2020-08-31 00:37:17 +03:00
It was fixed by forcing an lseek to the beginning of the
file just before reading in libtiff. These tests remain
to ensure that it stays fixed."""
2013-04-22 00:53:43 +04:00
2020-03-02 17:02:19 +03:00
def test_g4_hopper_file(self, tmp_path):
2014-06-10 13:10:47 +04:00
"""Testing the open file load path"""
2013-04-22 00:53:43 +04:00
2015-04-24 11:24:52 +03:00
test_file = "Tests/images/hopper_g4.tif"
2019-06-13 18:54:11 +03:00
with open(test_file, "rb") as f:
2019-11-25 23:03:23 +03:00
with Image.open(f) as im:
assert im.size == (128, 128)
2020-03-02 17:02:19 +03:00
self._assert_noerr(tmp_path, im)
2013-04-22 00:53:43 +04:00
2020-03-02 17:02:19 +03:00
def test_g4_hopper_bytesio(self, tmp_path):
2014-06-10 13:10:47 +04:00
"""Testing the bytesio loading code path"""
2015-04-24 11:24:52 +03:00
test_file = "Tests/images/hopper_g4.tif"
2014-06-10 13:10:47 +04:00
s = BytesIO()
2019-06-13 18:54:11 +03:00
with open(test_file, "rb") as f:
2014-06-10 13:10:47 +04:00
s.write(f.read())
s.seek(0)
2019-11-25 23:03:23 +03:00
with Image.open(s) as im:
assert im.size == (128, 128)
2020-03-02 17:02:19 +03:00
self._assert_noerr(tmp_path, im)
2020-03-02 17:02:19 +03:00
def test_g4_hopper(self, tmp_path):
2014-09-23 11:30:55 +04:00
"""The 128x128 lena image failed for some reason."""
2013-04-22 00:53:43 +04:00
2015-04-24 11:24:52 +03:00
test_file = "Tests/images/hopper_g4.tif"
2019-11-25 23:03:23 +03:00
with Image.open(test_file) as im:
assert im.size == (128, 128)
2020-03-02 17:02:19 +03:00
self._assert_noerr(tmp_path, im)