@@ -1301,6 +1301,48 @@ 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' ,
1305
+ [('red' , 0.5 ), ('#ff0000' , 0.5 ), ('#f00' , 0.5 ),
1306
+ ('#ff0000ff' , 0.5 ), ((1.0 , 0.0 , 0.0 , 1.0 ), 0.5 )])
1307
+ def test_to_rgba_array_color_alpha_tuple (rgba_alpha ):
1308
+ """to_rgba_array() accepts tuple (color, alpha) argument."""
1309
+ booleans = mcolors .to_rgba_array (rgba_alpha ) \
1310
+ == mcolors .to_rgba_array ('red' , alpha = 0.5 )
1311
+ assert booleans .all ()
1312
+
1313
+
1314
+ @pytest .mark .parametrize ('rg
8000
ba_alpha' ,
1315
+ [('blue' , - 2 ), ('#0000ff' , - 2 ), ('#00f' , - 2 ),
1316
+ ('#0000ffff' , 2 ), ((0.0 , 0.0 , 1.0 , 1.0 ), 2 )])
1317
+ def test_to_rgba_array_color_alpha_tuple_invalid_alpha (rgba_alpha ):
1318
+ """
1319
+ to_rgba_array() rejects tuple (color, alpha) argument when
1320
+ alpha is not between 0 and 1.
1321
+ """
1322
+ with pytest .raises (ValueError , match = 'Alpha must be between 0 and 1,' ):
1323
+ mcolors .to_rgba_array (rgba_alpha )
1324
+
1325
+
1326
+ @pytest .mark .parametrize ('rgba_alpha' ,
1327
+ [('red' , 0.5 ), ('#ff0000' , 0.5 ), ('#f00' , 0.5 ),
1328
+ ('#ff0000ff' , 0.5 ), ((1.0 , 0.0 , 0.0 , 1.0 ), 0.5 )])
1329
+ def test_to_rgba_color_alpha_tuple (rgba_alpha ):
1330
+ """to_rgba() accepts tuple (color, alpha) argument."""
1331
+ assert mcolors .to_rgba (rgba_alpha ) == mcolors .to_rgba ('red' , alpha = 0.5 )
1332
+
1333
+
1334
+ @pytest .mark .parametrize ('rgba_alpha' ,
1335
+ [('blue' , - 2 ), ('#0000ff' , - 2 ), ('#00f' , - 2 ),
1336
+ ('#0000ffff' , 2 ), ((0.0 , 0.0 , 1.0 , 1.0 ), 2 )])
1337
+ def test_to_rgba_color_alpha_tuple_invalid_alpha (rgba_alpha ):
1338
+ """
1339
+ to_rgba() rejects tuple (color, alpha) argument when alpha
1340
+ is not between 0 and 1.
1341
+ """
1342
+ with pytest .raises (ValueError , match = 'Alpha must be between 0 and 1' ):
1343
+ mcolors .to_rgba (rgba_alpha )
1344
+
1345
+
1304
1346
def test_failed_conversions ():
1305
1347
with pytest .raises (ValueError ):
1306
1348
mcolors .to_rgba ('5' )
0 commit comments