GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ec1513...37abcf )
by thatsIch
01:10
created

HexAppendAlphaTest.test_mixed_case()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
1
"""Test color converter."""
2
3
4
import sys
5
6
from unittest import TestCase
7
8
COLOR_CONVERTER = sys.modules["Rainmeter.color.converter"]
9
10
11
class IntToHexTest(TestCase):
12
    """Testing int to hex conversion and its corner cases."""
13
14
    def test_below_lower_boundary(self):
15
        """Rainmeter only supports from 0 upwards."""
16
        self.assertRaises(AssertionError, COLOR_CONVERTER.int_to_hex, -1)
17
18
    def test_lower_boundary(self):
19
        """Zero is a corner case and should return 00."""
20
        hex_value = COLOR_CONVERTER.int_to_hex(0)
21
22
        self.assertEqual(hex_value, "00")
23
24
    def test_default(self):
25
        """A random number within the boundary 0, 255 should work."""
26
        hex_value = COLOR_CONVERTER.int_to_hex(128)
27
28
        self.assertEqual(hex_value, "80")
29
30
    def test_upper_boundary(self):
31
        """255 is a corner case and should return FF."""
32
        hex_value = COLOR_CONVERTER.int_to_hex(255)
33
34
        self.assertEqual(hex_value, "FF")
35
36
    def test_over_upper_boundary(self):
37
        """Rainmeter only supports up to 255."""
38
        self.assertRaises(AssertionError, COLOR_CONVERTER.int_to_hex, 256)
39
40
    def test_letter_case(self):
41
        """We also support lower case if it is requested."""
42
        hex_value = COLOR_CONVERTER.int_to_hex(255, letter_case=COLOR_CONVERTER.LetterCase.Lower)
43
44
        self.assertEqual(hex_value, "ff")
