|
18 | 18 | validate_bool, |
19 | 19 | validate_color, |
20 | 20 | validate_colorlist, |
| 21 | + validate_color_or_bool, |
21 | 22 | _validate_color_or_linecolor, |
22 | 23 | validate_cycler, |
23 | 24 | validate_float, |
@@ -343,6 +344,35 @@ def generate_validator_testcases(valid): |
343 | 344 | ('(0, 1, "0.5")', ValueError), # last one not a float |
344 | 345 | ), |
345 | 346 | }, |
| 347 | + {'validator': validate_color_or_bool, |
| 348 | + 'success': (('None', 'none'), |
| 349 | + ('none', 'none'), |
| 350 | + ('AABBCC', '#AABBCC'), # RGB hex code |
| 351 | + ('AABBCC00', '#AABBCC00'), # RGBA hex code |
| 352 | + ('tab:blue', 'tab:blue'), # named color |
| 353 | + ('C12', 'C12'), # color from cycle |
| 354 | + ('(0, 1, 0)', (0.0, 1.0, 0.0)), # RGB tuple |
| 355 | + ((0, 1, 0), (0, 1, 0)), # non-string version |
| 356 | + ('(0, 1, 0, 1)', (0.0, 1.0, 0.0, 1.0)), # RGBA tuple |
| 357 | + ((0, 1, 0, 1), (0, 1, 0, 1)), # non-string version |
| 358 | + *((_, True) for _ in |
| 359 | + ('t', 'yes', 'on', 'true', 1, True)), |
| 360 | + *((_, False) for _ in |
| 361 | + ('f', 'n', 'no', 'off', 'false', 0, False)), |
| 362 | + # These last three are currently individually validated |
| 363 | + # both as colors and as bools. `validate_color_or_bool` |
| 364 | + # checks for color first, so they won't appear as boolean. |
| 365 | + ('y', 'y'), |
| 366 | + ('1', '1'), |
| 367 | + ('0', '0') |
| 368 | + ), |
| 369 | + 'fail': (('tab:veryblue', ValueError), # invalid name |
| 370 | + ('(0, 1)', ValueError), # tuple with length < 3 |
| 371 | + ('(0, 1, 0, 1, 0)', ValueError), # tuple with length > 4 |
| 372 | + ('(0, 1, none)', ValueError), # cannot cast none to float |
| 373 | + ('(0, 1, "0.5")', ValueError), # last one not a float |
| 374 | + ), |
| 375 | + }, |
346 | 376 | {'validator': _validate_color_or_linecolor, |
347 | 377 | 'success': (('linecolor', 'linecolor'), |
348 | 378 | ('markerfacecolor', 'markerfacecolor'), |
|
0 commit comments