Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/check_j2k_overflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
def test_j2k_overflow(tmp_path):
im = Image.new("RGBA", (1024, 131584))
target = str(tmp_path / "temp.jpc")
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(target)
2 changes: 1 addition & 1 deletion Tests/check_libtiff_segfault.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ def test_libtiff_segfault():
libtiff >= 4.0.0
"""

with pytest.raises(IOError):
with pytest.raises(OSError):
with Image.open(TEST_FILE) as im:
im.load()
4 changes: 2 additions & 2 deletions Tests/test_file_bufrstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_load():
with Image.open(TEST_FILE) as im:

# Act / Assert: stub cannot load without an implemented handler
with pytest.raises(IOError):
with pytest.raises(OSError):
im.load()


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

# Act / Assert: stub cannot save without an implemented handler
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(tmpfile)
4 changes: 2 additions & 2 deletions Tests/test_file_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_short_header():
def short_header():
Image.open(BytesIO(img_file[:119]))

with pytest.raises(IOError):
with pytest.raises(OSError):
short_header()


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

with pytest.raises(IOError):
with pytest.raises(OSError):
short_file()


Expand Down
6 changes: 3 additions & 3 deletions Tests/test_file_fitsstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_load():
with Image.open(TEST_FILE) as im:

# Act / Assert: stub cannot load without an implemented handler
with pytest.raises(IOError):
with pytest.raises(OSError):
im.load()


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

# Act / Assert: stub cannot save without an implemented handler
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(dummy_filename)
with pytest.raises(IOError):
with pytest.raises(OSError):
FitsStubImagePlugin._save(im, dummy_fp, dummy_filename)
2 changes: 1 addition & 1 deletion Tests/test_file_fpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def test_invalid_file():


def test_fpx_invalid_number_of_bands():
with pytest.raises(IOError, match="Invalid number of bands"):
with pytest.raises(OSError, match="Invalid number of bands"):
Image.open("Tests/images/input_bw_five_bands.fpx")
4 changes: 2 additions & 2 deletions Tests/test_file_gribstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_load():
with Image.open(TEST_FILE) as im:

# Act / Assert: stub cannot load without an implemented handler
with pytest.raises(IOError):
with pytest.raises(OSError):
im.load()


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

# Act / Assert: stub cannot save without an implemented handler
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(tmpfile)
6 changes: 3 additions & 3 deletions Tests/test_file_hdf5stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_load():
with Image.open(TEST_FILE) as im:

# Act / Assert: stub cannot load without an implemented handler
with pytest.raises(IOError):
with pytest.raises(OSError):
im.load()


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

# Act / Assert: stub cannot save without an implemented handler
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(dummy_filename)
with pytest.raises(IOError):
with pytest.raises(OSError):
Hdf5StubImagePlugin._save(im, dummy_fp, dummy_filename)
12 changes: 6 additions & 6 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_large_icc_meta(self, tmp_path):
with Image.open("Tests/images/icc_profile_big.jpg") as im:
f = str(tmp_path / "temp.jpg")
icc_profile = im.info["icc_profile"]
# Should not raise IOError for image with icc larger than image size.
# Should not raise OSError for image with icc larger than image size.
im.save(
f,
format="JPEG",
Expand Down Expand Up @@ -379,14 +379,14 @@ def test_truncated_jpeg_should_read_all_the_data(self):
ImageFile.LOAD_TRUNCATED_IMAGES = False
assert im.getbbox() is not None

def test_truncated_jpeg_throws_IOError(self):
def test_truncated_jpeg_throws_oserror(self):
filename = "Tests/images/truncated_jpeg.jpg"
with Image.open(filename) as im:
with pytest.raises(IOError):
with pytest.raises(OSError):
im.load()

# Test that the error is raised if loaded a second time
with pytest.raises(IOError):
with pytest.raises(OSError):
im.load()

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

def test_save_tiff_with_dpi(self, tmp_path):
Expand Down Expand Up @@ -702,7 +702,7 @@ def test_fd_leak(self, tmp_path):
im = Image.open(tmpfile)
fp = im.fp
assert not fp.closed
with pytest.raises(WindowsError):
with pytest.raises(OSError):
os.remove(tmpfile)
im.load()
assert fp.closed
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_16bit_jp2_roundtrips():

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


Expand Down
8 changes: 4 additions & 4 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,11 @@ def xtest_bw_compression_w_rgb(self, tmp_path):
im = hopper("RGB")
out = str(tmp_path / "temp.tif")

with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(out, compression="tiff_ccitt")
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(out, compression="group3")
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(out, compression="group4")

def test_fp_leak(self):
Expand Down Expand Up @@ -831,7 +831,7 @@ def test_sampleformat_not_corrupted(self):
def test_realloc_overflow(self):
TiffImagePlugin.READ_LIBTIFF = True
with Image.open("Tests/images/tiff_overflow_rows_per_strip.tif") as im:
with pytest.raises(IOError) as e:
with pytest.raises(OSError) as e:
im.load()

# Assert that the error code is IMAGING_CODEC_MEMORY
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_msp.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ def test_cannot_save_wrong_mode(tmp_path):
filename = str(tmp_path / "temp.msp")

# Act/Assert
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(filename)
8 changes: 4 additions & 4 deletions Tests/test_file_palm.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ def test_p_mode(tmp_path):
roundtrip(tmp_path, mode)


def test_l_ioerror(tmp_path):
def test_l_oserror(tmp_path):
# Arrange
mode = "L"

# Act / Assert
with pytest.raises(IOError):
with pytest.raises(OSError):
helper_save_as_palm(tmp_path, mode)


def test_rgb_ioerror(tmp_path):
def test_rgb_oserror(tmp_path):
# Arrange
mode = "RGB"

# Act / Assert
with pytest.raises(IOError):
with pytest.raises(OSError):
helper_save_as_palm(tmp_path, mode)
2 changes: 1 addition & 1 deletion Tests/test_file_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_pdf_open(tmp_path):
def test_pdf_append_fails_on_nonexistent_file():
im = hopper("RGB")
with tempfile.TemporaryDirectory() as temp_dir:
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(os.path.join(temp_dir, "nonexistent.pdf"), append=True)


Expand Down
12 changes: 6 additions & 6 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_broken(self):
# file was checked into Subversion as a text file.

test_file = "Tests/images/broken.png"
with pytest.raises(IOError):
with pytest.raises(OSError):
Image.open(test_file)

def test_bad_text(self):
Expand Down Expand Up @@ -334,7 +334,7 @@ def test_load_verify(self):
def test_verify_struct_error(self):
# Check open/load/verify exception (#1755)

# offsets to test, -10: breaks in i32() in read. (IOError)
# offsets to test, -10: breaks in i32() in read. (OSError)
# -13: breaks in crc, txt chunk.
# -14: malformed chunk

Expand All @@ -344,7 +344,7 @@ def test_verify_struct_error(self):

with Image.open(BytesIO(test_file)) as im:
assert im.fp is not None
with pytest.raises((IOError, SyntaxError)):
with pytest.raises((OSError, SyntaxError)):
im.verify()

def test_verify_ignores_crc_error(self):
Expand Down Expand Up @@ -463,7 +463,7 @@ def test_scary(self):
data = b"\x89" + fd.read()

pngfile = BytesIO(data)
with pytest.raises(IOError):
with pytest.raises(OSError):
Image.open(pngfile)

def test_trns_rgb(self):
Expand Down Expand Up @@ -575,13 +575,13 @@ def test_textual_chunks_after_idat(self):

# Raises a SyntaxError in load_end
with Image.open("Tests/images/broken_data_stream.png") as im:
with pytest.raises(IOError):
with pytest.raises(OSError):
assert isinstance(im.text, dict)

# Raises a UnicodeDecodeError in load_end
with Image.open("Tests/images/truncated_image.png") as im:
# The file is truncated
with pytest.raises(IOError):
with pytest.raises(OSError):
im.text()
ImageFile.LOAD_TRUNCATED_IMAGES = True
assert isinstance(im.text, dict)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_ppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_neg_ppm():
# has been removed. The default opener doesn't accept negative
# sizes.

with pytest.raises(IOError):
with pytest.raises(OSError):
Image.open("Tests/images/negative_size.ppm")


Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_psd.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ def test_combined_larger_than_size():

# If we instead take the 'size' of the extra data field as the source of truth,
# then the seek can't be negative
with pytest.raises(IOError):
with pytest.raises(OSError):
Image.open("Tests/images/combined_larger_than_size.psd")
2 changes: 1 addition & 1 deletion Tests/test_file_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_is_int_not_a_number():
def test_invalid_file():
invalid_file = "Tests/images/invalid.spider"

with pytest.raises(IOError):
with pytest.raises(OSError):
Image.open(invalid_file)


Expand Down
6 changes: 3 additions & 3 deletions Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_save_rgba(self, tmp_path):
def test_save_unsupported_mode(self, tmp_path):
im = hopper("HSV")
outfile = str(tmp_path / "temp.tif")
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(outfile)

def test_little_endian(self):
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_32bit_float(self):
assert im.getextrema() == (-3.140936851501465, 3.140684127807617)

def test_unknown_pixel_mode(self):
with pytest.raises(IOError):
with pytest.raises(OSError):
Image.open("Tests/images/hopper_unknown_pixel_mode.tif")

def test_n_frames(self):
Expand Down Expand Up @@ -614,7 +614,7 @@ def test_fd_leak(self, tmp_path):
im = Image.open(tmpfile)
fp = im.fp
assert not fp.closed
with pytest.raises(WindowsError):
with pytest.raises(OSError):
os.remove(tmpfile)
im.load()
assert fp.closed
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_unsupported(self):
WebPImagePlugin.SUPPORTED = False

file_path = "Tests/images/hopper.webp"
pytest.warns(UserWarning, lambda: pytest.raises(IOError, Image.open, file_path))
pytest.warns(UserWarning, lambda: pytest.raises(OSError, Image.open, file_path))

if HAVE_WEBP:
WebPImagePlugin.SUPPORTED = True
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_wmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ def test_save(tmp_path):

for ext in [".wmf", ".emf"]:
tmpfile = str(tmp_path / ("temp" + ext))
with pytest.raises(IOError):
with pytest.raises(OSError):
im.save(tmpfile)
4 changes: 2 additions & 2 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_image_modes_fail(self):
assert str(e.value) == "unrecognized image mode"

def test_exception_inheritance(self):
assert issubclass(UnidentifiedImageError, IOError)
assert issubclass(UnidentifiedImageError, OSError)

def test_sanity(self):

Expand Down Expand Up @@ -687,5 +687,5 @@ def test_encode_registry(self):
assert enc.args == ("RGB", "args", "extra")

def test_encode_registry_fail(self):
with pytest.raises(IOError):
with pytest.raises(OSError):
Image._getencoder("RGB", "DoesNotExist", ("args",), extra=("extra",))
Loading