@@ -70,8 +70,7 @@ def is_docker_qemu() -> bool:
7070 init_proc_exe = os .readlink ("/proc/1/exe" )
7171 except (FileNotFoundError , PermissionError ):
7272 return False
73- else :
74- return "qemu" in init_proc_exe
73+ return "qemu" in init_proc_exe
7574
7675
7776class TestUnsupportedAvif :
@@ -116,36 +115,32 @@ def test_read(self) -> None:
116115 image , "Tests/images/avif/hopper_avif_write.png" , 11.5
117116 )
118117
119- def _roundtrip (self , tmp_path : Path , mode : str , epsilon : float ) -> None :
118+ def test_write_rgb (self , tmp_path : Path ) -> None :
119+ """
120+ Can we write a RGB mode file to avif without error?
121+ Does it have the bits we expect?
122+ """
123+
120124 temp_file = str (tmp_path / "temp.avif" )
121125
122- hopper (mode ).save (temp_file )
123- with Image .open (temp_file ) as image :
124- assert image .mode == "RGB"
125- assert image .size == (128 , 128 )
126- assert image .format == "AVIF"
127- image .getdata ()
126+ im = hopper ()
127+ im .save (temp_file )
128+ with Image .open (temp_file ) as reloaded :
129+ assert reloaded .mode == "RGB"
130+ assert reloaded .size == (128 , 128 )
131+ assert reloaded .format == "AVIF"
132+ reloaded .getdata ()
128133
129- if mode == "RGB" :
130- # avifdec hopper.avif avif/hopper_avif_write.png
131- assert_image_similar_tofile (
132- image , "Tests/images/avif/hopper_avif_write.png" , 6.02
133- )
134+ # avifdec hopper.avif avif/hopper_avif_write.png
135+ assert_image_similar_tofile (
136+ reloaded , "Tests/images/avif/hopper_avif_write.png" , 6.02
137+ )
134138
135139 # This test asserts that the images are similar. If the average pixel
136140 # difference between the two images is less than the epsilon value,
137141 # then we're going to accept that it's a reasonable lossy version of
138142 # the image.
139- expected = hopper ()
140- assert_image_similar (image , expected , epsilon )
141-
142- def test_write_rgb (self , tmp_path : Path ) -> None :
143- """
144- Can we write a RGB mode file to avif without error?
145- Does it have the bits we expect?
146- """
147-
148- self ._roundtrip (tmp_path , "RGB" , 8.62 )
143+ assert_image_similar (reloaded , im , 8.62 )
149144
150145 def test_AvifEncoder_with_invalid_args (self ) -> None :
151146 """
@@ -186,9 +181,8 @@ def finish(self) -> None:
186181
187182 def test_no_resource_warning (self , tmp_path : Path ) -> None :
188183 with Image .open (TEST_AVIF_FILE ) as im :
189- temp_file = str (tmp_path / "temp.avif" )
190184 with warnings .catch_warnings ():
191- im .save (temp_file )
185+ im .save (tmp_path / "temp.avif" )
192186
193187 @pytest .mark .parametrize ("major_brand" , [b"avif" , b"avis" , b"mif1" , b"msf1" ])
194188 def test_accept_ftyp_brands (self , major_brand : bytes ) -> None :
0 commit comments