|
3 | 3 | import unittest |
4 | 4 |
|
5 | 5 | from tppt.exception import ColorInvalidFormatError |
6 | | -from tppt.types._color import Color, to_color |
| 6 | +from tppt.types._color import RGBColor, to_color |
7 | 7 |
|
8 | 8 |
|
9 | 9 | class TestColor(unittest.TestCase): |
10 | 10 | """Test cases for Color class.""" |
11 | 11 |
|
12 | 12 | def test_init_with_rgb_hex_short(self): |
13 | 13 | """Test initialization with short hex color code (#RGB).""" |
14 | | - color = Color("#123") |
15 | | - assert color.r == 0x11 |
16 | | - assert color.g == 0x22 |
17 | | - assert color.b == 0x33 |
| 14 | + color = to_color("#123") |
| 15 | + r, g, b = color |
| 16 | + assert r == 0x11 |
| 17 | + assert g == 0x22 |
| 18 | + assert b == 0x33 |
18 | 19 |
|
19 | 20 | def test_init_with_rgb_hex_long(self): |
20 | 21 | """Test initialization with long hex color code (#RRGGBB).""" |
21 | | - color = Color("#123456") |
22 | | - assert color.r == 0x12 |
23 | | - assert color.g == 0x34 |
24 | | - assert color.b == 0x56 |
| 22 | + color = to_color("#123456") |
| 23 | + r, g, b = color |
| 24 | + assert r == 0x12 |
| 25 | + assert g == 0x34 |
| 26 | + assert b == 0x56 |
25 | 27 |
|
26 | 28 | def test_init_with_rgb_tuple(self): |
27 | 29 | """Test initialization with RGB tuple.""" |
28 | | - color = Color(10, 20, 30) |
29 | | - assert color.r == 10 |
30 | | - assert color.g == 20 |
31 | | - assert color.b == 30 |
| 30 | + color = RGBColor(10, 20, 30) |
| 31 | + r, g, b = color |
| 32 | + assert r == 10 |
| 33 | + assert g == 20 |
| 34 | + assert b == 30 |
32 | 35 |
|
33 | 36 | def test_invalid_format_no_hash(self): |
34 | 37 | """Test initialization with invalid format (no # prefix).""" |
35 | 38 | with self.assertRaises(ColorInvalidFormatError): |
36 | | - Color("123456") |
| 39 | + to_color("123456") |
37 | 40 |
|
38 | 41 | def test_invalid_format_wrong_length(self): |
39 | 42 | """Test initialization with invalid format (wrong length).""" |
40 | 43 | with self.assertRaises(ColorInvalidFormatError): |
41 | | - Color("#12345") # 6 characters (including #) is invalid |
42 | | - |
43 | | - def test_repr(self): |
44 | | - """Test string representation.""" |
45 | | - color = Color(10, 20, 30) |
46 | | - assert repr(color) == "Color(10, 20, 30)" |
| 44 | + to_color("#12345") # 6 characters (including #) is invalid |
47 | 45 |
|
48 | 46 |
|
49 | 47 | class TestToColor(unittest.TestCase): |
50 | 48 | """Test cases for to_color function.""" |
51 | 49 |
|
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 | 50 | def test_to_color_with_tuple(self): |
59 | 51 | """Test to_color with a RGB tuple.""" |
60 | 52 | 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 |
| 53 | + assert isinstance(result, RGBColor) |
| 54 | + r, g, b = result |
| 55 | + assert r == 10 |
| 56 | + assert g == 20 |
| 57 | + assert b == 30 |
65 | 58 |
|
66 | 59 | def test_to_color_with_str(self): |
67 | 60 | """Test to_color with a hex string.""" |
68 | 61 | result = to_color("#123456") |
69 | | - assert isinstance(result, Color) |
70 | | - assert result.r == 0x12 |
71 | | - assert result.g == 0x34 |
72 | | - assert result.b == 0x56 |
| 62 | + assert isinstance(result, RGBColor) |
| 63 | + r, g, b = result |
| 64 | + assert r == 0x12 |
| 65 | + assert g == 0x34 |
| 66 | + assert b == 0x56 |
73 | 67 |
|
74 | 68 | def test_to_color_with_short_hex(self): |
75 | 69 | """Test to_color with a short hex string.""" |
76 | 70 | result = to_color("#123") |
77 | | - assert isinstance(result, Color) |
78 | | - assert result.r == 0x11 |
79 | | - assert result.g == 0x22 |
80 | | - assert result.b == 0x33 |
| 71 | + assert isinstance(result, RGBColor) |
| 72 | + r, g, b = result |
| 73 | + assert r == 0x11 |
| 74 | + assert g == 0x22 |
| 75 | + assert b == 0x33 |
0 commit comments