Skip to content

Commit

Permalink
Fixed catching warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Oct 26, 2024
1 parent 64eed14 commit 413bbb3
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Tests/test_bmp_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def test_bad() -> None:
for f in get_files("b"):
# Assert that there is no unclosed file warning
with warnings.catch_warnings():
warnings.simplefilter("error")

try:
with Image.open(f) as im:
im.load()
Expand Down
4 changes: 4 additions & 0 deletions Tests/test_file_dcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ def open() -> None:

def test_closed_file() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

im = Image.open(TEST_FILE)
im.load()
im.close()


def test_context_manager() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with Image.open(TEST_FILE) as im:
im.load()

Expand Down
4 changes: 4 additions & 0 deletions Tests/test_file_fli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def open() -> None:

def test_closed_file() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

im = Image.open(static_test_file)
im.load()
im.close()
Expand All @@ -81,6 +83,8 @@ def test_seek_after_close() -> None:

def test_context_manager() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with Image.open(static_test_file) as im:
im.load()

Expand Down
4 changes: 4 additions & 0 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def open() -> None:

def test_closed_file() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

im = Image.open(TEST_GIF)
im.load()
im.close()
Expand All @@ -67,6 +69,8 @@ def test_seek_after_close() -> None:

def test_context_manager() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with Image.open(TEST_GIF) as im:
im.load()

Expand Down
2 changes: 2 additions & 0 deletions Tests/test_file_icns.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def test_sanity() -> None:
with Image.open(TEST_FILE) as im:
# Assert that there is no unclosed file warning
with warnings.catch_warnings():
warnings.simplefilter("error")

im.load()

assert im.mode == "RGBA"
Expand Down
4 changes: 4 additions & 0 deletions Tests/test_file_im.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ def open() -> None:

def test_closed_file() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

im = Image.open(TEST_IM)
im.load()
im.close()


def test_context_manager() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with Image.open(TEST_IM) as im:
im.load()

Expand Down
2 changes: 2 additions & 0 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ def test_exif_x_resolution(self, tmp_path: Path) -> None:

out = str(tmp_path / "out.jpg")
with warnings.catch_warnings():
warnings.simplefilter("error")

im.save(out, exif=exif)

with Image.open(out) as reloaded:
Expand Down
4 changes: 4 additions & 0 deletions Tests/test_file_mpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def open() -> None:

def test_closed_file() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

im = Image.open(test_files[0])
im.load()
im.close()
Expand All @@ -63,6 +65,8 @@ def test_seek_after_close() -> None:

def test_context_manager() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with Image.open(test_files[0]) as im:
im.load()

Expand Down
2 changes: 2 additions & 0 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ def test_load_verify(self) -> None:
with Image.open(TEST_PNG_FILE) as im:
# Assert that there is no unclosed file warning
with warnings.catch_warnings():
warnings.simplefilter("error")

im.verify()

with Image.open(TEST_PNG_FILE) as im:
Expand Down
4 changes: 4 additions & 0 deletions Tests/test_file_psd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ def open() -> None:

def test_closed_file() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

im = Image.open(test_file)
im.load()
im.close()


def test_context_manager() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with Image.open(test_file) as im:
im.load()

Expand Down
4 changes: 4 additions & 0 deletions Tests/test_file_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ def open() -> None:

def test_closed_file() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

im = Image.open(TEST_FILE)
im.load()
im.close()


def test_context_manager() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with Image.open(TEST_FILE) as im:
im.load()

Expand Down
4 changes: 4 additions & 0 deletions Tests/test_file_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ def test_unclosed_file() -> None:

def test_close() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

tar = TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg")
tar.close()


def test_contextmanager() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg"):
pass
4 changes: 4 additions & 0 deletions Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def open() -> None:

def test_closed_file(self) -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

im = Image.open("Tests/images/multipage.tiff")
im.load()
im.close()
Expand All @@ -88,6 +90,8 @@ def test_seek_after_close(self) -> None:

def test_context_manager(self) -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

with Image.open("Tests/images/multipage.tiff") as im:
im.load()

Expand Down
2 changes: 2 additions & 0 deletions Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def test_no_resource_warning(self, tmp_path: Path) -> None:
file_path = "Tests/images/hopper.webp"
with Image.open(file_path) as image:
with warnings.catch_warnings():
warnings.simplefilter("error")

image.save(tmp_path / "temp.webp")

def test_file_pointer_could_be_reused(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@ def test_no_resource_warning_on_save(self, tmp_path: Path) -> None:
# Act/Assert
with Image.open(test_file) as im:
with warnings.catch_warnings():
warnings.simplefilter("error")

im.save(temp_file)

def test_no_new_file_on_error(self, tmp_path: Path) -> None:
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_imageqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ def test_image(mode: str) -> None:

def test_closed_file() -> None:
with warnings.catch_warnings():
warnings.simplefilter("error")

ImageQt.ImageQt("Tests/images/hopper.gif")
2 changes: 2 additions & 0 deletions Tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,6 @@ def test_no_resource_warning_for_numpy_array() -> None:
with Image.open(test_file) as im:
# Act/Assert
with warnings.catch_warnings():
warnings.simplefilter("error")

array(im)

0 comments on commit 413bbb3

Please sign in to comment.