def test_roundtrip(pair): rgb, lch = pair argb = convert(*convert(*rgb, src=cs.rgb, dst=cs.lch), src=cs.lch, dst=cs.rgb) for v in argb: assert v > -0.0001 assert v < 1.0001 assert _near(argb, rgb, 0.1)
def assert_color_roundtrip(color, src, dst, tolerance): """Asserts roundtrip of color correction within a given tolerance Helper function for tests below. """ other = convert(*color, src=src, dst=dst) rio_roundtrip = convert(*other, src=dst, dst=src) if _near(rio_roundtrip, color, tol=tolerance): return True else: # Did not roundtrip properly, can colormath do it? src_cm = to_colormath[src] dst_cm = to_colormath[dst] cm_roundtrip = convert_color( convert_color(src_cm(*color), dst_cm, illuminant="d65"), src_cm, illuminant="d65").get_value_tuple() assert _near(rio_roundtrip, cm_roundtrip, tol=tolerance)
def assert_color_roundtrip(color, src, dst, tolerance): """Asserts roundtrip of color correction within a given tolerance Helper function for tests below. """ other = convert(*color, src=src, dst=dst) rio_roundtrip = convert(*other, src=dst, dst=src) if _near(rio_roundtrip, color, tol=tolerance): return True else: # Did not roundtrip properly, can colormath do it? src_cm = to_colormath[src] dst_cm = to_colormath[dst] cm_roundtrip = convert_color( convert_color(src_cm(*color), dst_cm, illuminant="d65"), src_cm, illuminant="d65", ).get_value_tuple() assert _near(rio_roundtrip, cm_roundtrip, tol=tolerance)
def test_lch2rgb(pair): rgb, lch = pair argb = convert(*lch, src=cs.lch, dst=cs.rgb) assert _near(argb, rgb, (1.0, 1.0, 0.1))
def test_rgb2lch(pair): rgb, lch = pair alch = convert(*rgb, src=cs.rgb, dst=cs.lch) assert alch[0] >= 0 assert _near(alch, lch, (1.0, 1.0, 0.25))
def test_bad_colorspace_invalid_enum(): """Invalid colorspace enum names raise AttributeError""" with pytest.raises(AttributeError): convert(0.1, 0.1, 0.1, src=cs.foo, dst=cs.bar)
def test_bad_colorspace_invalid_int(): """Invalid colorspace integers raise ValueError""" with pytest.raises(ValueError): convert(0.1, 0.1, 0.1, src=999, dst=999)
def test_bad_colorspace_string(): """String colorspaces raise ValueError""" with pytest.raises(ValueError): convert(0.1, 0.1, 0.1, src="FOO", dst="RGB")
def test_bad_colorspace_string(): """String colorspaces raise ValueError""" with pytest.raises(ValueError): convert(0.1, 0.1, 0.1, src='FOO', dst='RGB')