Lint: Run PT016

This commit is contained in:
Andrew Murray 2024-09-14 20:59:02 +10:00
parent 586e6f86d7
commit 88b3265a9c
3 changed files with 6 additions and 12 deletions

View File

@ -1086,22 +1086,17 @@ class TestImage:
valgrind pytest -qq Tests/test_image.py::TestImage::test_overrun | grep decode.c valgrind pytest -qq Tests/test_image.py::TestImage::test_overrun | grep decode.c
""" """
with Image.open(os.path.join("Tests/images", path)) as im: with Image.open(os.path.join("Tests/images", path)) as im:
try: with pytest.raises(OSError) as e:
im.load() im.load()
pytest.fail() buffer_overrun = str(e.value) == "buffer overrun when reading image file"
except OSError as e: truncated = "image file is truncated" in str(e.value)
buffer_overrun = str(e) == "buffer overrun when reading image file"
truncated = "image file is truncated" in str(e)
assert buffer_overrun or truncated assert buffer_overrun or truncated
def test_fli_overrun2(self) -> None: def test_fli_overrun2(self) -> None:
with Image.open("Tests/images/fli_overrun2.bin") as im: with Image.open("Tests/images/fli_overrun2.bin") as im:
try: with pytest.raises(OSError, match="buffer overrun when reading image file"):
im.seek(1) im.seek(1)
pytest.fail()
except OSError as e:
assert str(e) == "buffer overrun when reading image file"
def test_exit_fp(self) -> None: def test_exit_fp(self) -> None:
with Image.new("L", (1, 1)) as im: with Image.new("L", (1, 1)) as im:

View File

@ -115,7 +115,7 @@ def test_ipythonviewer() -> None:
test_viewer = viewer test_viewer = viewer
break break
else: else:
pytest.fail() pytest.fail("IPythonViewer not found")
im = hopper() im = hopper()
assert test_viewer.show(im) == 1 assert test_viewer.show(im) == 1

View File

@ -125,7 +125,6 @@ lint.ignore = [
"PT007", # pytest-parametrize-values-wrong-type "PT007", # pytest-parametrize-values-wrong-type
"PT011", # pytest-raises-too-broad "PT011", # pytest-raises-too-broad
"PT012", # pytest-raises-with-multiple-statements "PT012", # pytest-raises-with-multiple-statements
"PT016", # pytest-fail-without-message
"PT017", # pytest-assert-in-except "PT017", # pytest-assert-in-except
"PYI026", # flake8-pyi: typing.TypeAlias added in Python 3.10 "PYI026", # flake8-pyi: typing.TypeAlias added in Python 3.10
"PYI034", # flake8-pyi: typing.Self added in Python 3.11 "PYI034", # flake8-pyi: typing.Self added in Python 3.11