@@ -51,20 +51,6 @@ def roundtrip(im: ImageFile.ImageFile, **options: Any) -> ImageFile.ImageFile:
5151 return Image .open (out )
5252
5353
54- def skip_unless_avif_decoder (codec_name : str ) -> pytest .MarkDecorator :
55- reason = f"{ codec_name } decode not available"
56- return pytest .mark .skipif (
57- not HAVE_AVIF or not _avif .decoder_codec_available (codec_name ), reason = reason
58- )
59-
60-
61- def skip_unless_avif_encoder (codec_name : str ) -> pytest .MarkDecorator :
62- reason = f"{ codec_name } encode not available"
63- return pytest .mark .skipif (
64- not HAVE_AVIF or not _avif .encoder_codec_available (codec_name ), reason = reason
65- )
66-
67-
6854def is_docker_qemu () -> bool :
6955 try :
7056 init_proc_exe = os .readlink ("/proc/1/exe" )
@@ -99,15 +85,12 @@ def test_version(self) -> None:
9985 def test_codec_version (self ) -> None :
10086 assert AvifImagePlugin .get_codec_version ("unknown" ) is None
10187
102- for codec_name in ("aom" , "dav1d" , "rav1e" , "svt" ):
103- codec_version = AvifImagePlugin .get_codec_version (codec_name )
104- if _avif .decoder_codec_available (
105- codec_name
106- ) or _avif .encoder_codec_available (codec_name ):
107- assert codec_version is not None
108- assert re .search (r"^v?\d+\.\d+\.\d+(-([a-z\d])+)*$" , codec_version )
109- else :
110- assert codec_version is None
88+ codec_version = AvifImagePlugin .get_codec_version ("aom" )
89+ if _avif .decoder_codec_available () or _avif .encoder_codec_available ():
90+ assert codec_version is not None
91+ assert re .search (r"^v?\d+\.\d+\.\d+(-([a-z\d])+)*$" , codec_version )
92+ else :
93+ assert codec_version is None
11194
11295 def test_read (self ) -> None :
11396 """
@@ -181,6 +164,9 @@ def test_encoder_finish_none_error(
181164 """Save should raise an OSError if AvifEncoder.finish returns None"""
182165
183166 class _mock_avif :
167+ def encoder_codec_available (self ) -> None :
168+ return True
169+
184170 class AvifEncoder :
185171 def __init__ (self , * args : Any ) -> None :
186172 pass
@@ -433,26 +419,6 @@ def test_encoder_range_invalid(self, tmp_path: Path) -> None:
433419 with pytest .raises (ValueError ):
434420 im .save (test_file , range = "foo" )
435421
436- @skip_unless_avif_encoder ("aom" )
437- def test_encoder_codec_param (self , tmp_path : Path ) -> None :
438- with Image .open (TEST_AVIF_FILE ) as im :
439- test_file = tmp_path / "temp.avif"
440- im .save (test_file , codec = "aom" )
441-
442- def test_encoder_codec_invalid (self , tmp_path : Path ) -> None :
443- with Image .open (TEST_AVIF_FILE ) as im :
444- test_file = tmp_path / "temp.avif"
445- with pytest .raises (ValueError ):
446- im .save (test_file , codec = "foo" )
447-
448- @skip_unless_avif_decoder ("dav1d" )
449- def test_decoder_codec_cannot_encode (self , tmp_path : Path ) -> None :
450- with Image .open (TEST_AVIF_FILE ) as im :
451- test_file = tmp_path / "temp.avif"
452- with pytest .raises (ValueError ):
453- im .save (test_file , codec = "dav1d" )
454-
455- @skip_unless_avif_encoder ("aom" )
456422 @pytest .mark .parametrize (
457423 "advanced" ,
458424 [
@@ -469,86 +435,30 @@ def test_encoder_advanced_codec_options(
469435 ) -> None :
470436 with Image .open (TEST_AVIF_FILE ) as im :
471437 ctrl_buf = BytesIO ()
472- im .save (ctrl_buf , "AVIF" , codec = "aom" )
438+ im .save (ctrl_buf , "AVIF" )
473439 test_buf = BytesIO ()
474440 im .save (
475441 test_buf ,
476442 "AVIF" ,
477- codec = "aom" ,
478443 advanced = advanced ,
479444 )
480445 assert ctrl_buf .getvalue () != test_buf .getvalue ()
481446
482- @skip_unless_avif_encoder ("aom" )
483447 @pytest .mark .parametrize ("advanced" , [{"foo" : "bar" }, {"foo" : 1234 }, 1234 ])
484448 def test_encoder_advanced_codec_options_invalid (
485449 self , tmp_path : Path , advanced : dict [str , str ] | int
486450 ) -> None :
487451 with Image .open (TEST_AVIF_FILE ) as im :
488452 test_file = tmp_path / "temp.avif"
489453 with pytest .raises (ValueError ):
490- im .save (test_file , codec = "aom" , advanced = advanced )
491-
492- @skip_unless_avif_decoder ("aom" )
493- def test_decoder_codec_param (self , monkeypatch : pytest .MonkeyPatch ) -> None :
494- monkeypatch .setattr (AvifImagePlugin , "DECODE_CODEC_CHOICE" , "aom" )
495-
496- with Image .open (TEST_AVIF_FILE ) as im :
497- assert im .size == (128 , 128 )
498-
499- @skip_unless_avif_encoder ("rav1e" )
500- def test_encoder_codec_cannot_decode (
501- self , monkeypatch : pytest .MonkeyPatch , tmp_path : Path
502- ) -> None :
503- monkeypatch .setattr (AvifImagePlugin , "DECODE_CODEC_CHOICE" , "rav1e" )
504-
505- with pytest .raises (ValueError ):
506- with Image .open (TEST_AVIF_FILE ):
507- pass
508-
509- def test_decoder_codec_invalid (self , monkeypatch : pytest .MonkeyPatch ) -> None :
510- monkeypatch .setattr (AvifImagePlugin , "DECODE_CODEC_CHOICE" , "foo" )
511-
512- with pytest .raises (ValueError ):
513- with Image .open (TEST_AVIF_FILE ):
514- pass
515-
516- @skip_unless_avif_encoder ("aom" )
517- def test_encoder_codec_available (self ) -> None :
518- assert _avif .encoder_codec_available ("aom" ) is True
519-
520- def test_encoder_codec_available_bad_params (self ) -> None :
521- with pytest .raises (TypeError ):
522- _avif .encoder_codec_available ()
523-
524- @skip_unless_avif_decoder ("dav1d" )
525- def test_encoder_codec_available_cannot_decode (self ) -> None :
526- assert _avif .encoder_codec_available ("dav1d" ) is False
527-
528- def test_encoder_codec_available_invalid (self ) -> None :
529- assert _avif .encoder_codec_available ("foo" ) is False
454+ im .save (test_file , advanced = advanced )
530455
531456 def test_encoder_quality_valueerror (self , tmp_path : Path ) -> None :
532457 with Image .open (TEST_AVIF_FILE ) as im :
533458 test_file = tmp_path / "temp.avif"
534459 with pytest .raises (ValueError ):
535460 im .save (test_file , quality = "invalid" )
536461
537- @skip_unless_avif_decoder ("aom" )
538- def test_decoder_codec_available (self ) -> None :
539- assert _avif .decoder_codec_available ("aom" ) is True
540-
541- def test_decoder_codec_available_bad_params (self ) -> None :
542- with pytest .raises (TypeError ):
543- _avif .decoder_codec_available ()
544-
545- @skip_unless_avif_encoder ("rav1e" )
546- def test_decoder_codec_available_cannot_decode (self ) -> None :
547- assert _avif .decoder_codec_available ("rav1e" ) is False
548-
549- def test_decoder_codec_available_invalid (self ) -> None :
550- assert _avif .decoder_codec_available ("foo" ) is False
551-
552462 def test_p_mode_transparency (self , tmp_path : Path ) -> None :
553463 im = Image .new ("P" , size = (64 , 64 ))
554464 draw = ImageDraw .Draw (im )
@@ -569,16 +479,10 @@ def test_decoder_strict_flags(self) -> None:
569479 with Image .open ("Tests/images/avif/hopper-missing-pixi.avif" ) as im :
570480 assert im .size == (128 , 128 )
571481
572- @skip_unless_avif_encoder ("aom" )
573482 @pytest .mark .parametrize ("speed" , [- 1 , 1 , 11 ])
574483 def test_aom_optimizations (self , tmp_path : Path , speed : int ) -> None :
575484 test_file = tmp_path / "temp.avif"
576- hopper ().save (test_file , codec = "aom" , speed = speed )
577-
578- @skip_unless_avif_encoder ("svt" )
579- def test_svt_optimizations (self , tmp_path : Path ) -> None :
580- test_file = tmp_path / "temp.avif"
581- hopper ().save (test_file , codec = "svt" , speed = 1 )
485+ hopper ().save (test_file , speed = speed )
582486
583487
584488@skip_unless_feature ("avif" )
0 commit comments