55
66from unittest import TestCase
77
8- COLOR_CONVERTER = sys . modules [ " Rainmeter.color. converter" ]
8+ from Rainmeter .color import converter
99
1010
1111class IntToHexTest (TestCase ):
1212 """Testing int to hex conversion and its corner cases."""
1313
1414 def test_below_lower_boundary (self ):
1515 """Rainmeter only supports from 0 upwards."""
16- self .assertRaises (AssertionError , COLOR_CONVERTER .int_to_hex , - 1 )
16+ self .assertRaises (AssertionError , converter .int_to_hex , - 1 )
1717
1818 def test_lower_boundary (self ):
1919 """Zero is a corner case and should return 00."""
20- hex_value = COLOR_CONVERTER .int_to_hex (0 )
20+ hex_value = converter .int_to_hex (0 )
2121
2222 self .assertEqual (hex_value , "00" )
2323
2424 def test_default (self ):
2525 """A random number within the boundary 0, 255 should work."""
26- hex_value = COLOR_CONVERTER .int_to_hex (128 )
26+ hex_value = converter .int_to_hex (128 )
2727
2828 self .assertEqual (hex_value , "80" )
2929
3030 def test_upper_boundary (self ):
3131 """255 is a corner case and should return FF."""
32- hex_value = COLOR_CONVERTER .int_to_hex (255 )
32+ hex_value = converter .int_to_hex (255 )
3333
3434 self .assertEqual (hex_value , "FF" )
3535
3636 def test_over_upper_boundary (self ):
3737 """Rainmeter only supports up to 255."""
38- self .assertRaises (AssertionError , COLOR_CONVERTER .int_to_hex , 256 )
38+ self .assertRaises (AssertionError , converter .int_to_hex , 256 )
3939
4040 def test_letter_case (self ):
4141 """We also support lower case if it is requested."""
42- hex_value = COLOR_CONVERTER .int_to_hex (255 , letter_case = COLOR_CONVERTER .LetterCase .Lower )
42+ hex_value = converter .int_to_hex (255 , letter_case = converter .LetterCase .Lower )
4343
4444 self .assertEqual (hex_value , "ff" )
4545
@@ -49,37 +49,37 @@ class RGBsToHexesTest(TestCase):
4949
5050 def test_default_rgb_conversion (self ):
5151 """3 valid ints should convert to 3 hexes."""
52- hexes = COLOR_CONVERTER .rgbs_to_hexes ([128 , 128 , 128 ])
52+ hexes = converter .rgbs_to_hexes ([128 , 128 , 128 ])
5353
5454 self .assertEqual (hexes , ["80" , "80" , "80" ])
5555
5656 def test_default_rgba_conversion (self ):
5757 """4 valid ints should convert to 4 hexes."""
58- hexes = COLOR_CONVERTER .rgbs_to_hexes ([128 , 128 , 128 , 128 ])
58+ hexes = converter .rgbs_to_hexes ([128 , 128 , 128 , 128 ])
5959
6060 self .assertEqual (hexes , ["80" , "80" , "80" , "80" ])
6161
6262 def test_invalid_rgb_low_len (self ):
6363 """RGB are at least 3 values."""
64- self .assertRaises (AssertionError , COLOR_CONVERTER .rgbs_to_hexes , [128 , 128 ])
64+ self .assertRaises (AssertionError , converter .rgbs_to_hexes , [128 , 128 ])
6565
6666 def test_invalid_rgb_high_len (self ):
6767 """RGB are at most 4 values."""
68- self .assertRaises (AssertionError , COLOR_CONVERTER .rgbs_to_hexes , [128 , 128 , 128 , 128 , 128 ])
68+ self .assertRaises (AssertionError , converter .rgbs_to_hexes , [128 , 128 , 128 , 128 , 128 ])
6969
7070
7171class HexesToStringTest (TestCase ):
7272 """This test guerentees that a proper string conversion ."""
7373
7474 def test_stringing (self ):
7575 """Default case with one spacing."""
76- stringed = COLOR_CONVERTER .hexes_to_string (["80" , "80" , "80" ])
76+ stringed = converter .hexes_to_string (["80" , "80" , "80" ])
7777
7878 self .assertEqual (stringed , "808080" )
7979
8080 def test_rgba (self ):
8181 """RGBA case."""
82- stringed = COLOR_CONVERTER .hexes_to_string (["80" , "80" , "80" , "80" ])
82+ stringed = converter .hexes_to_string (["80" , "80" , "80" , "80" ])
8383
8484 self .assertEqual (stringed , "80808080" )
8585
@@ -89,55 +89,55 @@ class HexToIntTest(TestCase):
8989
9090 def test_below_lower_boundary (self ):
9191 """Rainmeter only supports from 0 upwards."""
92- self .assertRaises (AssertionError , COLOR_CONVERTER .hex_to_int , "-1" )
92+ self .assertRaises (AssertionError , converter .hex_to_int , "-1" )
9393
9494 def test_lower_boundary (self ):
9595 """00 is a corner case and should return 0."""
96- int_value = COLOR_CONVERTER .hex_to_int ("00" )
96+ int_value = converter .hex_to_int ("00" )
9797
9898 self .assertEqual (int_value , 0 )
9999
100100 def test_default (self ):
101101 """A random number within the boundary 0, 255 should work."""
102- int_value = COLOR_CONVERTER .hex_to_int ("80" )
102+ int_value = converter .hex_to_int ("80" )
103103
104104 self .assertEqual (int_value , 128 )
105105
106106 def test_upper_boundary (self ):
107107 """FF is a corner case and should return 255."""
108- int_value = COLOR_CONVERTER .hex_to_int ("FF" )
108+ int_value = converter .hex_to_int ("FF" )
109109
110110 self .assertEqual (int_value , 255 )
111111
112112 def test_over_upper_boundary (self ):
113113 """Rainmeter only supports up to 255."""
114- self .assertRaises (AssertionError , COLOR_CONVERTER .hex_to_int , "100" )
114+ self .assertRaises (AssertionError , converter .hex_to_int , "100" )
115115
116116
117117class HexesToRGBsTest (TestCase ):
118118 """Testing Hexes to RGBs conversion and its corner cases."""
119119
120120 def test_default_hex_conversion (self ):
121121 """."""
122- rgb = COLOR_CONVERTER .hexes_to_rgbs (["80" , "80" , "80" ])
122+ rgb = converter .hexes_to_rgbs (["80" , "80" , "80" ])
123123
124124 self .assertEqual (rgb , [128 , 128 , 128 ])
125125
126126 def test_default_hexa_conversion (self ):
127127 """4 valid hexes should convert to rgba."""
128- rgba = COLOR_CONVERTER .hexes_to_rgbs (["80" , "80" , "80" , "80" ])
128+ rgba = converter .hexes_to_rgbs (["80" , "80" , "80" , "80" ])
129129
130130 self .assertEqual (rgba , [128 , 128 , 128 , 128 ])
131131
132132 def test_invalid_hex_low_len (self ):
133133 """Require at least 3 values."""
134- self .assertRaises (AssertionError , COLOR_CONVERTER .hexes_to_rgbs , ["FF" , "FF" ])
134+ self .assertRaises (AssertionError , converter .hexes_to_rgbs , ["FF" , "FF" ])
135135
136136 def test_invalid_hex_high_len (self ):
137137 """Require at most 4 values."""
138138 self .assertRaises (
139139 AssertionError ,
140- COLOR_CONVERTER .hexes_to_rgbs ,
140+ converter .hexes_to_rgbs ,
141141 ["FF" , "FF" , "FF" , "FF" , "FF" ]
142142 )
143143
@@ -147,19 +147,19 @@ class RGBsToStringTest(TestCase):
147147
148148 def test_stringing (self ):
149149 """Default Rainmeter decimal color representation."""
150- stringed = COLOR_CONVERTER .rgbs_to_string ([128 , 128 , 128 ])
150+ stringed = converter .rgbs_to_string ([128 , 128 , 128 ])
151151
152152 self .assertEqual (stringed , "128,128,128" )
153153
154154 def test_with_spacing (self ):
155155 """For people who like to space things."""
156- stringed = COLOR_CONVERTER .rgbs_to_string ([128 , 128 , 128 ], spacing = 1 )
156+ stringed = converter .rgbs_to_string ([128 , 128 , 128 ], spacing = 1 )
157157
158158 self .assertEqual (stringed , "128, 128, 128" )
159159
160160 def test_with_more_spacing (self ):
161161 """For people who like to use a lot of spacings."""
162- stringed = COLOR_CONVERTER .rgbs_to_string ([128 , 128 , 128 ], spacing = 5 )
162+ stringed = converter .rgbs_to_string ([128 , 128 , 128 ], spacing = 5 )
163163
164164 self .assertEqual (stringed , "128, 128, 128" )
165165
@@ -169,25 +169,25 @@ class HexAppendAlphaTest(TestCase):
169169
170170 def test_lower_case (self ):
171171 """Lower case hex string adds a lower-case full alpha channel."""
172- stringed = COLOR_CONVERTER .convert_hex_to_hex_with_alpha ("ff8800" )
172+ stringed = converter .convert_hex_to_hex_with_alpha ("ff8800" )
173173
174174 self .assertEqual (stringed , "ff8800ff" )
175175
176176 def test_upper_case (self ):
177177 """Upper case hex string adds upper-case full alpha channel."""
178- stringed = COLOR_CONVERTER .convert_hex_to_hex_with_alpha ("FF8800" )
178+ stringed = converter .convert_hex_to_hex_with_alpha ("FF8800" )
179179
180180 self .assertEqual (stringed , "FF8800FF" )
181181
182182 def test_mixed_case (self ):
183183 """If case is not clear add upper-case full alpha channel."""
184- stringed = COLOR_CONVERTER .convert_hex_to_hex_with_alpha ("Ff8800" )
184+ stringed = converter .convert_hex_to_hex_with_alpha ("Ff8800" )
185185
186186 self .assertEqual (stringed , "Ff8800FF" )
187187
188188 def test_already_alpha (self ):
189189 """Only add alpha channel if have only RGB."""
190- stringed = COLOR_CONVERTER .convert_hex_to_hex_with_alpha ("FF8800FF" )
190+ stringed = converter .convert_hex_to_hex_with_alpha ("FF8800FF" )
191191
192192 self .assertEqual (stringed , "FF8800FF" )
193193
@@ -203,7 +203,7 @@ def test_without_alpha(self):
203203 unless we have a value which differs from FF or 255.
204204 The color picker will default to FF if a non alpha channel color is inputted.
205205 """
206- stringed = COLOR_CONVERTER .convert_hex_str_to_rgba_str ("FFFFFFFF" , False )
206+ stringed = converter .convert_hex_str_to_rgba_str ("FFFFFFFF" , False )
207207
208208 self .assertEqual (stringed , "255,255,255" )
209209
@@ -213,7 +213,7 @@ def test_with_alpha(self):
213213
214214 That way even FF is written back.
215215 """
216- stringed = COLOR_CONVERTER .convert_hex_str_to_rgba_str ("FFFFFFFF" , True )
216+ stringed = converter .convert_hex_str_to_rgba_str ("FFFFFFFF" , True )
217217
218218 self .assertEqual (stringed , "255,255,255,255" )
219219
@@ -224,6 +224,6 @@ def test_without_alpha_but_non_max(self):
224224 In that case we have to translate that information too
225225 and force add the alpha channel to the content.
226226 """
227- stringed = COLOR_CONVERTER .convert_hex_str_to_rgba_str ("FFFFFF01" , False )
227+ stringed = converter .convert_hex_str_to_rgba_str ("FFFFFF01" , False )
228228
229229 self .assertEqual (stringed , "255,255,255,1" )
0 commit comments