From 88b3265a9cb86ffd8a7c43c1afa8dae1b78cf035 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 14 Sep 2024 20:59:02 +1000 Subject: [PATCH] Lint: Run PT016 --- Tests/test_image.py | 15 +++++---------- Tests/test_imageshow.py | 2 +- pyproject.toml | 1 - 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index cf5b5a710cc..9b65041f4b4 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -1086,22 +1086,17 @@ def test_overrun(self, path: str) -> None: valgrind pytest -qq Tests/test_image.py::TestImage::test_overrun | grep decode.c """ with Image.open(os.path.join("Tests/images", path)) as im: - try: + with pytest.raises(OSError) as e: im.load() - pytest.fail() - except OSError as e: - buffer_overrun = str(e) == "buffer overrun when reading image file" - truncated = "image file is truncated" in str(e) + buffer_overrun = str(e.value) == "buffer overrun when reading image file" + truncated = "image file is truncated" in str(e.value) - assert buffer_overrun or truncated + assert buffer_overrun or truncated def test_fli_overrun2(self) -> None: 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) - pytest.fail() - except OSError as e: - assert str(e) == "buffer overrun when reading image file" def test_exit_fp(self) -> None: with Image.new("L", (1, 1)) as im: diff --git a/Tests/test_imageshow.py b/Tests/test_imageshow.py index a4f7e5cc5b4..67c32783fc5 100644 --- a/Tests/test_imageshow.py +++ b/Tests/test_imageshow.py @@ -115,7 +115,7 @@ def test_ipythonviewer() -> None: test_viewer = viewer break else: - pytest.fail() + pytest.fail("IPythonViewer not found") im = hopper() assert test_viewer.show(im) == 1 diff --git a/pyproject.toml b/pyproject.toml index 4042bd9ee20..228c344e864 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,7 +125,6 @@ lint.ignore = [ "PT007", # pytest-parametrize-values-wrong-type "PT011", # pytest-raises-too-broad "PT012", # pytest-raises-with-multiple-statements - "PT016", # pytest-fail-without-message "PT017", # pytest-assert-in-except "PYI026", # flake8-pyi: typing.TypeAlias added in Python 3.10 "PYI034", # flake8-pyi: typing.Self added in Python 3.11