Skip to content

Commit 3d41195

Browse files
authored
Close file pointer earlier (#8895)
1 parent f630ec0 commit 3d41195

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

Tests/test_file_bmp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ def test_rle8() -> None:
190190
# Signal end of bitmap before the image is finished
191191
with open("Tests/images/bmp/g/pal8rle.bmp", "rb") as fp:
192192
data = fp.read(1063) + b"\x01"
193-
with Image.open(io.BytesIO(data)) as im:
194-
with pytest.raises(ValueError):
195-
im.load()
193+
with Image.open(io.BytesIO(data)) as im:
194+
with pytest.raises(ValueError):
195+
im.load()
196196

197197

198198
def test_rle4() -> None:
@@ -214,9 +214,9 @@ def test_rle4() -> None:
214214
def test_rle8_eof(file_name: str, length: int) -> None:
215215
with open(file_name, "rb") as fp:
216216
data = fp.read(length)
217-
with Image.open(io.BytesIO(data)) as im:
218-
with pytest.raises(ValueError):
219-
im.load()
217+
with Image.open(io.BytesIO(data)) as im:
218+
with pytest.raises(ValueError):
219+
im.load()
220220

221221

222222
def test_offset() -> None:

Tests/test_file_jpeg2k.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ def test_comment() -> None:
457457
# Test an image that is truncated partway through a codestream
458458
with open("Tests/images/comment.jp2", "rb") as fp:
459459
b = BytesIO(fp.read(130))
460-
with Image.open(b) as im:
461-
pass
460+
with Image.open(b) as im:
461+
pass
462462

463463

464464
def test_save_comment(card: ImageFile.ImageFile) -> None:

Tests/test_file_libtiff.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_g4_tiff_bytesio(self, tmp_path: Path) -> None:
8181
s = io.BytesIO()
8282
with open(test_file, "rb") as f:
8383
s.write(f.read())
84-
s.seek(0)
84+
s.seek(0)
8585
with Image.open(s) as im:
8686
assert im.size == (500, 500)
8787
self._assert_noerr(tmp_path, im)
@@ -1050,12 +1050,12 @@ def test_old_style_jpeg_orientation(self) -> None:
10501050
with open("Tests/images/old-style-jpeg-compression.tif", "rb") as fp:
10511051
data = fp.read()
10521052

1053-
# Set EXIF Orientation to 2
1054-
data = data[:102] + b"\x02" + data[103:]
1053+
# Set EXIF Orientation to 2
1054+
data = data[:102] + b"\x02" + data[103:]
10551055

1056-
with Image.open(io.BytesIO(data)) as im:
1057-
im = im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
1058-
assert_image_equal_tofile(im, "Tests/images/old-style-jpeg-compression.png")
1056+
with Image.open(io.BytesIO(data)) as im:
1057+
im = im.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
1058+
assert_image_equal_tofile(im, "Tests/images/old-style-jpeg-compression.png")
10591059

10601060
def test_open_missing_samplesperpixel(self) -> None:
10611061
with Image.open(

Tests/test_file_libtiff_small.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_g4_hopper_bytesio(self, tmp_path: Path) -> None:
3232
s = BytesIO()
3333
with open(test_file, "rb") as f:
3434
s.write(f.read())
35-
s.seek(0)
35+
s.seek(0)
3636
with Image.open(s) as im:
3737
assert im.size == (128, 128)
3838
self._assert_noerr(tmp_path, im)

0 commit comments

Comments
 (0)