2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2019-10-07 16:28:36 +03:00
|
|
|
from io import BytesIO
|
|
|
|
|
2013-04-22 00:53:43 +04:00
|
|
|
from PIL import Image
|
|
|
|
|
2019-01-13 20:00:12 +03:00
|
|
|
from .test_file_libtiff import LibTiffTestCase
|
2013-04-22 00:53:43 +04:00
|
|
|
|
|
|
|
|
2014-08-26 20:57:15 +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:
|
2020-02-22 16:06:21 +03:00
|
|
|
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:
|
2020-02-22 16:06:21 +03:00
|
|
|
assert im.size == (128, 128)
|
2020-03-02 17:02:19 +03:00
|
|
|
self._assert_noerr(tmp_path, im)
|
2013-07-01 02:42:19 +04:00
|
|
|
|
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:
|
2020-02-22 16:06:21 +03:00
|
|
|
assert im.size == (128, 128)
|
2020-03-02 17:02:19 +03:00
|
|
|
self._assert_noerr(tmp_path, im)
|