mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-29 09:23:11 +03:00
Close file pointer earlier (#8895)
This commit is contained in:
parent
f630ec097b
commit
3d4119521c
|
@ -190,9 +190,9 @@ def test_rle8() -> None:
|
||||||
# Signal end of bitmap before the image is finished
|
# Signal end of bitmap before the image is finished
|
||||||
with open("Tests/images/bmp/g/pal8rle.bmp", "rb") as fp:
|
with open("Tests/images/bmp/g/pal8rle.bmp", "rb") as fp:
|
||||||
data = fp.read(1063) + b"\x01"
|
data = fp.read(1063) + b"\x01"
|
||||||
with Image.open(io.BytesIO(data)) as im:
|
with Image.open(io.BytesIO(data)) as im:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
def test_rle4() -> None:
|
def test_rle4() -> None:
|
||||||
|
@ -214,9 +214,9 @@ def test_rle4() -> None:
|
||||||
def test_rle8_eof(file_name: str, length: int) -> None:
|
def test_rle8_eof(file_name: str, length: int) -> None:
|
||||||
with open(file_name, "rb") as fp:
|
with open(file_name, "rb") as fp:
|
||||||
data = fp.read(length)
|
data = fp.read(length)
|
||||||
with Image.open(io.BytesIO(data)) as im:
|
with Image.open(io.BytesIO(data)) as im:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
def test_offset() -> None:
|
def test_offset() -> None:
|
||||||
|
|
|
@ -457,8 +457,8 @@ def test_comment() -> None:
|
||||||
# Test an image that is truncated partway through a codestream
|
# Test an image that is truncated partway through a codestream
|
||||||
with open("Tests/images/comment.jp2", "rb") as fp:
|
with open("Tests/images/comment.jp2", "rb") as fp:
|
||||||
b = BytesIO(fp.read(130))
|
b = BytesIO(fp.read(130))
|
||||||
with Image.open(b) as im:
|
with Image.open(b) as im:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_save_comment(card: ImageFile.ImageFile) -> None:
|
def test_save_comment(card: ImageFile.ImageFile) -> None:
|
||||||
|
|
|
@ -81,7 +81,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
s = io.BytesIO()
|
s = io.BytesIO()
|
||||||
with open(test_file, "rb") as f:
|
with open(test_file, "rb") as f:
|
||||||
s.write(f.read())
|
s.write(f.read())
|
||||||
s.seek(0)
|
s.seek(0)
|
||||||
with Image.open(s) as im:
|
with Image.open(s) as im:
|
||||||
assert im.size == (500, 500)
|
assert im.size == (500, 500)
|
||||||
self._assert_noerr(tmp_path, im)
|
self._assert_noerr(tmp_path, im)
|
||||||
|
@ -1050,12 +1050,12 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
with open("Tests/images/old-style-jpeg-compression.tif", "rb") as fp:
|
with open("Tests/images/old-style-jpeg-compression.tif", "rb") as fp:
|
||||||
data = fp.read()
|
data = fp.read()
|
||||||
|
|
||||||
# Set EXIF Orientation to 2
|
# Set EXIF Orientation to 2
|
||||||
data = data[:102] + b"\x02" + data[103:]
|
data = data[:102] + b"\x02" + data[103:]
|
||||||
|
|
||||||
with Image.open(io.BytesIO(data)) as im:
|
with Image.open(io.BytesIO(data)) as im:
|
||||||
im = im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
|
im = im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
|
||||||
assert_image_equal_tofile(im, "Tests/images/old-style-jpeg-compression.png")
|
assert_image_equal_tofile(im, "Tests/images/old-style-jpeg-compression.png")
|
||||||
|
|
||||||
def test_open_missing_samplesperpixel(self) -> None:
|
def test_open_missing_samplesperpixel(self) -> None:
|
||||||
with Image.open(
|
with Image.open(
|
||||||
|
|
|
@ -32,7 +32,7 @@ class TestFileLibTiffSmall(LibTiffTestCase):
|
||||||
s = BytesIO()
|
s = BytesIO()
|
||||||
with open(test_file, "rb") as f:
|
with open(test_file, "rb") as f:
|
||||||
s.write(f.read())
|
s.write(f.read())
|
||||||
s.seek(0)
|
s.seek(0)
|
||||||
with Image.open(s) as im:
|
with Image.open(s) as im:
|
||||||
assert im.size == (128, 128)
|
assert im.size == (128, 128)
|
||||||
self._assert_noerr(tmp_path, im)
|
self._assert_noerr(tmp_path, im)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user