File: test_dejaVuCommands.py

package info (click to toggle)
mgltools-viewerframework 1.5.7-1
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 1,584 kB
  • ctags: 1,271
  • sloc: python: 13,681; sh: 78; makefile: 10
file content (174 lines) | stat: -rw-r--r-- 5,716 bytes parent folder | download | duplicates (4)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#
# Author: Sowjanya Karnati
#
#
#$Id: test_dejaVuCommands.py,v 1.3 2008/09/11 17:55:11 vareille Exp $
#


import sys
import unittest
from ViewerFramework.VF import ViewerFramework
from ViewerFramework.dejaVuCommands import setbackgroundcolorCommand,setAntialiasingCommand
from DejaVu.IndexedPolylines import IndexedPolylines
def pause(self, sleepTime=0.4):
        from time import sleep
        sleep(sleepTime)

class DejaVuCommandBaseTests(unittest.TestCase):
    def setUp(self):
        from ViewerFramework.VF import ViewerFramework
        self.vf = ViewerFramework(logMode='no', 
                                  trapExceptions=False, withShell=0)
        self.vf.browseCommands('dejaVuCommands',package='ViewerFramework')
        self.vf.GUI.dockCamera()
    
    
        
    def tearDown(self):
        self.vf.Exit(0)


class SetBackGroungColorTest(DejaVuCommandBaseTests):
    
    def test_settingbgcolor_white(self):
        """tests setting bg color to white"""
        color = [1.0,1.0,1.0]
        self.vf.setbackgroundcolor(color)
        self.assertEqual(self.vf.GUI.VIEWER.currentCamera.backgroundColor[:-1],color)
        

    def test_settingbgcolor_black(self):
        """tests setting bg color to black"""
        color = [0.0,0.0,0.0]
        self.vf.setbackgroundcolor(color)
        self.assertEqual(self.vf.GUI.VIEWER.currentCamera.backgroundColor[:-1],color)
        

    def test_settingbgcolor_blue(self):
        """tests setting bg color to blue"""
        color = [0.0,0.0,1.0]
        self.vf.setbackgroundcolor(color)
        self.assertEqual(self.vf.GUI.VIEWER.currentCamera.backgroundColor[:-1],color)
        

    def test_settingbgcolor_green(self):
        """tests setting bg color to green"""
        color = [0.0,1.0,0.0]
        self.vf.setbackgroundcolor(color)
        self.assertEqual(self.vf.GUI.VIEWER.currentCamera.backgroundColor[:-1],color)
        
    
    def test_settingbgcolor_red(self):
        """tests setting bg color to red"""
        color = [1.0,0.0,0.0]
        self.vf.setbackgroundcolor(color)
        self.assertEqual(self.vf.GUI.VIEWER.currentCamera.backgroundColor[:-1],color)
        
        
    def test_settingbgcolor_invalid_input_1(self):
         """tests command with invalid input"""
         color = []
         c = self.vf.setbackgroundcolor(color)
         error = "Error: color length should be 3"
         self.assertEqual(c,error)
    
    def test_settingbgcolor_invalid_input_2(self): 
         """tests command with invalid input with len(list)>3"""
         color = [1.0,0.2,0.2,0.2]
         c = self.vf.setbackgroundcolor(color)
         error1 = "Error: color length should be 3"
         self.assertEqual(c,error1)
    
    def test_settingbgcolor_invalid_input_3(self):  
         """tests command with invalid input with string
"""
         color = "ftfr"
         c = self.vf.setbackgroundcolor(color)
         error2 = "Error: color type can't be string"
         self.assertEqual(c,error2)    


    ################widget tests###################
    def test_settingbgcolor_widget(self):
        """tests selecting color in widget"""
        color = [1.0,1.0,0.0]
        c = self.vf.setbackgroundcolor
        form = c.showForm('setbackgroundcolor', modal=0, blocking=0)
        c.color_cb(color)
        self.assertEqual(self.vf.GUI.VIEWER.currentCamera.backgroundColor[:-1],color)
        form.withdraw()


class setAntiAliasngTest(DejaVuCommandBaseTests):


    def test_setantialiasing_1(self):
        """tests setting antialiasing val to 3"""
        aa = 3
        triangle=IndexedPolylines('mytriangle',vertices=[[-15,0,0],[0,-10,0],[15,10,0]],
                                   faces=((0,1),(1,2),(2,0),))
        self.vf.GUI.VIEWER.AddObject(triangle)
        c = self.vf.setAntialiasing(aa)
        self.assertEqual(self.vf.GUI.VIEWER.GUI.nbJitter.get(),aa)


    def test_setantialiasing_2(self):
        """tests setting antialiasing val to 15"""
        aa = 15
        triangle=IndexedPolylines('mytriangle',vertices=[[-15,0,0],[0,-10,0],[15,10,0]],
                                   faces=((0,1),(1,2),(2,0),))
        self.vf.GUI.VIEWER.AddObject(triangle)
        c = self.vf.setAntialiasing(aa)
        self.assertEqual(self.vf.GUI.VIEWER.GUI.nbJitter.get(),aa)


    def test_setantialiasing_3(self):
        """tests setting antialiasing val to 66"""
        aa = 66
        triangle=IndexedPolylines('mytriangle',vertices=[[-15,0,0],[0,-10,0],[15,10,0]],
                                   faces=((0,1),(1,2),(2,0),))
        self.vf.GUI.VIEWER.AddObject(triangle) 
        c = self.vf.setAntialiasing(aa)
        self.assertEqual(self.vf.GUI.VIEWER.GUI.nbJitter.get(),aa)


    def test_setantialiasing_invalid_input(self):
        """tests command with invalid input"""
        aa =1
        triangle=IndexedPolylines('mytriangle',vertices=[[-15,0,0],[0,-10,0],[15,10,0]],
                                   faces=((0,1),(1,2),(2,0),))
        self.vf.GUI.VIEWER.AddObject(triangle) 
        c = self.vf.setAntialiasing
        self.assertRaises(ValueError,c,aa)


###############widget tests###############3


    def test_settingantialiasing_widget(self):
        """tests by selecting antialiasing val in widget"""
        aa = 2
        c = self.vf.setAntialiasing
        form = c.showForm('setAntialiasing', modal=0, blocking=0)
        cf = c.cmdForms['setAntialiasing']
        ebn = cf.descr.entryByName
        cmdW = ebn['value']['widget']
        cmdW.select_clear(0,last=1)
        cmdW.select_set(1)
        val = cmdW.getcurselection()[0]
        self.assertEqual(val,aa)
        form.withdraw()

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