diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 52997e694c1..d5746992933 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -422,12 +422,11 @@ def test_seek() -> None: with Image.open("Tests/images/dispose_none.gif") as img: assert isinstance(img, GifImagePlugin.GifImageFile) frame_count = 0 - try: + with pytest.raises(EOFError): while True: frame_count += 1 img.seek(img.tell() + 1) - except EOFError: - assert frame_count == 5 + assert frame_count == 5 img.seek(0) with pytest.raises(ValueError, match="cannot seek to frame 2"): diff --git a/Tests/test_file_gimpgradient.py b/Tests/test_file_gimpgradient.py index 006ee952d43..6e032df4021 100644 --- a/Tests/test_file_gimpgradient.py +++ b/Tests/test_file_gimpgradient.py @@ -1,5 +1,7 @@ from __future__ import annotations +import pytest + from PIL import GimpGradientFile, ImagePalette @@ -84,7 +86,7 @@ def test_sphere_increasing() -> None: ret = GimpGradientFile.sphere_increasing(middle, pos) # Assert - assert round(abs(ret - 0.9682458365518543), 7) == 0 + assert ret == pytest.approx(0.9682458365518543) def test_sphere_decreasing() -> None: diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index c9849a056a3..d6d7be9c898 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -321,7 +321,7 @@ def check_tags( and libtiff ): # libtiff does not support real RATIONALS - assert round(abs(float(reloaded_value) - float(value)), 7) == 0 + assert reloaded_value == pytest.approx(value) continue assert reloaded_value == value diff --git a/Tests/test_file_palm.py b/Tests/test_file_palm.py index 58208ba99fa..bc6debeffe7 100644 --- a/Tests/test_file_palm.py +++ b/Tests/test_file_palm.py @@ -36,7 +36,7 @@ def open_with_magick(magick: list[str], tmp_path: Path, f: str) -> Image.Image: def roundtrip(tmp_path: Path, mode: str) -> None: magick = magick_command() if not magick: - return + pytest.skip("ImageMagick not available") im = hopper(mode) outfile = str(tmp_path / "temp.palm") diff --git a/Tests/test_file_tiff_metadata.py b/Tests/test_file_tiff_metadata.py index a9a367f88c6..3decb74a5eb 100644 --- a/Tests/test_file_tiff_metadata.py +++ b/Tests/test_file_tiff_metadata.py @@ -72,9 +72,9 @@ def test_rt_metadata(tmp_path: Path) -> None: assert loaded.tag_v2[ImageDescription] == reloaded_text_data loaded_float = loaded.tag[TAG_IDS["RollAngle"]][0] - assert round(abs(loaded_float - float_data), 5) == 0 + assert loaded_float == pytest.approx(float_data) loaded_double = loaded.tag[TAG_IDS["YawAngle"]][0] - assert round(abs(loaded_double - double_data), 7) == 0 + assert loaded_double == pytest.approx(double_data) # check with 2 element ImageJMetaDataByteCounts, issue #2006 diff --git a/Tests/test_image_entropy.py b/Tests/test_image_entropy.py index c1dbb879b0b..f6beb592c81 100644 --- a/Tests/test_image_entropy.py +++ b/Tests/test_image_entropy.py @@ -1,5 +1,7 @@ from __future__ import annotations +import pytest + from .helper import hopper @@ -7,12 +9,12 @@ def test_entropy() -> None: def entropy(mode: str) -> float: return hopper(mode).entropy() - assert round(abs(entropy("1") - 0.9138803254693582), 7) == 0 - assert round(abs(entropy("L") - 7.063008716585465), 7) == 0 - assert round(abs(entropy("I") - 7.063008716585465), 7) == 0 - assert round(abs(entropy("F") - 7.063008716585465), 7) == 0 - assert round(abs(entropy("P") - 5.082506854662517), 7) == 0 - assert round(abs(entropy("RGB") - 8.821286587714319), 7) == 0 - assert round(abs(entropy("RGBA") - 7.42724306524488), 7) == 0 - assert round(abs(entropy("CMYK") - 7.4272430652448795), 7) == 0 - assert round(abs(entropy("YCbCr") - 7.698360534903628), 7) == 0 + assert entropy("1") == pytest.approx(0.9138803254693582) + assert entropy("L") == pytest.approx(7.063008716585465) + assert entropy("I") == pytest.approx(7.063008716585465) + assert entropy("F") == pytest.approx(7.063008716585465) + assert entropy("P") == pytest.approx(5.082506854662517) + assert entropy("RGB") == pytest.approx(8.821286587714319) + assert entropy("RGBA") == pytest.approx(7.42724306524488) + assert entropy("CMYK") == pytest.approx(7.4272430652448795) + assert entropy("YCbCr") == pytest.approx(7.698360534903628) diff --git a/Tests/test_pdfparser.py b/Tests/test_pdfparser.py index 4c522eb7a50..5f89205f725 100644 --- a/Tests/test_pdfparser.py +++ b/Tests/test_pdfparser.py @@ -62,7 +62,7 @@ def test_parsing() -> None: assert PdfParser.get_value(b"(\\53a)", 0) == (b"\x2ba", 6) assert PdfParser.get_value(b"(\\1111)", 0) == (b"\x491", 7) assert PdfParser.get_value(b" 123 (", 0) == (123, 4) - assert round(abs(PdfParser.get_value(b" 123.4 %", 0)[0] - 123.4), 7) == 0 + assert PdfParser.get_value(b" 123.4 %", 0)[0] == pytest.approx(123.4) assert PdfParser.get_value(b" 123.4 %", 0)[1] == 6 with pytest.raises(PdfFormatError): PdfParser.get_value(b"]", 0)