@@ -150,27 +150,30 @@ def test_icc(self, tmp_path):
150150 assert not im1 .info .get ("icc_profile" )
151151 assert im2 .info .get ("icc_profile" )
152152
153- def test_icc_big (self ):
153+ @pytest .mark .parametrize (
154+ "n" ,
155+ (
156+ 0 ,
157+ 1 ,
158+ 3 ,
159+ 4 ,
160+ 5 ,
161+ 65533 - 14 , # full JPEG marker block
162+ 65533 - 14 + 1 , # full block plus one byte
163+ ImageFile .MAXBLOCK , # full buffer block
164+ ImageFile .MAXBLOCK + 1 , # full buffer block plus one byte
165+ ImageFile .MAXBLOCK * 4 + 3 , # large block
166+ ),
167+ )
168+ def test_icc_big (self , n ):
154169 # Make sure that the "extra" support handles large blocks
155- def test (n ):
156- # The ICC APP marker can store 65519 bytes per marker, so
157- # using a 4-byte test code should allow us to detect out of
158- # order issues.
159- icc_profile = (b"Test" * int (n / 4 + 1 ))[:n ]
160- assert len (icc_profile ) == n # sanity
161- im1 = self .roundtrip (hopper (), icc_profile = icc_profile )
162- assert im1 .info .get ("icc_profile" ) == (icc_profile or None )
163-
164- test (0 )
165- test (1 )
166- test (3 )
167- test (4 )
168- test (5 )
169- test (65533 - 14 ) # full JPEG marker block
170- test (65533 - 14 + 1 ) # full block plus one byte
171- test (ImageFile .MAXBLOCK ) # full buffer block
172- test (ImageFile .MAXBLOCK + 1 ) # full buffer block plus one byte
173- test (ImageFile .MAXBLOCK * 4 + 3 ) # large block
170+ # The ICC APP marker can store 65519 bytes per marker, so
171+ # using a 4-byte test code should allow us to detect out of
172+ # order issues.
173+ icc_profile = (b"Test" * int (n / 4 + 1 ))[:n ]
174+ assert len (icc_profile ) == n # sanity
175+ im1 = self .roundtrip (hopper (), icc_profile = icc_profile )
176+ assert im1 .info .get ("icc_profile" ) == (icc_profile or None )
174177
175178 @mark_if_feature_version (
176179 pytest .mark .valgrind_known_error , "libjpeg_turbo" , "2.0" , reason = "Known Failing"
@@ -649,19 +652,19 @@ def test_bad_mpo_header(self):
649652 # Assert
650653 assert im .format == "JPEG"
651654
652- def test_save_correct_modes (self ):
655+ @pytest .mark .parametrize ("mode" , ("1" , "L" , "RGB" , "RGBX" , "CMYK" , "YCbCr" ))
656+ def test_save_correct_modes (self , mode ):
653657 out = BytesIO ()
654- for mode in ["1" , "L" , "RGB" , "RGBX" , "CMYK" , "YCbCr" ]:
655- img = Image .new (mode , (20 , 20 ))
656- img .save (out , "JPEG" )
658+ img = Image .new (mode , (20 , 20 ))
659+ img .save (out , "JPEG" )
657660
658- def test_save_wrong_modes (self ):
661+ @pytest .mark .parametrize ("mode" , ("LA" , "La" , "RGBA" , "RGBa" , "P" ))
662+ def test_save_wrong_modes (self , mode ):
659663 # ref https://github.com/python-pillow/Pillow/issues/2005
660664 out = BytesIO ()
661- for mode in ["LA" , "La" , "RGBA" , "RGBa" , "P" ]:
662- img = Image .new (mode , (20 , 20 ))
663- with pytest .raises (OSError ):
664- img .save (out , "JPEG" )
665+ img = Image .new (mode , (20 , 20 ))
666+ with pytest .raises (OSError ):
667+ img .save (out , "JPEG" )
665668
666669 def test_save_tiff_with_dpi (self , tmp_path ):
667670 # Arrange
0 commit comments