@@ -1307,6 +1307,51 @@ def test_to_rgba_array_alpha_array():
13071307 assert_array_equal (c [:, 3 ], alpha )
13081308
13091309
1310+ def test_to_rgba_array_accepts_color_alpha_tuple ():
1311+ assert_array_equal (
1312+ mcolors .to_rgba_array (('black' , 0.9 )),
1313+ [[0 , 0 , 0 , 0.9 ]])
1314+
1315+
1316+ def test_to_rgba_array_explicit_alpha_overrides_tuple_alpha ():
1317+ assert_array_equal (
1318+ mcolors .to_rgba_array (('black' , 0.9 ), alpha = 0.5 ),
1319+ [[0 , 0 , 0 , 0.5 ]])
1320+
1321+
1322+ def test_to_rgba_array_accepts_color_alpha_tuple_with_multiple_colors ():
1323+ color_array = np .array ([[1. , 1. , 1. , 1. ], [0. , 0. , 1. , 0. ]])
1324+ assert_array_equal (
1325+ mcolors .to_rgba_array ((color_array , 0.2 )),
1326+ [[1. , 1. , 1. , 0.2 ], [0. , 0. , 1. , 0.2 ]])
1327+
1328+ color_sequence = [[1. , 1. , 1. , 1. ], [0. , 0. , 1. , 0. ]]
1329+ assert_array_equal (
1330+ mcolors .to_rgba_array ((color_sequence , 0.4 )),
1331+ [[1. , 1. , 1. , 0.4 ], [0. , 0. , 1. , 0.4 ]])
1332+
1333+
1334+ def test_to_rgba_array_error_with_color_invalid_alpha_tuple ():
1335+ with pytest .raises (ValueError , match = "'alpha' must be between 0 and 1," ):
1336+ mcolors .to_rgba_array (('black' , 2.0 ))
1337+
1338+
1339+ @pytest .mark .parametrize ('rgba_alpha' ,
1340+ [('white' , 0.5 ), ('#ffffff' , 0.5 ), ('#ffffff00' , 0.5 ),
1341+ ((1.0 , 1.0 , 1.0 , 1.0 ), 0.5 )])
1342+ def test_to_rgba_accepts_color_alpha_tuple (rgba_alpha ):
1343+ assert mcolors .to_rgba (rgba_alpha ) == (1 , 1 , 1 , 0.5 )
1344+
1345+
1346+ def test_to_rgba_explicit_alpha_overrides_tuple_alpha ():
1347+ assert mcolors .to_rgba (('red' , 0.1 ), alpha = 0.9 ) == (1 , 0 , 0 , 0.9 )
1348+
1349+
1350+ def test_to_rgba_error_with_color_invalid_alpha_tuple ():
1351+ with pytest .raises (ValueError , match = "'alpha' must be between 0 and 1" ):
1352+ mcolors .to_rgba (('blue' , 2.0 ))
1353+
1354+
13101355def test_failed_conversions ():
13111356 with pytest .raises (ValueError ):
13121357 mcolors .to_rgba ('5' )
0 commit comments