File: rgba_test_case.py

package info (click to toggle)
python-enable 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,220 kB
  • sloc: cpp: 57,417; python: 28,437; makefile: 314; sh: 43
file content (62 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import unittest

from numpy import array, ones

from kiva import agg

from test_utils import Utils

class RgbaTestCase(unittest.TestCase, Utils):

    def test_init(self):
        m = agg.Rgba()

    def test_init1(self):
        m = agg.Rgba(.5,.5,.5)
        desired = array((.5,.5,.5,1.0))
        self.assertRavelEqual(m.asarray(),desired)

    def test_init_from_array1(self):
        a = ones(3,'d') * .8
        m = agg.Rgba(a)
        desired = ones(4,'d') * .8
        desired[3] = 1.0
        result = m.asarray()
        self.assertRavelEqual(result, desired)

    def test_init_from_array2(self):
        a = ones(4,'d') * .8
        m = agg.Rgba(a)
        desired = ones(4,'d') * .8
        result = m.asarray()
        self.assertRavelEqual(result, desired)

    def test_init_from_array3(self):
        a = ones(5,'d')
        try:
            m = agg.Rgba(a)
        except ValueError:
            pass # can't init from array that isn't 6 element.

    def test_init_from_array4(self):
        a = ones((2,3),'d')
        try:
            m = agg.Rgba(a)
        except ValueError:
            pass # can't init from array that isn't 1d.

    def test_gradient(self):
        first = agg.Rgba(0.,0.,0.,0.)
        second = agg.Rgba(1.,1.,1.,1.)
        actual = first.gradient(second,.5).asarray()
        desired = array((.5,.5,.5,.5))
        self.assertRavelEqual(actual, desired)

    def test_pre(self):
        first = agg.Rgba(1.0,1.0,1.0,0.5)
        actual = first.premultiply().asarray()
        desired = array((.5,.5,.5,.5))
        self.assertRavelEqual(actual, desired)

if __name__ == "__main__":
    unittest.main()