|
3 | 3 | import unittest |
4 | 4 |
|
5 | 5 | from tppt.exception import ColorInvalidFormatError |
6 | | -from tppt.types._color import Color |
| 6 | +from tppt.types._color import Color, to_color |
7 | 7 |
|
8 | 8 |
|
9 | 9 | class TestColor(unittest.TestCase): |
@@ -44,3 +44,37 @@ def test_repr(self): |
44 | 44 | """Test string representation.""" |
45 | 45 | color = Color(10, 20, 30) |
46 | 46 | assert repr(color) == "Color(10, 20, 30)" |
| 47 | + |
| 48 | + |
| 49 | +class TestToColor(unittest.TestCase): |
| 50 | + """Test cases for to_color function.""" |
| 51 | + |
| 52 | + def test_to_color_with_color_instance(self): |
| 53 | + """Test to_color with a Color instance.""" |
| 54 | + original = Color(10, 20, 30) |
| 55 | + result = to_color(original) |
| 56 | + assert result is original |
| 57 | + |
| 58 | + def test_to_color_with_tuple(self): |
| 59 | + """Test to_color with a RGB tuple.""" |
| 60 | + result = to_color((10, 20, 30)) |
| 61 | + assert isinstance(result, Color) |
| 62 | + assert result.r == 10 |
| 63 | + assert result.g == 20 |
| 64 | + assert result.b == 30 |
| 65 | + |
| 66 | + def test_to_color_with_str(self): |
| 67 | + """Test to_color with a hex string.""" |
| 68 | + result = to_color("#123456") |
| 69 | + assert isinstance(result, Color) |
| 70 | + assert result.r == 0x12 |
| 71 | + assert result.g == 0x34 |
| 72 | + assert result.b == 0x56 |
| 73 | + |
| 74 | + def test_to_color_with_short_hex(self): |
| 75 | + """Test to_color with a short hex string.""" |
| 76 | + result = to_color("#123") |
| 77 | + assert isinstance(result, Color) |
| 78 | + assert result.r == 0x11 |
| 79 | + assert result.g == 0x22 |
| 80 | + assert result.b == 0x33 |
0 commit comments