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
9 changes: 3 additions & 6 deletions Tests/test_bmp_reference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

import pytest
import warnings

from PIL import Image

Expand All @@ -20,16 +19,14 @@ def test_bad():
either"""
for f in get_files("b"):

with pytest.warns(None) as record:
# Assert that there is no unclosed file warning
with warnings.catch_warnings():
try:
with Image.open(f) as im:
im.load()
except Exception: # as msg:
pass

# Assert that there is no unclosed file warning
assert not record


def test_questionable():
"""These shouldn't crash/dos, but it's not well defined that these
Expand Down
10 changes: 4 additions & 6 deletions Tests/test_file_dcx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

from PIL import DcxImagePlugin, Image
Expand Down Expand Up @@ -31,21 +33,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(TEST_FILE)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(TEST_FILE) as im:
im.load()

assert not record


def test_invalid_file():
with open("Tests/images/flower.jpg", "rb") as fp:
Expand Down
10 changes: 4 additions & 6 deletions Tests/test_file_fli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

from PIL import FliImagePlugin, Image
Expand Down Expand Up @@ -38,21 +40,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(static_test_file)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(static_test_file) as im:
im.load()

assert not record


def test_tell():
# Arrange
Expand Down
9 changes: 3 additions & 6 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from io import BytesIO

import pytest
Expand Down Expand Up @@ -39,21 +40,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(TEST_GIF)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(TEST_GIF) as im:
im.load()

assert not record


def test_invalid_file():
invalid_file = "Tests/images/flower.jpg"
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_icns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import os
import warnings

import pytest

Expand All @@ -19,9 +20,8 @@ def test_sanity():
with Image.open(TEST_FILE) as im:

# Assert that there is no unclosed file warning
with pytest.warns(None) as record:
with warnings.catch_warnings():
im.load()
assert not record

assert im.mode == "RGBA"
assert im.size == (1024, 1024)
Expand Down
9 changes: 3 additions & 6 deletions Tests/test_file_im.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import filecmp
import warnings

import pytest

Expand Down Expand Up @@ -35,21 +36,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(TEST_IM)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(TEST_IM) as im:
im.load()

assert not record


def test_tell():
# Arrange
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
import warnings
from io import BytesIO

import pytest
Expand Down Expand Up @@ -756,9 +757,8 @@ def test_exif_x_resolution(self, tmp_path):
assert exif[282] == 180

out = str(tmp_path / "out.jpg")
with pytest.warns(None) as record:
with warnings.catch_warnings():
im.save(out, exif=exif)
assert not record

with Image.open(out) as reloaded:
assert reloaded.getexif()[282] == 180
Expand Down
9 changes: 3 additions & 6 deletions Tests/test_file_mpo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from io import BytesIO

import pytest
Expand Down Expand Up @@ -41,21 +42,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(test_files[0])
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(test_files[0]) as im:
im.load()

assert not record


def test_app():
for test_file in test_files:
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import sys
import warnings
import zlib
from io import BytesIO

Expand Down Expand Up @@ -331,9 +332,8 @@ def test_load_verify(self):

with Image.open(TEST_PNG_FILE) as im:
# Assert that there is no unclosed file warning
with pytest.warns(None) as record:
with warnings.catch_warnings():
im.verify()
assert not record

with Image.open(TEST_PNG_FILE) as im:
im.load()
Expand Down
10 changes: 4 additions & 6 deletions Tests/test_file_psd.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

from PIL import Image, PsdImagePlugin
Expand Down Expand Up @@ -29,21 +31,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(test_file)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(test_file) as im:
im.load()

assert not record


def test_invalid_file():
invalid_file = "Tests/images/flower.jpg"
Expand Down
9 changes: 3 additions & 6 deletions Tests/test_file_spider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tempfile
import warnings
from io import BytesIO

import pytest
Expand Down Expand Up @@ -28,21 +29,17 @@ def open():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open(TEST_FILE)
im.load()
im.close()

assert not record


def test_context_manager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open(TEST_FILE) as im:
im.load()

assert not record


def test_save(tmp_path):
# Arrange
Expand Down
10 changes: 4 additions & 6 deletions Tests/test_file_tar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

from PIL import Image, TarIO, features
Expand Down Expand Up @@ -31,16 +33,12 @@ def open():


def test_close():
with pytest.warns(None) as record:
with warnings.catch_warnings():
tar = TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg")
tar.close()

assert not record


def test_contextmanager():
with pytest.warns(None) as record:
with warnings.catch_warnings():
with TarIO.TarIO(TEST_TAR_FILE, "hopper.jpg"):
pass

assert not record
9 changes: 3 additions & 6 deletions Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import warnings
from io import BytesIO

import pytest
Expand Down Expand Up @@ -64,20 +65,16 @@ def open():
pytest.warns(ResourceWarning, open)

def test_closed_file(self):
with pytest.warns(None) as record:
with warnings.catch_warnings():
im = Image.open("Tests/images/multipage.tiff")
im.load()
im.close()

assert not record

def test_context_manager(self):
with pytest.warns(None) as record:
with warnings.catch_warnings():
with Image.open("Tests/images/multipage.tiff") as im:
im.load()

assert not record

def test_mac_tiff(self):
# Read RGBa images from macOS [@PIL136]

Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_webp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import io
import re
import sys
import warnings

import pytest

Expand Down Expand Up @@ -161,9 +162,8 @@ def test_no_resource_warning(self, tmp_path):
file_path = "Tests/images/hopper.webp"
with Image.open(file_path) as image:
temp_file = str(tmp_path / "temp.webp")
with pytest.warns(None) as record:
with warnings.catch_warnings():
image.save(temp_file)
assert not record

def test_file_pointer_could_be_reused(self):
file_path = "Tests/images/hopper.webp"
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import sys
import tempfile
import warnings

import pytest

Expand Down Expand Up @@ -648,9 +649,8 @@ def test_no_resource_warning_on_save(self, tmp_path):

# Act/Assert
with Image.open(test_file) as im:
with pytest.warns(None) as record:
with warnings.catch_warnings():
im.save(temp_file)
assert not record

def test_load_on_nonexclusive_multiframe(self):
with open("Tests/images/frozenpond.mpo", "rb") as fp:
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_imageqt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

from PIL import ImageQt
Expand Down Expand Up @@ -56,7 +58,5 @@ def test_image():


def test_closed_file():
with pytest.warns(None) as record:
with warnings.catch_warnings():
ImageQt.ImageQt("Tests/images/hopper.gif")

assert not record
Loading