|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import re |
3 | 4 | from typing import TYPE_CHECKING, Any |
4 | 5 |
|
5 | 6 | import pytest |
@@ -45,26 +46,31 @@ def test_to_rgb(color: Color, expected: str) -> None: |
45 | 46 | ("color", "expected_exception", "exception_match"), |
46 | 47 | [ |
47 | 48 | # invalid types |
48 | | - (1, TypeError, None), |
49 | | - ([1, 2, 3], TypeError, None), |
| 49 | + (1, TypeError, "Expected str or tuple for color, got <class 'int'> instead"), |
| 50 | + ([1, 2, 3], TypeError, "Expected str or tuple for color, got <class 'list'> instead"), |
50 | 51 | # invalid CSS named color |
51 | | - ("not-a-color", ValueError, None), |
| 52 | + ( |
| 53 | + "not-a-color", |
| 54 | + ValueError, |
| 55 | + "color should be a tuple or a str representation of a " |
| 56 | + "hex or rgb color, got 'not-a-color' instead", |
| 57 | + ), |
52 | 58 | # invalid hex |
53 | | - ("#1234567890", ValueError, r"too many values to unpack \(expected 3\)"), |
54 | | - ("#ABCDEFGHIJ", ValueError, r"invalid literal for int\(\) with base 16"), |
| 59 | + ("#1234567890", ValueError, "too many values to unpack (expected 3)"), |
| 60 | + ("#ABCDEFGHIJ", ValueError, "invalid literal for int() with base 16"), |
55 | 61 | # invalid rgb |
56 | | - ("rgb(0,0,999)", PlotlyError, r"rgb colors tuples cannot exceed 255"), |
| 62 | + ("rgb(0,0,999)", PlotlyError, "rgb colors tuples cannot exceed 255"), |
57 | 63 | # invalid tuple |
58 | | - ((1, 2), ValueError, r"not enough values to unpack \(expected 3, got 2\)"), |
59 | | - ((1, 2, 3, 4), ValueError, r"too many values to unpack \(expected 3\)"), |
| 64 | + ((1, 2), ValueError, "not enough values to unpack (expected 3, got 2)"), |
| 65 | + ((1, 2, 3, 4), ValueError, "too many values to unpack (expected 3)"), |
60 | 66 | ], |
61 | 67 | ) |
62 | 68 | def test_to_rgb_fails_for_invalid_color( |
63 | 69 | color: Any, |
64 | 70 | expected_exception: type[Exception], |
65 | | - exception_match: str | None, |
| 71 | + exception_match: str, |
66 | 72 | ) -> None: |
67 | | - with pytest.raises(expected_exception, match=exception_match or ""): |
| 73 | + with pytest.raises(expected_exception, match=re.escape(exception_match)): |
68 | 74 | to_rgb(color) |
69 | 75 |
|
70 | 76 |
|
|
0 commit comments