Skip to content

Commit 1857bf5

Browse files
authored
Merge pull request #5259 from radarhere/warns
2 parents 53318fb + 4a0569e commit 1857bf5

16 files changed

Lines changed: 54 additions & 44 deletions

Tests/test_bmp_reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def test_bad():
2020
either"""
2121
for f in get_files("b"):
2222

23-
def open(f):
23+
with pytest.warns(None) as record:
2424
try:
2525
with Image.open(f) as im:
2626
im.load()
2727
except Exception: # as msg:
2828
pass
2929

3030
# Assert that there is no unclosed file warning
31-
pytest.warns(None, open, f)
31+
assert not record
3232

3333

3434
def test_questionable():

Tests/test_file_dcx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ def open():
3131

3232

3333
def test_closed_file():
34-
def open():
34+
with pytest.warns(None) as record:
3535
im = Image.open(TEST_FILE)
3636
im.load()
3737
im.close()
3838

39-
pytest.warns(None, open)
39+
assert not record
4040

4141

4242
def test_context_manager():
43-
def open():
43+
with pytest.warns(None) as record:
4444
with Image.open(TEST_FILE) as im:
4545
im.load()
4646

47-
pytest.warns(None, open)
47+
assert not record
4848

4949

5050
def test_invalid_file():

Tests/test_file_fli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ def open():
3838

3939

4040
def test_closed_file():
41-
def open():
41+
with pytest.warns(None) as record:
4242
im = Image.open(static_test_file)
4343
im.load()
4444
im.close()
4545

46-
pytest.warns(None, open)
46+
assert not record
4747

4848

4949
def test_context_manager():
50-
def open():
50+
with pytest.warns(None) as record:
5151
with Image.open(static_test_file) as im:
5252
im.load()
5353

54-
pytest.warns(None, open)
54+
assert not record
5555

5656

5757
def test_tell():

Tests/test_file_gif.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ def open():
3838

3939

4040
def test_closed_file():
41-
def open():
41+
with pytest.warns(None) as record:
4242
im = Image.open(TEST_GIF)
4343
im.load()
4444
im.close()
4545

46-
pytest.warns(None, open)
46+
assert not record
4747

4848

4949
def test_context_manager():
50-
def open():
50+
with pytest.warns(None) as record:
5151
with Image.open(TEST_GIF) as im:
5252
im.load()
5353

54-
pytest.warns(None, open)
54+
assert not record
5555

5656

5757
def test_invalid_file():

Tests/test_file_icns.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def test_sanity():
1919
with Image.open(TEST_FILE) as im:
2020

2121
# Assert that there is no unclosed file warning
22-
pytest.warns(None, im.load)
22+
with pytest.warns(None) as record:
23+
im.load()
24+
assert not record
2325

2426
assert im.mode == "RGBA"
2527
assert im.size == (1024, 1024)

Tests/test_file_im.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ def open():
3535

3636

3737
def test_closed_file():
38-
def open():
38+
with pytest.warns(None) as record:
3939
im = Image.open(TEST_IM)
4040
im.load()
4141
im.close()
4242

43-
pytest.warns(None, open)
43+
assert not record
4444

4545

4646
def test_context_manager():
47-
def open():
47+
with pytest.warns(None) as record:
4848
with Image.open(TEST_IM) as im:
4949
im.load()
5050

51-
pytest.warns(None, open)
51+
assert not record
5252

5353

5454
def test_tell():

Tests/test_file_jpeg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def test_exif_x_resolution(self, tmp_path):
733733
out = str(tmp_path / "out.jpg")
734734
with pytest.warns(None) as record:
735735
im.save(out, exif=exif)
736-
assert len(record) == 0
736+
assert not record
737737

738738
with Image.open(out) as reloaded:
739739
assert reloaded.getexif()[282] == 180

Tests/test_file_mpo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ def open():
4141

4242

4343
def test_closed_file():
44-
def open():
44+
with pytest.warns(None) as record:
4545
im = Image.open(test_files[0])
4646
im.load()
4747
im.close()
4848

49-
pytest.warns(None, open)
49+
assert not record
5050

5151

5252
def test_context_manager():
53-
def open():
53+
with pytest.warns(None) as record:
5454
with Image.open(test_files[0]) as im:
5555
im.load()
5656

57-
pytest.warns(None, open)
57+
assert not record
5858

5959

6060
def test_app():

Tests/test_file_png.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ def test_load_verify(self):
325325

326326
with Image.open(TEST_PNG_FILE) as im:
327327
# Assert that there is no unclosed file warning
328-
pytest.warns(None, im.verify)
328+
with pytest.warns(None) as record:
329+
im.verify()
330+
assert not record
329331

330332
with Image.open(TEST_PNG_FILE) as im:
331333
im.load()

Tests/test_file_psd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ def open():
2929

3030

3131
def test_closed_file():
32-
def open():
32+
with pytest.warns(None) as record:
3333
im = Image.open(test_file)
3434
im.load()
3535
im.close()
3636

37-
pytest.warns(None, open)
37+
assert not record
3838

3939

4040
def test_context_manager():
41-
def open():
41+
with pytest.warns(None) as record:
4242
with Image.open(test_file) as im:
4343
im.load()
4444

45-
pytest.warns(None, open)
45+
assert not record
4646

4747

4848
def test_invalid_file():

0 commit comments

Comments
 (0)