Beispiel #1
0
    def test_bz(self):
        """Test `bz`."""

        c = Color('color(--jzazbz 1 0.2 -0.3 / 1)')
        self.assertEqual(c.bz, -0.3)
        c.bz = 0.1
        self.assertEqual(c.bz, 0.1)
Beispiel #2
0
    def test_cp(self):
        """Test `cp`."""

        c = Color('color(--ictcp 1 0.2 -0.3 / 1)')
        self.assertEqual(c.cp, -0.3)
        c.cp = 0.1
        self.assertEqual(c.cp, 0.1)
Beispiel #3
0
    def test_i(self):
        """Test `i`."""

        c = Color('color(--ictcp 1 0.2 -0.3 / 1)')
        self.assertEqual(c.i, 1)
        c.i = 0.2
        self.assertEqual(c.i, 0.2)
Beispiel #4
0
    def test_force_alpha(self):
        """Test force alpha."""

        color = "color(--lchuv 20% 10 130 / 1)"
        lchuv = Color(color)
        self.assertEqual("color(--lchuv 20 10 130 / 1)",
                         lchuv.to_string(alpha=True))
    def test_delta_e_alternate_calls(self):
        """Test alternative delta e calls."""

        self.assertCompare(
            Color('red').delta_e('blue', method='2000'),
            Color('red').delta_e_2000('blue')
        )
Beispiel #6
0
    def test_hue(self):
        """Test `hue`."""

        c = Color('color(--lchuv 90% 50 120 / 1)')
        self.assertEqual(c.hue, 120)
        c.hue = 110
        self.assertEqual(c.hue, 110)
Beispiel #7
0
    def test_from_luv(self):
        """Test null from Luv conversion."""

        c1 = Color('color(--luv 90% 0 0)')
        c2 = c1.convert('lchuv')
        self.assertColorEqual(c2, Color('color(--lchuv 90% 0 0)'))
        self.assertTrue(c2.is_nan('hue'))
Beispiel #8
0
    def test_saturation(self):
        """Test `saturation`."""

        c = Color('color(--okhsl 120 50% 90% / 1)')
        self.assertEqual(c.saturation, 0.5)
        c.saturation = 0.6
        self.assertEqual(c.saturation, 0.6)
Beispiel #9
0
    def test_lightness(self):
        """Test `lightness`."""

        c = Color('color(--okhsl 120 50% 90% / 1)')
        self.assertEqual(c.lightness, 0.9)
        c.lightness = 0.8
        self.assertEqual(c.lightness, 0.8)
Beispiel #10
0
    def test_red(self):
        """Test `red`."""

        c = Color('color(rec2020 0.1 0.2 0.3 / 1)')
        self.assertEqual(c.red, 0.1)
        c.red = 0.2
        self.assertEqual(c.red, 0.2)
Beispiel #11
0
    def test_green(self):
        """Test `green`."""

        c = Color('color(rec2020 0.1 0.2 0.3 / 1)')
        self.assertEqual(c.green, 0.2)
        c.green = 0.1
        self.assertEqual(c.green, 0.1)
Beispiel #12
0
    def test_blue(self):
        """Test `blue`."""

        c = Color('color(rec2020 0.1 0.2 0.3 / 1)')
        self.assertEqual(c.blue, 0.3)
        c.blue = 0.1
        self.assertEqual(c.blue, 0.1)
Beispiel #13
0
    def test_from_lab(self):
        """Test null from Lab conversion."""

        c1 = Color('lab(90% 0 0)')
        c2 = c1.convert('lch')
        self.assertColorEqual(c2, Color('lch(90% 0 0)'))
        self.assertTrue(c2.is_nan('hue'))
Beispiel #14
0
    def test_jz(self):
        """Test `lightness`."""

        c = Color('color(--jzazbz 1 0.2 -0.3 / 1)')
        self.assertEqual(c.jz, 1)
        c.jz = 0.2
        self.assertEqual(c.jz, 0.2)
Beispiel #15
0
    def test_z(self):
        """Test `z`."""

        c = Color('color(xyz-d50 0.1 0.2 0.3 / 1)')
        self.assertEqual(c.z, 0.3)
        c.z = 0.1
        self.assertEqual(c.z, 0.1)
Beispiel #16
0
    def test_alpha(self):
        """Test `alpha`."""

        c = Color('color(--okhsl 120 50% 90% / 1)')
        self.assertEqual(c.alpha, 1)
        c.alpha = 0.5
        self.assertEqual(c.alpha, 0.5)
Beispiel #17
0
    def test_chroma(self):
        """Test `chroma`."""

        c = Color('color(--lchuv 90% 50 120 / 1)')
        self.assertEqual(c.chroma, 50)
        c.chroma = 40
        self.assertEqual(c.chroma, 40)
Beispiel #18
0
    def test_hue(self):
        """Test `hue`."""

        c = Color('color(--okhsl 120 50% 90% / 1)')
        self.assertEqual(c.hue, 120)
        c.hue = 110
        self.assertEqual(c.hue, 110)
