@@ -215,11 +215,14 @@ def test_signedness(self, mode):
215215 self .check (mode , 2 ** 15 + 1 )
216216 self .check (mode , 2 ** 16 - 1 )
217217
218+ @pytest .mark .parametrize ("mode" , ("P" , "PA" ))
218219 @pytest .mark .parametrize ("color" , ((255 , 0 , 0 ), (255 , 0 , 0 , 255 )))
219- def test_p_putpixel_rgb_rgba (self , color ):
220- im = Image .new ("P" , (1 , 1 ), 0 )
220+ def test_p_putpixel_rgb_rgba (self , mode , color ):
221+ im = Image .new (mode , (1 , 1 ))
221222 im .putpixel ((0 , 0 ), color )
222- assert im .convert ("RGB" ).getpixel ((0 , 0 )) == (255 , 0 , 0 )
223+
224+ alpha = color [3 ] if len (color ) == 4 and mode == "PA" else 255
225+ assert im .convert ("RGBA" ).getpixel ((0 , 0 )) == (255 , 0 , 0 , alpha )
223226
224227
225228@pytest .mark .skipif (cffi is None , reason = "No CFFI" )
@@ -340,12 +343,15 @@ def test_reference_counting(self):
340343 # pixels can contain garbage if image is released
341344 assert px [i , 0 ] == 0
342345
343- def test_p_putpixel_rgb_rgba (self ):
344- for color in [(255 , 0 , 0 ), (255 , 0 , 0 , 255 )]:
345- im = Image .new ("P" , (1 , 1 ), 0 )
346+ @pytest .mark .parametrize ("mode" , ("P" , "PA" ))
347+ def test_p_putpixel_rgb_rgba (self , mode ):
348+ for color in [(255 , 0 , 0 ), (255 , 0 , 0 , 127 )]:
349+ im = Image .new (mode , (1 , 1 ))
346350 access = PyAccess .new (im , False )
347351 access .putpixel ((0 , 0 ), color )
348- assert im .convert ("RGB" ).getpixel ((0 , 0 )) == (255 , 0 , 0 )
352+
353+ alpha = color [3 ] if len (color ) == 4 and mode == "PA" else 255
354+ assert im .convert ("RGBA" ).getpixel ((0 , 0 )) == (255 , 0 , 0 , alpha )
349355
350356
351357class TestImagePutPixelError (AccessTest ):
0 commit comments