def test_valid(self, val, skip_types, expected): assert Color.to_int(val, skip_types) == expected
def test_repr(self): color = Color(0xeeff22aa) assert repr(color) == "<Color(4009697962)>"
def test_str(self): color = Color(0xeeff22aa) assert str(color) == "eeff22aa"
def test_invalid_init(self): with pytest.raises(ValueError): Color(-1)
def test_int(self): color = Color(0xeeff22aa) assert int(color) == 0xeeff22aa
def test_alpha(self): color = Color(0xeeff22aa) assert round(color.alpha, 2) == 0.93
def test_without_alpha(self): color = Color.from_rgba(0xef, 0xa1, 0xde) assert color.integer == 0xefa1de
def test_rgb(self, prop, color_hex, expected): color = Color(color_hex) assert getattr(color, prop) == expected
def test_valid_edit(self, prop, color_hex, arg, expected): """Edit a color which already has an alpha value""" color = Color(color_hex) setattr(color, prop, arg) assert color.integer == expected
def test_invalid_edit(self, prop, color_hex, arg): """Modifications that should raise exception""" color = Color(color_hex) with pytest.raises(ValueError): setattr(color, prop, arg)
def test_from_name(): assert Color.from_name('gainsboro') == Color(0xdcdcdc)
def test_invalid(self, val, skip_types): with pytest.raises(ValueError): assert Color.to_int(val, skip_types)