diff --git a/Tests/test_file_avif.py b/Tests/test_file_avif.py index 8dc00849097..5f0d72d3707 100644 --- a/Tests/test_file_avif.py +++ b/Tests/test_file_avif.py @@ -4,7 +4,7 @@ import os import re import warnings -from collections.abc import Generator +from collections.abc import Generator, Sequence from contextlib import contextmanager from io import BytesIO from pathlib import Path @@ -289,7 +289,8 @@ def test_exif(self) -> None: exif = im.getexif() assert exif[274] == 3 - @pytest.mark.parametrize("use_bytes, orientation", [(True, 1), (False, 2)]) + @pytest.mark.parametrize("use_bytes", [True, False]) + @pytest.mark.parametrize("orientation", [1, 2]) def test_exif_save( self, tmp_path: Path, @@ -393,7 +394,7 @@ def test_seek(self) -> None: with pytest.raises(EOFError): im.seek(1) - @pytest.mark.parametrize("subsampling", ["4:4:4", "4:2:2", "4:0:0"]) + @pytest.mark.parametrize("subsampling", ["4:4:4", "4:2:2", "4:2:0", "4:0:0"]) def test_encoder_subsampling(self, tmp_path: Path, subsampling: str) -> None: with Image.open(TEST_AVIF_FILE) as im: test_file = str(tmp_path / "temp.avif") @@ -405,10 +406,11 @@ def test_encoder_subsampling_invalid(self, tmp_path: Path) -> None: with pytest.raises(ValueError): im.save(test_file, subsampling="foo") - def test_encoder_range(self, tmp_path: Path) -> None: + @pytest.mark.parametrize("value", ["full", "limited"]) + def test_encoder_range(self, tmp_path: Path, value: str) -> None: with Image.open(TEST_AVIF_FILE) as im: test_file = str(tmp_path / "temp.avif") - im.save(test_file, range="limited") + im.save(test_file, range=value) def test_encoder_range_invalid(self, tmp_path: Path) -> None: with Image.open(TEST_AVIF_FILE) as im: @@ -444,10 +446,11 @@ def test_decoder_codec_cannot_encode(self, tmp_path: Path) -> None: "enable-chroma-deltaq": "1", }, (("aq-mode", "1"), ("enable-chroma-deltaq", "1")), + [("aq-mode", "1"), ("enable-chroma-deltaq", "1")], ], ) def test_encoder_advanced_codec_options( - self, advanced: dict[str, str] | tuple[tuple[str, str], ...] + self, advanced: dict[str, str] | Sequence[tuple[str, str]] ) -> None: with Image.open(TEST_AVIF_FILE) as im: ctrl_buf = BytesIO() @@ -587,24 +590,25 @@ def test_n_frames(self) -> None: def test_write_animation_P(self, tmp_path: Path) -> None: """ Convert an animated GIF to animated AVIF, then compare the frame - count, and first and second-to-last frames to ensure they're visually similar. + count, and ensure the frames are visually similar to the originals. """ - with Image.open("Tests/images/avif/star.gif") as orig: - assert orig.n_frames > 1 + with Image.open("Tests/images/avif/star.gif") as original: + assert original.n_frames > 1 temp_file = str(tmp_path / "temp.avif") - orig.save(temp_file, save_all=True) + original.save(temp_file, save_all=True) with Image.open(temp_file) as im: - assert im.n_frames == orig.n_frames + assert im.n_frames == original.n_frames # Compare first frame in P mode to frame from original GIF - assert_image_similar(im, orig.convert("RGBA"), 2) + assert_image_similar(im, original.convert("RGBA"), 2) - # Compare second-to-last frame in RGBA mode to frame from original GIF - orig.seek(orig.n_frames - 2) - im.seek(im.n_frames - 2) - assert_image_similar(im, orig, 2.54) + # Compare later frames in RGBA mode to frames from original GIF + for frame in range(1, original.n_frames): + original.seek(frame) + im.seek(frame) + assert_image_similar(im, original, 2.54) def test_write_animation_RGBA(self, tmp_path: Path) -> None: """