示例#1
0
    def test_hsla(self):
        self.assertEqualHSL('hsla(1,20%,30%,0.5)', hsla(1, 0.2, 0.3, 0.5))
        self.assertEqualHSL('hsla(1, 20%, 30%, 0.5)', hsla(1, 0.2, 0.3, 0.5))
        self.assertEqualHSL('hsla( 1, 20% , 30% , 0.5)',
                            hsla(1, 0.2, 0.3, 0.5))

        with self.assertRaises(ValueError):
            color('hsla(1, 20%, 30%)')

        with self.assertRaises(ValueError):
            color('hsla(a, 20%, 30%, 0.5)')

        with self.assertRaises(ValueError):
            color('hsla(1, a, 30%, 0.5)')

        with self.assertRaises(ValueError):
            color('hsla(1, 20%, a, 0.5)')

        with self.assertRaises(ValueError):
            color('hsla(1, 20%, 30%, a)')

        with self.assertRaises(ValueError):
            color('hsla(1, 20%, 30%, 0.5, 5)')
示例#2
0
    def test_hsla_hash(self):
        self.assertEqual(hash(hsla(10, 0.2, 0.3, 0.5)),
                         hash(hsla(10, 0.2, 0.3, 0.5)))
        self.assertEqual(hash(hsla(10, 0.2, 0.3, 1.0)), hash(hsl(10, 0.2,
                                                                 0.3)))
        self.assertNotEqual(hash(hsla(10, 0.3, 0.2, 0.5)),
                            hash(hsla(10, 0.2, 0.3, 0.5)))

        self.assertNotEqual(hash(hsla(10, 0, 0, 0.5)),
                            hash(rgba(10, 0, 0, 0.5)))
示例#3
0
 def test_hsl_alpha(self):
     self.assertEqualColor(hsla(60, 0.0, 0.0, 0.3),
                           rgba(0x00, 0x00, 0x00, 0.3))
     self.assertEqualColor(hsla(60, 0.0, 1.0, 0.3),
                           rgba(0xff, 0xff, 0xff, 0.3))
     self.assertEqualColor(hsla(60, 1.0, 0.5, 0.3),
                           rgba(0xff, 0xff, 0x00, 0.3))
     self.assertEqualColor(hsla(60, 0.25, 0.25, 0.3),
                           rgba(0x50, 0x50, 0x30, 0.3))
     self.assertEqualColor(hsla(60, 0.25, 0.75, 0.3),
                           rgba(0xcf, 0xcf, 0xaf, 0.3))
     self.assertEqualColor(hsla(60, 0.75, 0.75, 0.3),
                           rgba(0xef, 0xef, 0x8f, 0.3))
     self.assertEqualColor(hsla(60, 0.75, 0.25, 0.3),
                           rgba(0x70, 0x70, 0x10, 0.3))
示例#4
0
 def test_hsla_repr(self):
     self.assertEqual(repr(hsla(10, 0.2, 0.3, 0.5)),
                      "hsla(10, 0.2, 0.3, 0.5)")