Пример #1
0
def test_replace(rgb_dict, expected):
    color = Color.from_rgb(0.75, 0.45, 0.29)  # rgb(191,115,74)
    assert int(color.rgb.replace(**rgb_dict)) == expected
Пример #2
0
 def test_invalid(self):
     with pytest.raises(ValueError):
         Color.from_rgb(0.6, 0.2, 0xcc)
Пример #3
0
 def test_invalid(self):
     with pytest.raises(ValueError):
         Color.from_hsl(25, 1.0, 0.74)
Пример #4
0
 def test_alphacolor_comparison(self, func):
     color = Color.from_int(0xefab3)
     alphacolor = AlphaColor.from_name("red")
     assert getattr(color, func)(alphacolor) == NotImplemented
Пример #5
0
 def test_invalid(self, colorint):
     with pytest.raises(ValueError):
         Color.from_int(colorint)
Пример #6
0
def test_copy():
    orig = Color.from_hsl(0.2583, 0.1515, 0.7412)
    copy = orig.copy()
    assert id(orig) != id(copy)
    assert orig.rgb.vals == copy.rgb.vals
Пример #7
0
 def test_invalid_comparison(self, func, arg):
     color = Color.from_int(0xefab3)
     assert getattr(color, func)(arg) == NotImplemented
Пример #8
0
 def test_invalid(self, attr):
     color = Color.from_hsv(0.75, 0.47, 0.29)
     with pytest.raises(AttributeError):
         setattr(color.hsv, attr, 0.1)
Пример #9
0
def test_replace(hsv_dict, expected):
    color = Color.from_hsv(0.75, 0.45, 0.29)
    assert int(color.hsv.replace(**hsv_dict)) == expected
Пример #10
0
 def test_valid(self, attr, expected):
     color = Color.from_hsv(0.75, 0.47, 0.29)
     assert round(getattr(color.hsv, attr), 4) == expected
Пример #11
0
 def test_valid(self, attr, val):
     color = Color.from_hsv(0.45, 0.15, 0.89)
     setattr(color.hsv, attr, val)
     assert round(getattr(color.hsv, attr), 4) == val
Пример #12
0
def test_vals_getter():
    color = Color.from_hsv(0.75, 0.45, 0.29)
    assert [round(val, 4) for val in color.hsv.vals] == [0.75, 0.45, 0.29]
Пример #13
0
 def test_setter_invalid(self, wrong_vals):
     color = Color.from_rgb(0.75, 0.45, 0.29)  # rgb(191,115,74)
     with pytest.raises(ValueError):
         color.rgb.vals = wrong_vals
Пример #14
0
 def test_setter_valid(self, vals):
     color = Color.from_rgb(0.75, 0.45, 0.29)  # rgb(191,115,74)
     color.rgb.vals = vals
     assert list(color.rgb) == list(vals)
Пример #15
0
def test_from_rgb():
    assert int(Color.from_rgb(0.3569, 0.4510, 0.2902)) == 0x5b734a
Пример #16
0
 def test_setter_valid(self, vals):
     color = Color.from_hsv(0.75, 0.45, 0.29)
     color.hsv.vals = vals
     assert [round(val, 4) for val in color.hsv] == list(vals)
Пример #17
0
def test_from_hsl():
    assert int(Color.from_hsl(0.2583, 0.1515, 0.7412)) == 0xbcc7b3
Пример #18
0
 def test_setter_invalid(self, wrong_vals):
     color = Color.from_hsv(0.75, 0.45, 0.29)
     with pytest.raises(ValueError):
         color.hsv.vals = wrong_vals
Пример #19
0
 def test_gt(self):
     color_a = Color.from_int(0xffab3)
     color_b = Color.from_int(0xefab3)
     assert color_a > color_b
Пример #20
0
 def test_ne(self):
     color_a = Color.from_int(0xefab3)
     color_b = Color.from_int(0xffab3)
     assert color_a != color_b
Пример #21
0
 def test_eq(self):
     color_a = Color.from_int(0xefab3)
     color_b = Color.from_int(0xefab3)
     assert color_a == color_b
Пример #22
0
def test_str():
    color = Color.from_int(0xabcdef)
    assert str(color) == "abcdef"
Пример #23
0
 def test_valid(self, colorint, rgb):
     color = Color.from_int(colorint)
     rounded_comps = [round(comp, 4) for comp in color.rgb]
     assert rounded_comps == rgb
Пример #24
0
def test_repr():
    color = Color.from_int(0xabcdef)
    assert repr(color) == "<Color(0xabcdef)>"
Пример #25
0
 def test_valid(self):
     assert int(Color.from_rgb(0.6, 0.2, 0.8)) == 0x9933cc
Пример #26
0
def test_hex():
    color = Color.from_int(0xabcdef)
    assert hex(color) == "0xabcdef"
Пример #27
0
 def test_valid(self):
     assert int(Color.from_hsl(0.625, 0.15, 0.74)) == 0xb3b8c7
Пример #28
0
def test_from_name():
    color = Color.from_name("gray")
    assert int(color) == 0x808080
Пример #29
0
 def test_valid(self):
     assert int(Color.from_hsv(0.625, 0.15, 0.74)) == 0xa0a7bd
Пример #30
0
 def test_vals(self):
     color = Color.from_rgb(0.75, 0.45, 0.29)
     color.rgb.vals = (0.2, 0.4, 0.6)
     assert color.rgb.vals == (0.2, 0.4, 0.6)