File: test_colour.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (97 lines) | stat: -rw-r--r-- 2,818 bytes parent folder | download
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import unittest
import wx
from unittests import wtc

#---------------------------------------------------------------------------

class Colour(wtc.WidgetTestCase):

    def test_default_ctor(self):
        c = wx.Colour()
        self.assertTrue(not c.IsOk())
        self.assertTrue(c.Get() == (-1,-1,-1,255))


    def test_rgb_ctor(self):
        c = wx.Colour(1,2,3)
        self.assertTrue(c.Get(False) == (1,2,3))


    def test_rgba_ctor(self):
        c = wx.Colour(1,2,3,4)
        self.assertTrue(c.Get() == (1,2,3,4))


    def test_copy_ctor(self):
        c1 = wx.Colour(1,2,3,4)
        c2 = wx.Colour(c1)
        self.assertTrue(c1 == c2)
        self.assertTrue(c1 is not c2)
        self.assertTrue(c1.Get() == c2.Get())


    def test_seq_ctor1(self):
        c = wx.Colour( [1,2,3,4] )
        self.assertTrue(c.Get() == (1,2,3,4))


    def test_seq_ctor2(self):
        c = wx.Colour( [1,2,3] )
        self.assertTrue(c.Get(False) == (1,2,3))


    def test_numpy_ctor(self):
        import numpy as np
        a = np.array( [1,2,3,4] )
        c = wx.Colour(a)
        self.assertTrue(c.Get() == (1,2,3,4))


    def test_GetPixel(self):
        c1 = wx.Colour(1,2,3,4)
        p = c1.GetPixel()


    def test_converters(self):
        # Ensure that other types that are sequence-like can't be
        # auto-converted, the copy constructor is good-enough for testing this
        with self.assertRaises(TypeError):
            p = wx.Colour(wx.Rect(1,2,3,4))


    def test_GetIM(self):
        # Test the immutable version returned by GetIM
        obj = wx.Colour(1,2,3,4)
        im = obj.GetIM()
        assert isinstance(im, tuple)
        assert im.red == obj.red
        assert im.green == obj.green
        assert im.blue == obj.blue
        assert im.alpha == obj.alpha
        obj2 = wx.Colour(im)
        assert obj == obj2


    if hasattr(wx, 'testColourTypeMap'):
        def test_ColourTypemaps(self):
            c = wx.testColourTypeMap('red')
            self.assertTrue(c.Get() == (0xff, 0, 0, 0xff))
            c = wx.testColourTypeMap('Blue:80')
            self.assertTrue(c.Get() == (0, 0, 0xff, 0x80))
            c = wx.testColourTypeMap('#112233')
            self.assertTrue(c.Get() == (0x11, 0x22, 0x33, 0xff))
            c = wx.testColourTypeMap('#11223344')
            self.assertTrue(c.Get() == (0x11, 0x22, 0x33, 0x44))
            c = wx.testColourTypeMap(None)
            self.assertTrue(c.Get() == (-1, -1, -1, 0xff))
            c = wx.testColourTypeMap( (1,2,3) )
            self.assertTrue(c.Get() == (1, 2, 3, 0xff))
            c = wx.testColourTypeMap( (1,2,3,4) )
            self.assertTrue(c.Get() == (1, 2, 3, 4))


#---------------------------------------------------------------------------


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