@@ -212,11 +212,14 @@ def test_signedness(self):
212212 self .check (mode , 2 ** 15 + 1 )
213213 self .check (mode , 2 ** 16 - 1 )
214214
215- def test_p_putpixel_rgb_rgba (self ):
216- for color in [(255 , 0 , 0 ), (255 , 0 , 0 , 255 )]:
217- im = Image .new ("P" , (1 , 1 ), 0 )
215+ @pytest .mark .parametrize ("mode" , ("P" , "PA" ))
216+ def test_p_putpixel_rgb_rgba (self , mode ):
217+ for color in [(255 , 0 , 0 ), (255 , 0 , 0 , 127 )]:
218+ im = Image .new (mode , (1 , 1 ))
218219 im .putpixel ((0 , 0 ), color )
219- assert im .convert ("RGB" ).getpixel ((0 , 0 )) == (255 , 0 , 0 )
220+
221+ alpha = color [3 ] if len (color ) == 4 and mode == "PA" else 255
222+ assert im .convert ("RGBA" ).getpixel ((0 , 0 )) == (255 , 0 , 0 , alpha )
220223
221224
222225@pytest .mark .skipif (cffi is None , reason = "No CFFI" )
@@ -337,12 +340,15 @@ def test_reference_counting(self):
337340 # pixels can contain garbage if image is released
338341 assert px [i , 0 ] == 0
339342
340- def test_p_putpixel_rgb_rgba (self ):
341- for color in [(255 , 0 , 0 ), (255 , 0 , 0 , 255 )]:
342- im = Image .new ("P" , (1 , 1 ), 0 )
343+ @pytest .mark .parametrize ("mode" , ("P" , "PA" ))
344+ def test_p_putpixel_rgb_rgba (self , mode ):
345+ for color in [(255 , 0 , 0 ), (255 , 0 , 0 , 127 )]:
346+ im = Image .new (mode , (1 , 1 ))
343347 access = PyAccess .new (im , False )
344348 access .putpixel ((0 , 0 ), color )
345- assert im .convert ("RGB" ).getpixel ((0 , 0 )) == (255 , 0 , 0 )
349+
350+ alpha = color [3 ] if len (color ) == 4 and mode == "PA" else 255
351+ assert im .convert ("RGBA" ).getpixel ((0 , 0 )) == (255 , 0 , 0 , alpha )
346352
347353
348354class TestImagePutPixelError (AccessTest ):
0 commit comments