def test_rgba(self): self.assertEqualColor('rgba(1,2,3,0.5)', rgba(1, 2, 3, 0.5)) self.assertEqualColor('rgba(1, 2, 3, 0.5)', rgba(1, 2, 3, 0.5)) self.assertEqualColor('rgba( 1 , 2 , 3 , 0.5)', rgba(1, 2, 3, 0.5)) self.assertEqualColor('#1234', rgba(0x11, 0x22, 0x33, 0.2666)) self.assertEqualColor('#11223344', rgba(0x11, 0x22, 0x33, 0.2666)) self.assertEqualColor('#abcd', rgba(0xaa, 0xbb, 0xcc, 0.8666)) self.assertEqualColor('#ABCD', rgba(0xaa, 0xbb, 0xcc, 0.8666)) self.assertEqualColor('#abcdefba', rgba(0xab, 0xcd, 0xef, 0.7294)) self.assertEqualColor('#ABCDEFBA', rgba(0xab, 0xcd, 0xef, 0.7294)) with self.assertRaises(ValueError): color('rgba(10, 20, 30)') with self.assertRaises(ValueError): color('rgba(a, 10, 20, 0.5)') with self.assertRaises(ValueError): color('rgba(10, b, 20, 0.5)') with self.assertRaises(ValueError): color('rgba(10, 20, c, 0.5)') with self.assertRaises(ValueError): color('rgba(10, 20, 30, c)') with self.assertRaises(ValueError): color('rgba(10, 20, 30, 0.5, 5)')
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)))
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))
def test_rgba_hash(self): self.assertEqual(hash(rgba(10, 20, 30, 0.5)), hash(rgba(10, 20, 30, 0.5))) self.assertEqual(hash(rgba(10, 20, 30, 1.0)), hash(rgb(10, 20, 30))) self.assertNotEqual(hash(rgb(10, 20, 30)), hash(rgb(30, 20, 10)))
def test_rgba_repr(self): self.assertEqual(repr(rgba(10, 20, 30, 0.5)), "rgba(10, 20, 30, 0.5)")
def test_noop(self): self.assertEqualColor(rgba(1, 2, 3, 0.5), rgba(1, 2, 3, 0.5)) self.assertEqualHSL(hsl(1, 0.2, 0.3), hsl(1, 0.2, 0.3))