Skip to content

Commit 3bb39c7

Browse files
authored
Merge pull request #4536 from hugovk/oserror
Replace IOError and WindowsError aliases with OSError
2 parents caeae8f + 29147e7 commit 3bb39c7

53 files changed

Lines changed: 155 additions & 131 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Tests/check_j2k_overflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
def test_j2k_overflow(tmp_path):
66
im = Image.new("RGBA", (1024, 131584))
77
target = str(tmp_path / "temp.jpc")
8-
with pytest.raises(IOError):
8+
with pytest.raises(OSError):
99
im.save(target)

Tests/check_libtiff_segfault.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ def test_libtiff_segfault():
99
libtiff >= 4.0.0
1010
"""
1111

12-
with pytest.raises(IOError):
12+
with pytest.raises(OSError):
1313
with Image.open(TEST_FILE) as im:
1414
im.load()

Tests/test_file_bufrstub.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_load():
3232
with Image.open(TEST_FILE) as im:
3333

3434
# Act / Assert: stub cannot load without an implemented handler
35-
with pytest.raises(IOError):
35+
with pytest.raises(OSError):
3636
im.load()
3737

3838

@@ -42,5 +42,5 @@ def test_save(tmp_path):
4242
tmpfile = str(tmp_path / "temp.bufr")
4343

4444
# Act / Assert: stub cannot save without an implemented handler
45-
with pytest.raises(IOError):
45+
with pytest.raises(OSError):
4646
im.save(tmpfile)

Tests/test_file_dds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_short_header():
138138
def short_header():
139139
Image.open(BytesIO(img_file[:119]))
140140

141-
with pytest.raises(IOError):
141+
with pytest.raises(OSError):
142142
short_header()
143143

144144

@@ -152,7 +152,7 @@ def short_file():
152152
with Image.open(BytesIO(img_file[:-100])) as im:
153153
im.load()
154154

155-
with pytest.raises(IOError):
155+
with pytest.raises(OSError):
156156
short_file()
157157

158158

Tests/test_file_fitsstub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_load():
3030
with Image.open(TEST_FILE) as im:
3131

3232
# Act / Assert: stub cannot load without an implemented handler
33-
with pytest.raises(IOError):
33+
with pytest.raises(OSError):
3434
im.load()
3535

3636

@@ -41,7 +41,7 @@ def test_save():
4141
dummy_filename = "dummy.filename"
4242

4343
# Act / Assert: stub cannot save without an implemented handler
44-
with pytest.raises(IOError):
44+
with pytest.raises(OSError):
4545
im.save(dummy_filename)
46-
with pytest.raises(IOError):
46+
with pytest.raises(OSError):
4747
FitsStubImagePlugin._save(im, dummy_fp, dummy_filename)

Tests/test_file_fpx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ def test_invalid_file():
1919

2020

2121
def test_fpx_invalid_number_of_bands():
22-
with pytest.raises(IOError, match="Invalid number of bands"):
22+
with pytest.raises(OSError, match="Invalid number of bands"):
2323
Image.open("Tests/images/input_bw_five_bands.fpx")

Tests/test_file_gribstub.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_load():
3232
with Image.open(TEST_FILE) as im:
3333

3434
# Act / Assert: stub cannot load without an implemented handler
35-
with pytest.raises(IOError):
35+
with pytest.raises(OSError):
3636
im.load()
3737

3838

@@ -42,5 +42,5 @@ def test_save(tmp_path):
4242
tmpfile = str(tmp_path / "temp.grib")
4343

4444
# Act / Assert: stub cannot save without an implemented handler
45-
with pytest.raises(IOError):
45+
with pytest.raises(OSError):
4646
im.save(tmpfile)

Tests/test_file_hdf5stub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_load():
3030
with Image.open(TEST_FILE) as im:
3131

3232
# Act / Assert: stub cannot load without an implemented handler
33-
with pytest.raises(IOError):
33+
with pytest.raises(OSError):
3434
im.load()
3535

3636

@@ -41,7 +41,7 @@ def test_save():
4141
dummy_filename = "dummy.filename"
4242

4343
# Act / Assert: stub cannot save without an implemented handler
44-
with pytest.raises(IOError):
44+
with pytest.raises(OSError):
4545
im.save(dummy_filename)
46-
with pytest.raises(IOError):
46+
with pytest.raises(OSError):
4747
Hdf5StubImagePlugin._save(im, dummy_fp, dummy_filename)

Tests/test_file_jpeg.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_large_icc_meta(self, tmp_path):
147147
with Image.open("Tests/images/icc_profile_big.jpg") as im:
148148
f = str(tmp_path / "temp.jpg")
149149
icc_profile = im.info["icc_profile"]
150-
# Should not raise IOError for image with icc larger than image size.
150+
# Should not raise OSError for image with icc larger than image size.
151151
im.save(
152152
f,
153153
format="JPEG",
@@ -379,14 +379,14 @@ def test_truncated_jpeg_should_read_all_the_data(self):
379379
ImageFile.LOAD_TRUNCATED_IMAGES = False
380380
assert im.getbbox() is not None
381381

382-
def test_truncated_jpeg_throws_IOError(self):
382+
def test_truncated_jpeg_throws_oserror(self):
383383
filename = "Tests/images/truncated_jpeg.jpg"
384384
with Image.open(filename) as im:
385-
with pytest.raises(IOError):
385+
with pytest.raises(OSError):
386386
im.load()
387387

388388
# Test that the error is raised if loaded a second time
389-
with pytest.raises(IOError):
389+
with pytest.raises(OSError):
390390
im.load()
391391

392392
def test_qtables(self, tmp_path):
@@ -552,7 +552,7 @@ def test_save_wrong_modes(self):
552552
out = BytesIO()
553553
for mode in ["LA", "La", "RGBA", "RGBa", "P"]:
554554
img = Image.new(mode, (20, 20))
555-
with pytest.raises(IOError):
555+
with pytest.raises(OSError):
556556
img.save(out, "JPEG")
557557

558558
def test_save_tiff_with_dpi(self, tmp_path):
@@ -702,7 +702,7 @@ def test_fd_leak(self, tmp_path):
702702
im = Image.open(tmpfile)
703703
fp = im.fp
704704
assert not fp.closed
705-
with pytest.raises(WindowsError):
705+
with pytest.raises(OSError):
706706
os.remove(tmpfile)
707707
im.load()
708708
assert fp.closed

Tests/test_file_jpeg2k.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_16bit_jp2_roundtrips():
218218

219219
def test_unbound_local():
220220
# prepatch, a malformed jp2 file could cause an UnboundLocalError exception.
221-
with pytest.raises(IOError):
221+
with pytest.raises(OSError):
222222
Image.open("Tests/images/unbound_variable.jp2")
223223

224224

0 commit comments

Comments
 (0)