@@ -1301,6 +1301,62 @@ def test_to_rgba_array_alpha_array():
1301
1301
assert_array_equal (c [:,3 ],alpha )
1302
1302
1303
1303
1304
+ @pytest .mark .parametrize ('rgba_alpha, alpha' ,
1305
+ [(('black' ,1 ),0.5 ), (('#000000' ,0.5 ),None )])
1306
+ def test_to_rgba_array_color_alpha_tuple (rgba_alpha ,alpha ):
1307
+ """to_rgba_array() accepts tuple (color, alpha) argument."""
1308
+ booleans = mcolors .to_rgba_array (rgba_alpha ,alpha = alpha ) \
1309
+ == mcolors .to_rgba_array ('black' ,alpha = 0.5 )
1310
+ assert booleans .all ()
1311
+
1312
+
1313
+ def test_to_rgba_array_color_alpha_tuple_multiple_colors ():
1314
+ """to_rgba_array() accepts tuple (array of colors, alpha) argument."""
1315
+ color_array = np .array ([[1. ,1. ,1. ,1. ], [0. ,0. ,1. ,0. ]])
1316
+ booleans = mcolors .to_rgba_array ((color_array ,0.5 ),alpha = None ) \
1317
+ == np .array ([[1. ,1. ,1. ,0.5 ], [0. ,0. ,1. ,0.5 ]])
1318
+ assert booleans .all ()
1319
+
1320
+ color_sequence = [[1. ,1. ,1. ,1. ], [0. ,0. ,1. ,0. ]]
1321
+ booleans = mcolors .to_rgba_array ((color_sequence ,1 ),alpha = 0.5 ) \
1322
+ == np .array ([[1. ,1. ,1. ,0.5 ], [0. ,0. ,1. ,0.5 ]])
1323
+ assert booleans .all ()
1324
+
1325
+
1326
+ @pytest .mark .parametrize ('rgba_alpha' ,
1327
+ [('black' ,- 2 ), ('#000000' ,- 2 ), ('#000' ,- 2 ),
1328
+ ('#000000ff' ,2 ), ((0.0 ,0.0 ,0.0 ,0.0 ),2 )])
1329
+ def test_to_rgba_array_color_alpha_tuple_invalid_alpha (rgba_alpha ):
1330
+ """
1331
+ to_rgba_array() rejects tuple (color, alpha) argument when
1332
+ alpha is not between 0 and 1.
1333
+ """
1334
+ with pytest .raises (ValueError ,match = "'alpha' must be between 0 and 1," ):
1335
+ mcolors .to_rgba_array (rgba_alpha )
1336
+
1337
+
1338
+ @pytest .mark .parametrize ('rgba_alpha, alpha' ,
1339
+ [(('white' ,1 ),0.5 ), (('#ffffff' ,1 ),0.5 ),
1340
+ (('#ffffff00' ,0.5 ),None ),
1341
+ (((1.0 ,1.0 ,1.0 ,1.0 ),0.5 ),None )])
1342
+ def test_to_rgba_color_alpha_tuple (rgba_alpha ,alpha ):
1343
+ """to_rgba() accepts tuple (color, alpha) argument."""
1344
+ assert mcolors .to_rgba (rgba_alpha ,alpha = alpha ) \
1345
+ == mcolors .to_rgba ('white' ,alpha = 0.5 )
1346
+
1347
+
1348
+ @pytest .mark .parametrize ('rgba_alpha' ,
1349
+ [('blue' ,- 2 ), ('#0000ff' ,- 2 ), ('#00f' ,- 2 ),
1350
+ ('#0000ffff' ,2 ), ((0.0 ,0.0 ,1.0 ,1.0 ),2 )])
1351
+ def test_to_rgba_color_alpha_tuple_invalid_alpha (rgba_alpha ):
1352
+ """
1353
+ to_rgba() rejects tuple (color, alpha) argument when alpha
1354
+ is not between 0 and 1.
1355
+ """
1356
+ with pytest .raises (ValueError ,match = "'alpha' must be between 0 and 1" ):
1357
+ mcolors .to_rgba (rgba_alpha )
1358
+
1359
+
1304
1360
def test_failed_conversions ():
1305
1361
with pytest .raises (ValueError ):
1306
1362
mcolors .to_rgba ('5' )