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
def test_invalid(self): with pytest.raises(ValueError): Color.from_rgb(0.6, 0.2, 0xcc)
def test_invalid(self): with pytest.raises(ValueError): Color.from_hsl(25, 1.0, 0.74)
def test_alphacolor_comparison(self, func): color = Color.from_int(0xefab3) alphacolor = AlphaColor.from_name("red") assert getattr(color, func)(alphacolor) == NotImplemented
def test_invalid(self, colorint): with pytest.raises(ValueError): Color.from_int(colorint)
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
def test_invalid_comparison(self, func, arg): color = Color.from_int(0xefab3) assert getattr(color, func)(arg) == NotImplemented
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)
def test_replace(hsv_dict, expected): color = Color.from_hsv(0.75, 0.45, 0.29) assert int(color.hsv.replace(**hsv_dict)) == expected
def test_valid(self, attr, expected): color = Color.from_hsv(0.75, 0.47, 0.29) assert round(getattr(color.hsv, attr), 4) == expected
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
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]
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
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)
def test_from_rgb(): assert int(Color.from_rgb(0.3569, 0.4510, 0.2902)) == 0x5b734a
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)
def test_from_hsl(): assert int(Color.from_hsl(0.2583, 0.1515, 0.7412)) == 0xbcc7b3
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
def test_gt(self): color_a = Color.from_int(0xffab3) color_b = Color.from_int(0xefab3) assert color_a > color_b
def test_ne(self): color_a = Color.from_int(0xefab3) color_b = Color.from_int(0xffab3) assert color_a != color_b
def test_eq(self): color_a = Color.from_int(0xefab3) color_b = Color.from_int(0xefab3) assert color_a == color_b
def test_str(): color = Color.from_int(0xabcdef) assert str(color) == "abcdef"
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
def test_repr(): color = Color.from_int(0xabcdef) assert repr(color) == "<Color(0xabcdef)>"
def test_valid(self): assert int(Color.from_rgb(0.6, 0.2, 0.8)) == 0x9933cc
def test_hex(): color = Color.from_int(0xabcdef) assert hex(color) == "0xabcdef"
def test_valid(self): assert int(Color.from_hsl(0.625, 0.15, 0.74)) == 0xb3b8c7
def test_from_name(): color = Color.from_name("gray") assert int(color) == 0x808080
def test_valid(self): assert int(Color.from_hsv(0.625, 0.15, 0.74)) == 0xa0a7bd
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)