@@ -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,10 @@ def test_encoder_finish_none_error(
181164 """Save should raise an OSError if AvifEncoder.finish returns None"""
182165
183166 class _mock_avif :
167+ @classmethod
168+ def encoder_codec_available (cls ) -> bool :
169+ return True
170+
184171 class AvifEncoder :
185172 def __init__ (self , * args : Any ) -> None :
186173 pass
@@ -434,26 +421,6 @@ def test_encoder_range_invalid(self, tmp_path: Path) -> None:
434421 with pytest .raises (ValueError ):
435422 im .save (test_file , range = "foo" )
436423
437- @skip_unless_avif_encoder ("aom" )
438- def test_encoder_codec_param (self , tmp_path : Path ) -> None :
439- with Image .open (TEST_AVIF_FILE ) as im :
440- test_file = tmp_path / "temp.avif"
441- im .save (test_file , codec = "aom" )
442-
443- def test_encoder_codec_invalid (self , tmp_path : Path ) -> None :
444- with Image .open (TEST_AVIF_FILE ) as im :
445- test_file = tmp_path / "temp.avif"
446- with pytest .raises (ValueError ):
447- im .save (test_file , codec = "foo" )
448-
449- @skip_unless_avif_decoder ("dav1d" )
450- def test_decoder_codec_cannot_encode (self , tmp_path : Path ) -> None :
451- with Image .open (TEST_AVIF_FILE ) as im :
452- test_file = tmp_path / "temp.avif"
453- with pytest .raises (ValueError ):
454- im .save (test_file , codec = "dav1d" )
455-
456- @skip_unless_avif_encoder ("aom" )
457424 @pytest .mark .parametrize (
458425 "advanced" ,
459426 [
@@ -470,86 +437,30 @@ def test_encoder_advanced_codec_options(
470437 ) -> None :
471438 with Image .open (TEST_AVIF_FILE ) as im :
472439 ctrl_buf = BytesIO ()
473- im .save (ctrl_buf , "AVIF" , codec = "aom" )
440+ im .save (ctrl_buf , "AVIF" )
474441 test_buf = BytesIO ()
475442 im .save (
476443 test_buf ,
477444 "AVIF" ,
478- codec = "aom" ,
479445 advanced = advanced ,
480446 )
481447 assert ctrl_buf .getvalue () != test_buf .getvalue ()
482448
483- @skip_unless_avif_encoder ("aom" )
484449 @pytest .mark .parametrize ("advanced" , [{"foo" : "bar" }, {"foo" : 1234 }, 1234 ])
485450 def test_encoder_advanced_codec_options_invalid (
486451 self , tmp_path : Path , advanced : dict [str , str ] | int
487452 ) -> None :
488453 with Image .open (TEST_AVIF_FILE ) as im :
489454 test_file = tmp_path / "temp.avif"
490455 with pytest .raises (ValueError ):
491- im .save (test_file , codec = "aom" , advanced = advanced )
492-
493- @skip_unless_avif_decoder ("aom" )
494- def test_decoder_codec_param (self , monkeypatch : pytest .MonkeyPatch ) -> None :
495- monkeypatch .setattr (AvifImagePlugin , "DECODE_CODEC_CHOICE" , "aom" )
496-
497- with Image .open (TEST_AVIF_FILE ) as im :
498- assert im .size == (128 , 128 )
499-
500- @skip_unless_avif_encoder ("rav1e" )
501- def test_encoder_codec_cannot_decode (
502- self , monkeypatch : pytest .MonkeyPatch , tmp_path : Path
503- ) -> None :
504- monkeypatch .setattr (AvifImagePlugin , "DECODE_CODEC_CHOICE" , "rav1e" )
505-
506- with pytest .raises (ValueError ):
507- with Image .open (TEST_AVIF_FILE ):
508- pass
509-
510- def test_decoder_codec_invalid (self , monkeypatch : pytest .MonkeyPatch ) -> None :
511- monkeypatch .setattr (AvifImagePlugin , "DECODE_CODEC_CHOICE" , "foo" )
512-
513- with pytest .raises (ValueError ):
514- with Image .open (TEST_AVIF_FILE ):
515- pass
516-
517- @skip_unless_avif_encoder ("aom" )
518- def test_encoder_codec_available (self ) -> None :
519- assert _avif .encoder_codec_available ("aom" ) is True
520-
521- def test_encoder_codec_available_bad_params (self ) -> None :
522- with pytest .raises (TypeError ):
523- _avif .encoder_codec_available ()
524-
525- @skip_unless_avif_decoder ("dav1d" )
526- def test_encoder_codec_available_cannot_decode (self ) -> None :
527- assert _avif .encoder_codec_available ("dav1d" ) is False
528-
529- def test_encoder_codec_available_invalid (self ) -> None :
530- assert _avif .encoder_codec_available ("foo" ) is False
456+ im .save (test_file , advanced = advanced )
531457
532458 def test_encoder_quality_valueerror (self , tmp_path : Path ) -> None :
533459 with Image .open (TEST_AVIF_FILE ) as im :
534460 test_file = tmp_path / "temp.avif"
535461 with pytest .raises (ValueError ):
536462 im .save (test_file , quality = "invalid" )
537463
538- @skip_unless_avif_decoder ("aom" )
539- def test_decoder_codec_available (self ) -> None :
540- assert _avif .decoder_codec_available ("aom" ) is True
541-
542- def test_decoder_codec_available_bad_params (self ) -> None :
543- with pytest .raises (TypeError ):
544- _avif .decoder_codec_available ()
545-
546- @skip_unless_avif_encoder ("rav1e" )
547- def test_decoder_codec_available_cannot_decode (self ) -> None :
548- assert _avif .decoder_codec_available ("rav1e" ) is False
549-
550- def test_decoder_codec_available_invalid (self ) -> None :
551- assert _avif .decoder_codec_available ("foo" ) is False
552-
553464 def test_p_mode_transparency (self , tmp_path : Path ) -> None :
554465 im = Image .new ("P" , size = (64 , 64 ))
555466 draw = ImageDraw .Draw (im )
@@ -570,16 +481,10 @@ def test_decoder_strict_flags(self) -> None:
570481 with Image .open ("Tests/images/avif/hopper-missing-pixi.avif" ) as im :
571482 assert im .size == (128 , 128 )
572483
573- @skip_unless_avif_encoder ("aom" )
574484 @pytest .mark .parametrize ("speed" , [- 1 , 1 , 11 ])
575485 def test_aom_optimizations (self , tmp_path : Path , speed : int ) -> None :
576486 test_file = tmp_path / "temp.avif"
577- hopper ().save (test_file , codec = "aom" , speed = speed )
578-
579- @skip_unless_avif_encoder ("svt" )
580- def test_svt_optimizations (self , tmp_path : Path ) -> None :
581- test_file = tmp_path / "temp.avif"
582- hopper ().save (test_file , codec = "svt" , speed = 1 )
487+ hopper ().save (test_file , speed = speed )
583488
584489
585490@skip_unless_feature ("avif" )
0 commit comments