Beispiel #19
0
    def test_alpha(self):
        """Test `alpha`."""

        c = Color('color(--lchuv 90% 50 120 / 1)')
        self.assertEqual(c.alpha, 1)
        c.alpha = 0.5
        self.assertEqual(c.alpha, 0.5)
Beispiel #20
0
    def assert_round_trip(self, color, space):
        """Cycle through all the other colors and convert to them and back and check the results."""

        c1 = Color(color).convert(space)
        for space in SPACES:
            # Print the color space to easily identify which color space broke.
            c2 = c1.convert(space)
            c2.convert(c1.space(), in_place=True)
            # Catch cases where we are really close to 360 which should wrap to 0
            for c in (c1, c2):
                if isinstance(c._space, Cylindrical):
                    if util.round_half_up(util.no_nan(c.hue),
                                          c.PRECISION) == 360:
                        c.hue = 0
            # Run rounded string back through parsing in case we hit something like a hue that needs normalization.
            str1 = Color(c1.to_string(color=True,
                                      fit=False)).to_string(color=True,
                                                            fit=False)
            str2 = Color(c2.to_string(color=True,
                                      fit=False)).to_string(color=True,
                                                            fit=False)
            # Print failing results for debug purposes
            if str1 != str2:
                print('----- Convert: {} <=> {} -----'.format(
                    c1.space(), space))
                print('Original: ', color.to_string(color=True, fit=False))
                print(c1.space() + ': ', str1, c1.coords())
                print(space + ': ', str2, c2.coords())
                assert str1 == str2
Beispiel #21
0
    def test_no_alpha(self):
        """Test no alpha."""

        color = "color(--lchuv 20% 10 130 / 0.2)"
        lchuv = Color(color)
        self.assertEqual("color(--lchuv 20 10 130)",
                         lchuv.to_string(alpha=False))
Beispiel #22
0
def get_colors(result):
    """Get color from results."""

    from coloraide import Color
    from coloraide.interpolate import Interpolator

    colors = []
    if isinstance(result, Color):
        colors.append(ColorTuple(result.to_string(fit=False), result.clone()))
    elif isinstance(result, Interpolator):
        colors = ColorInterpolate(result.steps(steps=5, max_delta_e=3))
    elif isinstance(result, ColorRow):
        colors = result
    elif isinstance(result, str):
        try:
            colors.append(ColorTuple(result, Color(result)))
        except Exception:
            pass
    elif isinstance(result, Sequence):
        for x in result:
            if isinstance(x, Color):
                colors.append(ColorTuple(x.to_string(fit=False), x.clone()))
            elif isinstance(x, str):
                try:
                    colors.append(ColorTuple(x, Color(x)))
                except Exception:
                    pass
    return colors
Beispiel #23
0
    def test_lightness(self):
        """Test `lightness`."""

        c = Color('color(--lchuv 90% 50 120 / 1)')
        self.assertEqual(c.lightness, 90)
        c.lightness = 80
        self.assertEqual(c.lightness, 80)
Beispiel #24
0
    def test_alpha(self):
        """Test `alpha`."""

        c = Color('color(xyz-d50 0.1 0.2 0.3 / 1)')
        self.assertEqual(c.alpha, 1)
        c.alpha = 0.5
        self.assertEqual(c.alpha, 0.5)
Beispiel #25
0
    def test_delta_e_alternate_calls_with_params(self):
        """Test alternative delta e calls with parameters."""

        self.assertCompare(
            Color('red').delta_e('blue', method='hyab', space="din99o"),
            Color('red').delta_e_hyab('blue', space="din99o")
        )
Beispiel #26
0
    def test_x(self):
        """Test `x`."""

        c = Color('color(xyz-d50 0.1 0.2 0.3 / 1)')
        self.assertEqual(c.x, 0.1)
        c.x = 0.2
        self.assertEqual(c.x, 0.2)
Beispiel #27
0
    def test_alpha(self):
        """Test `alpha`."""

        c = Color('color(--ictcp 1 0.2 -0.3 / 1)')
        self.assertEqual(c.alpha, 1)
        c.alpha = 0.5
        self.assertEqual(c.alpha, 0.5)
Beispiel #28
0
    def test_y(self):
        """Test `y`."""

        c = Color('color(xyz-d50 0.1 0.2 0.3 / 1)')
        self.assertEqual(c.y, 0.2)
        c.y = 0.1
        self.assertEqual(c.y, 0.1)
Beispiel #29
0
    def test_ct(self):
        """Test `ct`."""

        c = Color('color(--ictcp 1 0.2 -0.3 / 1)')
        self.assertEqual(c.ct, 0.2)
        c.ct = 0.1
        self.assertEqual(c.ct, 0.1)
Beispiel #30
0
    def test_az(self):
        """Test `az`."""

        c = Color('color(--jzazbz 1 0.2 -0.3 / 1)')
        self.assertEqual(c.az, 0.2)
        c.az = 0.1
        self.assertEqual(c.az, 0.1)