Skip to content
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
5 changes: 2 additions & 3 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
4 changes: 3 additions & 1 deletion Tests/test_file_gimpgradient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import pytest

from PIL import GimpGradientFile, ImagePalette


Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_palm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_tiff_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 11 additions & 9 deletions Tests/test_image_entropy.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from __future__ import annotations

import pytest

from .helper import hopper


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)
2 changes: 1 addition & 1 deletion Tests/test_pdfparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down