Esempio n. 1
0
    def test_pygame2_base_Color_a(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Color.a:

        # Gets or sets the alpha value of the Color.
        c = Color (100, 100, 100)
        self.assertEqual (c.a, 255)
        
        c = Color (100, 100, 100, 100)
        self.assertEqual (c.a, 100)
        
        c = Color (100, 100, 100)
        self.assertEqual (c.a, 255)
        c.a = 200
        self.assertEqual (c.a, 200)
        c.a += 22
        self.assertEqual (c.a, 222)
        
        c = Color (0xAABBCCDD)
        self.assertEqual (c.a, 0xAA)
        
        c = Color ("0xBBCCDD")
        self.assertEqual (c.a, 0xFF)
        c = Color ("0xAABBCCDD")
        self.assertEqual (c.a, 0xDD)
        
        c = Color ("#AABBCCDD")
        self.assertEqual (c.a, 0xDD)
        c = Color ("#BBCCDD")
        self.assertEqual (c.a, 0xFF)
        
        c = Color ("red")
        self.assertEqual (c.a, 255)
Esempio n. 2
0
    def test_rgba (self):
        c = Color (0)
        self.assertEqual (c.r, 0)
        self.assertEqual (c.g, 0)
        self.assertEqual (c.b, 0)
        self.assertEqual (c.a, 0)

        # Test simple assignments
        c.r = 123
        self.assertEqual (c.r, 123)
        self.assertRaises (ValueError, _assignr, c, 537)
        self.assertEqual (c.r, 123)
        self.assertRaises (ValueError, _assignr, c, -3)
        self.assertEqual (c.r, 123)

        c.g = 55
        self.assertEqual (c.g, 55)
        self.assertRaises (ValueError, _assigng, c, 348)
        self.assertEqual (c.g, 55)
        self.assertRaises (ValueError, _assigng, c, -44)
        self.assertEqual (c.g, 55)

        c.b = 77
        self.assertEqual (c.b, 77)
        self.assertRaises (ValueError, _assignb, c, 256)
        self.assertEqual (c.b, 77)
        self.assertRaises (ValueError, _assignb, c, -12)
        self.assertEqual (c.b, 77)

        c.a = 255
        self.assertEqual (c.a, 255)
        self.assertRaises (ValueError, _assigna, c, 312)
        self.assertEqual (c.a, 255)
        self.assertRaises (ValueError, _assigna, c, -10)
        self.assertEqual (c.a, 255)