Exemplo n.º 1
0
    def test_ok_calculate(self):
        args = (
            (Color((0x50, 0x50, 0x50)), 4, (0xB7, 0xB7, 0xB7)),
            (Color((0xB7, 0xB7, 0xB7)), 6, (0x35, 0x35, 0x35)),
        )

        for color, contrast, rgb in args:
            self.assertColorEqual(color.inverted(contrast), rgb)
Exemplo n.º 2
0
    def test_impossible(self):
        args = (
            (Color((0x7F, 0x7F, 0x7F)), 10),
            (Color((0x00, 0xFF, 0xFF)), 21),
        )

        with patch("sys.stderr", new=StringIO()):
            for color, contrast in args:
                self.assertRaises(RuntimeError, color.inverted, contrast)
Exemplo n.º 3
0
    def test_ok(self):
        args = (
            ((0x00, 0x00, 0x00), "Black"),
            ((0xFF, 0x00, 0x00), "Red"),
            ((0xFF, 0xFF, 0xFF), "White"),
            ((0x12, 0x34, 0x56), "Anonymous"),
        )

        for rgb, name in args:
            self.assertColorEqual(Color(rgb), rgb, name)

        self.assertColorEqual(Color((0x12, 0x34, 0x56), "Custom"),
                              (0x12, 0x34, 0x56), "Custom")
Exemplo n.º 4
0
    def test(self):
        args = (
            ((0x00, 0x00, 0x00), (0xFF, 0xFF, 0xFF), 21),
            ((0x00, 0x00, 0xFF), (0xFF, 0xFF, 0xFF), 8),
            ((0x00, 0x00, 0xFF), (0xFF, 0x00, 0x00), 2),
            ((0x00, 0x00, 0x00), (0x00, 0x00, 0x00), 1),
            ((0xFF, 0xFF, 0xFF), (0xFF, 0xFF, 0xFF), 1),
        )

        for a, b, result in args:
            a, b = Color(a), Color(b)
            self.assertEqual(a // b, b // a)
            self.assertEqual(result, a // b)
Exemplo n.º 5
0
    def test(self):
        args = (
            ((0x00, 0x00, 0x00), (0xFF, 0xFF, 0xFF), 21.0),
            ((0x00, 0x00, 0xFF), (0xFF, 0xFF, 0xFF), 8.59),
            ((0x00, 0x00, 0xFF), (0xFF, 0x00, 0x00), 2.14),
            ((0x00, 0x00, 0x00), (0x00, 0x00, 0x00), 1.0),
            ((0xFF, 0xFF, 0xFF), (0xFF, 0xFF, 0xFF), 1.0),
        )

        for a, b, result in args:
            a, b = Color(a), Color(b)
            self.assertEqual(a / b, b / a)
            self.assertEqual(result, int((a / b) * 100) / 100)
Exemplo n.º 6
0
    def test_ok(self):
        args = (1, 21)

        for arg in args:
            self.assertPasses(Color((0, 0, 0)).inverted, arg)

        args = (
            (Color((0x00, 0x00, 0x00)), (0xFF, 0xFF, 0xFF), "White"),
            (Color((0xFF, 0xFF, 0xFF)), (0x00, 0x00, 0x00), "Black"),
            (Color((0x00, 0xFF, 0xFF)), (0xFF, 0x00, 0x00), "Red"),
            (Color((0xFF, 0x00, 0x00)), (0x00, 0xFF, 0xFF), "Cyan"),
        )

        for color, rgb, name in args:
            self.assertColorEqual(color.inverted(), rgb, name)
Exemplo n.º 7
0
    def test(self):
        args = (
            ((0x00, 0x00, 0x00), (0, 0, 0, 100)),
            ((0xFF, 0x00, 0x00), (0, 100, 100, 0)),
            ((0xAB, 0xCD, 0xEF), (28, 14, 0, 6)),
        )

        for rgb, result in args:
            self.assertEqual(result, Color(rgb).cmyk)
Exemplo n.º 8
0
    def test(self):
        args = (
            ((0x00, 0x00, 0x00), (0, 0, 0)),
            ((0xFF, 0x00, 0x00), (0, 100, 50)),
            ((0xAB, 0xCD, 0xEF), (210, 68, 80)),
        )

        for rgb, result in args:
            self.assertEqual(result, Color(rgb).hsl)
Exemplo n.º 9
0
    def test(self):
        args = (
            ((0x00, 0x00, 0x00), True, "000000"),
            ((0xFF, 0x00, 0x00), True, "ff0000"),
            ((0xFF, 0x00, 0x00), False, "FF0000"),
            ((0xAB, 0xCD, 0xEF), True, "abcdef"),
            ((0xAB, 0xCD, 0xEF), False, "ABCDEF"),
        )

        for rgb, lowercase, result in args:
            self.assertEqual(result, Color(rgb).hex(lowercase))
Exemplo n.º 10
0
    def test(self):
        args = (
            (0.0, (0x00, 0x00, 0x00)),
            (1.0, (0xFF, 0xFF, 0xFF)),
            (0.2126, (0xFF, 0x00, 0x00)),
            (0.7151, (0x00, 0xFF, 0x00)),
            (0.0722, (0x00, 0x00, 0xFF)),
        )

        for luminance, rgb in args:
            self.assertEqual(luminance,
                             int(Color(rgb).luminance * 10_000) / 10_000)
Exemplo n.º 11
0
 def test(self):
     self.assertEqual("Color(rgb=(0, 0, 0), name='Black')",
                      str(Color((0x00, 0x00, 0x00), "Black")))
     self.assertEqual("Color(rgb=(0, 0, 0), name='Black')",
                      repr(Color((0x00, 0x00, 0x00), "Black")))
Exemplo n.º 12
0
    def test_nok_contrast(self):
        args = (0.9, 21.1)

        with patch("sys.stderr", new=StringIO()):
            for arg in args:
                self.assertRaises(ValueError, Color((0, 0, 0)).inverted, arg)
Exemplo n.º 13
0
    def test_ok_contrast(self):
        args = (1, 21)

        for arg in args:
            self.assertPasses(Color((0, 0, 0)).inverted, arg)