def test_rgb_to_hsl(self): assert_items_almost_equal((30.0, 1.0, 0.5), grapefruit.rgb_to_hsl(1, 0.5, 0)) assert_items_almost_equal((20.0, 1.0, 0.625), grapefruit.rgb_to_hsl(1, 0.5, 0.25)) #ff8040 assert_items_almost_equal((40.0, 1.0, 0.375), grapefruit.rgb_to_hsl(0.75, 0.5, 0)) #bf8000
def test_set_cmy(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.cmy = (0.1, 0.2, 0.3) assert_items_almost_equal(col.cmy, (0.1, 0.2, 0.3)) assert_equal(col.rgb, grapefruit.cmy_to_rgb(0.1, 0.2, 0.3)) assert_almost_equal( col.hsl, grapefruit.rgb_to_hsl(grapefruit.cmy_to_rgb(0.1, 0.2, 0.3)))
def test_set_hsv(self): col = grapefruit.Color.from_hsv(30, 1, 1) col.hsv = (40, 0.5, 0.2) assert_items_almost_equal(col.hsv, (40, 0.5, 0.2)) assert_equal(col.rgb, grapefruit.hsv_to_rgb(40, 0.5, 0.2)) assert_almost_equal( col.hsl, grapefruit.rgb_to_hsl(grapefruit.hsv_to_rgb(40, 0.5, 0.2)))
def test_set_cmyk(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.cmyk = (0, 0.111, 0.222, 0.46) assert_items_almost_equal(col.cmyk, (0, 0.111, 0.222, 0.46)) assert_equal( col.rgb, grapefruit.cmy_to_rgb(grapefruit.cmyk_to_cmy( 0, 0.111, 0.222, 0.46))) assert_almost_equal( col.hsl, grapefruit.rgb_to_hsl( grapefruit.cmy_to_rgb( grapefruit.cmyk_to_cmy(0, 0.111, 0.222, 0.46))))
def test_rgb_to_hsl_tuple(self): assert_items_almost_equal((30.0, 1.0, 0.5), grapefruit.rgb_to_hsl((1, 0.5, 0)))
def test_set_hsv(self): col = grapefruit.Color.from_hsv(30, 1, 1) col.hsv = (40, 0.5, 0.2) assert_items_almost_equal(col.hsv, (40, 0.5, 0.2)) assert_equal(col.rgb, grapefruit.hsv_to_rgb(40, 0.5, 0.2)) assert_almost_equal(col.hsl, grapefruit.rgb_to_hsl(grapefruit.hsv_to_rgb(40, 0.5, 0.2)))
def test_set_blue(self): col = grapefruit.Color.from_rgb(0.1, 0.2, 0.3) col.blue = 0.9 assert_equal(col.rgb, (0.1, 0.2, 0.9)) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.1, 0.2, 0.9))
def test_set_green(self): col = grapefruit.Color.from_rgb(0.1, 0.2, 0.3) col.green = 0.9 assert_equal(col.rgb, (0.1, 0.9, 0.3)) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.1, 0.9, 0.3))
def test_set_html(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.html = '#0080ff' assert_equal(col.rgb, (0.0, 128.0/255.0, 1.0)) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.0, 128.0/255.0, 1.0))
def test_set_cmyk(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.cmyk = (0, 0.111, 0.222, 0.46) assert_items_almost_equal(col.cmyk, (0, 0.111, 0.222, 0.46)) assert_equal(col.rgb, grapefruit.cmy_to_rgb(grapefruit.cmyk_to_cmy(0, 0.111, 0.222, 0.46))) assert_almost_equal(col.hsl, grapefruit.rgb_to_hsl(grapefruit.cmy_to_rgb(grapefruit.cmyk_to_cmy(0, 0.111, 0.222, 0.46))))
def test_set_ints(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.ints = (0, 128, 255) assert_equal(col.rgb, (0.0, 128.0 / 255.0, 1.0)) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.0, 128.0 / 255.0, 1.0))
def test_set_html(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.html = '#0080ff' assert_equal(col.rgb, (0.0, 128.0 / 255.0, 1.0)) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.0, 128.0 / 255.0, 1.0))
def test_set_cmy(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.cmy = (0.1, 0.2, 0.3) assert_items_almost_equal(col.cmy, (0.1, 0.2, 0.3)) assert_equal(col.rgb, grapefruit.cmy_to_rgb(0.1, 0.2, 0.3)) assert_almost_equal(col.hsl, grapefruit.rgb_to_hsl(grapefruit.cmy_to_rgb(0.1, 0.2, 0.3)))
def test_set_pil(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.pil = 0xff8000 assert_equal(col.rgb, (0.0, 128.0 / 255.0, 1.0)) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.0, 128.0 / 255.0, 1.0))
def test_set_ints(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.ints = (0, 128, 255) assert_equal(col.rgb, (0.0, 128.0/255.0, 1.0)) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.0, 128.0/255.0, 1.0))
def test_set_rgba(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.rgba = (0.1, 0.2, 0.3, 0.5) assert_equal(col.rgb, (0.1, 0.2, 0.3)) assert_equal(col.alpha, 0.5) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.1, 0.2, 0.3))
def test_set_pil(self): col = grapefruit.Color.from_rgb(1.0, 0.5, 0.0) col.pil = 0xff8000 assert_equal(col.rgb, (0.0, 128.0/255.0, 1.0)) assert_equal(col.hsl, grapefruit.rgb_to_hsl(0.0, 128.0/255.0, 1.0))