Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Replace assert False with pytest.fail() #7546

Merged
merged 1 commit into from
Nov 12, 2023
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/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def assert_image_equal(a, b, msg=None):
except Exception:
pass

assert False, msg or "got different content"
pytest.fail(msg or "got different content")


def assert_image_equal_tofile(a, filename, msg=None, mode=None):
Expand Down
4 changes: 3 additions & 1 deletion Tests/test_file_iptc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
from io import BytesIO, StringIO

import pytest

from PIL import Image, IptcImagePlugin

from .helper import hopper
Expand Down Expand Up @@ -44,7 +46,7 @@
for tag in iptc.keys():
if tag[0] == 240:
return
assert False, "FotoStation tag not found"
pytest.fail("FotoStation tag not found")

Check warning on line 49 in Tests/test_file_iptc.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_file_iptc.py#L49

Added line #L49 was not covered by tests


def test_getiptcinfo_zero_padding():
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
while True:
marker = out.read(2)
if not marker:
assert False, "End of stream without PLT"
pytest.fail("End of stream without PLT")

Check warning on line 419 in Tests/test_file_jpeg2k.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_file_jpeg2k.py#L419

Added line #L419 was not covered by tests

jp2_boxid = _binary.i16be(marker)
if jp2_boxid == 0xFF4F:
Expand All @@ -426,7 +426,7 @@
# PLT
return
elif jp2_boxid == 0xFF93:
assert False, "SOD without finding PLT first"
pytest.fail("SOD without finding PLT first")

Check warning on line 429 in Tests/test_file_jpeg2k.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_file_jpeg2k.py#L429

Added line #L429 was not covered by tests

hdr = out.read(2)
length = _binary.i16be(hdr)
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@
with Image.open(os.path.join("Tests/images", path)) as im:
try:
im.load()
assert False
pytest.fail()

Check warning on line 1002 in Tests/test_image.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_image.py#L1002

Added line #L1002 was not covered by tests
except OSError as e:
buffer_overrun = str(e) == "buffer overrun when reading image file"
truncated = "image file is truncated" in str(e)
Expand All @@ -1010,7 +1010,7 @@
with Image.open("Tests/images/fli_overrun2.bin") as im:
try:
im.seek(1)
assert False
pytest.fail()

Check warning on line 1013 in Tests/test_image.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_image.py#L1013

Added line #L1013 was not covered by tests
except OSError as e:
assert str(e) == "buffer overrun when reading image file"

Expand Down
6 changes: 3 additions & 3 deletions Tests/test_image_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_reducing_gap_1(self, gradients_image, box, epsilon):
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=1.0
)

with pytest.raises(AssertionError):
with pytest.raises(pytest.fail.Exception):
assert_image_equal(ref, im)

assert_image_similar(ref, im, epsilon)
Expand All @@ -210,7 +210,7 @@ def test_reducing_gap_2(self, gradients_image, box, epsilon):
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=2.0
)

with pytest.raises(AssertionError):
with pytest.raises(pytest.fail.Exception):
assert_image_equal(ref, im)

assert_image_similar(ref, im, epsilon)
Expand All @@ -225,7 +225,7 @@ def test_reducing_gap_3(self, gradients_image, box, epsilon):
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=3.0
)

with pytest.raises(AssertionError):
with pytest.raises(pytest.fail.Exception):
assert_image_equal(ref, im)

assert_image_similar(ref, im, epsilon)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_image_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_reducing_gap_values():

ref = hopper()
ref.thumbnail((18, 18), Image.Resampling.BICUBIC, reducing_gap=None)
with pytest.raises(AssertionError):
with pytest.raises(pytest.fail.Exception):
assert_image_equal(ref, im)

assert_image_similar(ref, im, 3.5)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imageshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
test_viewer = viewer
break
else:
assert False
pytest.fail()

Check warning on line 88 in Tests/test_imageshow.py

View check run for this annotation

Codecov / codecov/patch

Tests/test_imageshow.py#L88

Added line #L88 was not covered by tests

im = hopper()
assert test_viewer.show(im) == 1