Skip to content

Commit

Permalink
Test further scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 1, 2025
1 parent 81f085a commit f9ca602
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Tests/test_file_avif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
"""
Expand Down

0 comments on commit f9ca602

Please sign in to comment.