mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-24 07:40:32 +03:00
Merge pull request #7546 from hugovk/pytest-fail
Tests: Replace `assert False` with `pytest.fail()`
This commit is contained in:
commit
25cc5afbb1
|
@ -95,7 +95,7 @@ def assert_image_equal(a, b, msg=None):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
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):
|
def assert_image_equal_tofile(a, filename, msg=None, mode=None):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import sys
|
import sys
|
||||||
from io import BytesIO, StringIO
|
from io import BytesIO, StringIO
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from PIL import Image, IptcImagePlugin
|
from PIL import Image, IptcImagePlugin
|
||||||
|
|
||||||
from .helper import hopper
|
from .helper import hopper
|
||||||
|
@ -44,7 +46,7 @@ def test_getiptcinfo_fotostation():
|
||||||
for tag in iptc.keys():
|
for tag in iptc.keys():
|
||||||
if tag[0] == 240:
|
if tag[0] == 240:
|
||||||
return
|
return
|
||||||
assert False, "FotoStation tag not found"
|
pytest.fail("FotoStation tag not found")
|
||||||
|
|
||||||
|
|
||||||
def test_getiptcinfo_zero_padding():
|
def test_getiptcinfo_zero_padding():
|
||||||
|
|
|
@ -416,7 +416,7 @@ def test_plt_marker():
|
||||||
while True:
|
while True:
|
||||||
marker = out.read(2)
|
marker = out.read(2)
|
||||||
if not marker:
|
if not marker:
|
||||||
assert False, "End of stream without PLT"
|
pytest.fail("End of stream without PLT")
|
||||||
|
|
||||||
jp2_boxid = _binary.i16be(marker)
|
jp2_boxid = _binary.i16be(marker)
|
||||||
if jp2_boxid == 0xFF4F:
|
if jp2_boxid == 0xFF4F:
|
||||||
|
@ -426,7 +426,7 @@ def test_plt_marker():
|
||||||
# PLT
|
# PLT
|
||||||
return
|
return
|
||||||
elif jp2_boxid == 0xFF93:
|
elif jp2_boxid == 0xFF93:
|
||||||
assert False, "SOD without finding PLT first"
|
pytest.fail("SOD without finding PLT first")
|
||||||
|
|
||||||
hdr = out.read(2)
|
hdr = out.read(2)
|
||||||
length = _binary.i16be(hdr)
|
length = _binary.i16be(hdr)
|
||||||
|
|
|
@ -999,7 +999,7 @@ class TestImage:
|
||||||
with Image.open(os.path.join("Tests/images", path)) as im:
|
with Image.open(os.path.join("Tests/images", path)) as im:
|
||||||
try:
|
try:
|
||||||
im.load()
|
im.load()
|
||||||
assert False
|
pytest.fail()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
buffer_overrun = str(e) == "buffer overrun when reading image file"
|
buffer_overrun = str(e) == "buffer overrun when reading image file"
|
||||||
truncated = "image file is truncated" in str(e)
|
truncated = "image file is truncated" in str(e)
|
||||||
|
@ -1010,7 +1010,7 @@ class TestImage:
|
||||||
with Image.open("Tests/images/fli_overrun2.bin") as im:
|
with Image.open("Tests/images/fli_overrun2.bin") as im:
|
||||||
try:
|
try:
|
||||||
im.seek(1)
|
im.seek(1)
|
||||||
assert False
|
pytest.fail()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
assert str(e) == "buffer overrun when reading image file"
|
assert str(e) == "buffer overrun when reading image file"
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,7 @@ class TestReducingGapResize:
|
||||||
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=1.0
|
(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_equal(ref, im)
|
||||||
|
|
||||||
assert_image_similar(ref, im, epsilon)
|
assert_image_similar(ref, im, epsilon)
|
||||||
|
@ -210,7 +210,7 @@ class TestReducingGapResize:
|
||||||
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=2.0
|
(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_equal(ref, im)
|
||||||
|
|
||||||
assert_image_similar(ref, im, epsilon)
|
assert_image_similar(ref, im, epsilon)
|
||||||
|
@ -225,7 +225,7 @@ class TestReducingGapResize:
|
||||||
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=3.0
|
(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_equal(ref, im)
|
||||||
|
|
||||||
assert_image_similar(ref, im, epsilon)
|
assert_image_similar(ref, im, epsilon)
|
||||||
|
|
|
@ -147,7 +147,7 @@ def test_reducing_gap_values():
|
||||||
|
|
||||||
ref = hopper()
|
ref = hopper()
|
||||||
ref.thumbnail((18, 18), Image.Resampling.BICUBIC, reducing_gap=None)
|
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_equal(ref, im)
|
||||||
|
|
||||||
assert_image_similar(ref, im, 3.5)
|
assert_image_similar(ref, im, 3.5)
|
||||||
|
|
|
@ -85,7 +85,7 @@ def test_ipythonviewer():
|
||||||
test_viewer = viewer
|
test_viewer = viewer
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
assert False
|
pytest.fail()
|
||||||
|
|
||||||
im = hopper()
|
im = hopper()
|
||||||
assert test_viewer.show(im) == 1
|
assert test_viewer.show(im) == 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user