45
46
47 View Code Duplication
class RGBsToHexesTest(TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
48
    """Testing RGBs to hexes conversion and its corner cases."""
49
50
    def test_default_rgb_conversion(self):
51
        """3 valid ints should convert to 3 hexes."""
52
        hexes = COLOR_CONVERTER.rgbs_to_hexes([128, 128, 128])
53
54
        self.assertEqual(hexes, ["80", "80", "80"])
55
56
    def test_default_rgba_conversion(self):
57
        """4 valid ints should convert to 4 hexes."""
58
        hexes = COLOR_CONVERTER.rgbs_to_hexes([128, 128, 128, 128])
59
60
        self.assertEqual(hexes, ["80", "80", "80", "80"])
61
62
    def test_invalid_rgb_low_len(self):
63
        """RGB are at least 3 values."""
64
        self.assertRaises(AssertionError, COLOR_CONVERTER.rgbs_to_hexes, [128, 128])
65
66
    def test_invalid_rgb_high_len(self):
67
        """RGB are at most 4 values."""
68
        self.assertRaises(AssertionError, COLOR_CONVERTER.rgbs_to_hexes, [128, 128, 128, 128, 128])
69
70
71
class HexesToStringTest(TestCase):
72
    """This test guerentees that a proper string conversion ."""
73
74
    def test_stringing(self):
75
        """Default case with one spacing."""
76
        stringed = COLOR_CONVERTER.hexes_to_string(["80", "80", "80"])
77
78
        self.assertEqual(stringed, "808080")
79
80
    def test_rgba(self):
81
        """RGBA case."""
82
        stringed = COLOR_CONVERTER.hexes_to_string(["80", "80", "80", "80"])
83
84
        self.assertEqual(stringed, "80808080")
85
86
87
class HexToIntTest(TestCase):
88
    """Testing hex to int conversion and its corner cases."""
89
90
    def test_below_lower_boundary(self):
91
        """Rainmeter only supports from 0 upwards."""
92
        self.assertRaises(AssertionError, COLOR_CONVERTER.hex_to_int, "-1")
93
94
    def test_lower_boundary(self):
95
        """00 is a corner case and should return 0."""
96
        int_value = COLOR_CONVERTER.hex_to_int("00")
97
98
        self.assertEqual(int_value, 0)
99
100
    def test_default(self):
101
        """A random number within the boundary 0, 255 should work."""
102
        int_value = COLOR_CONVERTER.hex_to_int("80")
103
104
        self.assertEqual(int_value, 128)
105
106
    def test_upper_boundary(self):
107
        """FF is a corner case and should return 255."""
108
        int_value = COLOR_CONVERTER.hex_to_int("FF")
109
110
        self.assertEqual(int_value, 255)
111
112
    def test_over_upper_boundary(self):
113
        """Rainmeter only supports up to 255."""
114
        self.assertRaises(AssertionError, COLOR_CONVERTER.hex_to_int, "100")
115
116
117
class HexesToRGBsTest(TestCase):
118 View Code Duplication
    """Testing Hexes to RGBs conversion and its corner cases."""
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
119
120
    def test_default_hex_conversion(self):
121
        """."""
122
        rgb = COLOR_CONVERTER.hexes_to_rgbs(["80", "80", "80"])
123
124
        self.assertEqual(rgb, [128, 128, 128])
125
126
    def test_default_hexa_conversion(self):
127
        """4 valid hexes should convert to rgba."""
128
        rgba = COLOR_CONVERTER.hexes_to_rgbs(["80", "80", "80", "80"])
129
130
        self.assertEqual(rgba, [128, 128, 128, 128])
131
132
    def test_invalid_hex_low_len(self):
133
        """Require at least 3 values."""
134
        self.assertRaises(AssertionError, COLOR_CONVERTER.hexes_to_rgbs, ["FF", "FF"])
135
136
    def test_invalid_hex_high_len(self):
137
        """Require at most 4 values."""
138
        self.assertRaises(
139
            AssertionError,
140
            COLOR_CONVERTER.hexes_to_rgbs,
141
            ["FF", "FF", "FF", "FF", "FF"]
142
        )
143
144
145
class RGBsToStringTest(TestCase):
146
    """This test guerentees that a proper string conversion ."""
147
148
    def test_stringing(self):
149
        """Default Rainmeter decimal color representation."""
150
        stringed = COLOR_CONVERTER.rgbs_to_string([128, 128, 128])
151
152
        self.assertEqual(stringed, "128,128,128")
153
154
    def test_with_spacing(self):
155
        """For people who like to space things."""
156
        stringed = COLOR_CONVERTER.rgbs_to_string([128, 128, 128], spacing=1)
157
158
        self.assertEqual(stringed, "128, 128, 128")
159
160
    def test_with_more_spacing(self):
161
        """For people who like to use a lot of spacings."""
162
        stringed = COLOR_CONVERTER.rgbs_to_string([128, 128, 128], spacing=5)
163
164
        self.assertEqual(stringed, "128,     128,     128")
165
166
167
class HexAppendAlphaTest(TestCase):
168
    """This test handles different cases of appended alpha values."""
169
170
    def test_lower_case(self):
171
        """Lower case hex string adds a lower-case full alpha channel."""
172
        stringed = COLOR_CONVERTER.convert_hex_to_hex_with_alpha("ff8800")
173
174
        self.assertEqual(stringed, "ff8800ff")
175
176
    def test_upper_case(self):
177
        """Upper case hex string adds upper-case full alpha channel."""
178
        stringed = COLOR_CONVERTER.convert_hex_to_hex_with_alpha("FF8800")
179
180
        self.assertEqual(stringed, "FF8800FF")
181
182
    def test_mixed_case(self):
183
        """If case is not clear add upper-case full alpha channel."""
184
        stringed = COLOR_CONVERTER.convert_hex_to_hex_with_alpha("Ff8800")
185
186
        self.assertEqual(stringed, "Ff8800FF")
187
188
    def test_already_alpha(self):
189
        """Only add alpha channel if have only RGB."""
190
        stringed = COLOR_CONVERTER.convert_hex_to_hex_with_alpha("FF8800FF")
191
192
        self.assertEqual(stringed, "FF8800FF")
193