|
| 1 | +import pytest |
| 2 | + |
| 3 | +from branca.colormap import _parse_color_as_numerical_sequence |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize("input_data, expected", [ |
| 7 | + ((0, 0, 0), (0.0, 0.0, 0.0, 1.0)), |
| 8 | + ((255, 255, 255), (1.0, 1.0, 1.0, 1.0)), |
| 9 | + ((255, 0, 0), (1.0, 0.0, 0.0, 1.0)), |
| 10 | + ((0.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0)), |
| 11 | + ((0.5, 0.5, 0.5), (0.5, 0.5, 0.5, 1.0)), |
| 12 | + ((0.1, 0.2, 0.3, 0.4), (0.1, 0.2, 0.3, 0.4)), |
| 13 | + ((0.0, 1.0, 0.0, 0.5), (0.0, 1.0, 0.0, 0.5)), |
| 14 | + ((0, 0, 0, 255.0), (0.0, 0.0, 0.0, 1.0)), |
| 15 | + ((0, 0, 255.0, 0.0), (0.0, 0.0, 1.0, 0.0)), |
| 16 | +]) |
| 17 | +def test_parse_color_as_numerical_sequence(input_data, expected): |
| 18 | + assert _parse_color_as_numerical_sequence(input_data) == expected |
| 19 | + |
| 20 | +@pytest.mark.parametrize("input_data, raises", [ |
| 21 | + ((256, 0, 0), ValueError), |
| 22 | + ((0, 0, -1), ValueError), |
| 23 | + ((0, 1, 2, 3, 4), ValueError), |
| 24 | + ((0.5, 0.5, 0.5, "string"), TypeError), |
| 25 | +]) |
| 26 | +def test_parse_color_as_numerical_sequence_invalid(input_data, raises): |
| 27 | + with pytest.raises(raises): |
| 28 | + _parse_color_as_numerical_sequence(input_data) |
0 commit comments