File: test_gui.py

package info (click to toggle)
pybik 0.5-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 776 kB
  • sloc: python: 4,591; makefile: 4; sh: 1
file content (308 lines) | stat: -rwxr-xr-x 10,505 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/python
# -*- coding: utf-8 -*-

#  Copyright © 2009, 2011  B. Clausius <barcc@gmx.de>
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys, os

from ldtp import *
from ldtputils import *
from ooldtp import *

from nose.plugins.skip import SkipTest

sys.path.insert(0, os.path.dirname(__file__)+'/..')
from pybiklib.confstore import confstore

os.environ['GUI_TIMEOUT'] = '2'
os.environ['LANG'] = ''

BUTTON_ANIMSPEED_RESET = 'btnClearAnimspeed'
BUTTON_COLOR_RESET = 'btnClearFaceColor'
BUTTON_IMAGE_RESET = 'btnClearImageFile'
BUTTON_LIGHTING = 'btnLighting'
BUTTON_LIGHTING_RESET = 'btnClearLighting'
BUTTON_PATTERN_RESET = 'btnClearPattern'
BUTTON_SIZE = 'sbtnSpinButtonSize'
BUTTON_SIZE_RESET = 'btnClearSize'
DIALOG_EDIT_COLORS = 'dlgColorselector'
DIALOG_PREFERENCES = 'dlgPreferences'
ENTRY_FORMULA = 'txtEntryFormula'
HSCALE_ANIMSPEED = '???AnimSpeed'
MENU_COLORS = 'mnuEdit;mnuColor'
MENU_EDIT = 'mnuEdit'
MENU_GAME = 'mnuGame'
MENU_HELP = 'mnuHelp'
MENU_INFO = 'mnuHelp;mnuAbout'
MENU_NEW_RANDOM = 'mnuGame;mnuNewrandom'
MENU_NEW_SOLVED = 'mnuGame;mnuNewsolved'
MENU_PLAY_TOOLBAR = 'mnuView;mnuPlayToolbar'
MENU_PREFERENCES = 'mnuEdit;mnuPreferences'
MENU_QUIT = 'mnuGame;mnuQuit'
MENU_STATUSBAR = 'mnuView;mnuStatusBar'
MENU_VIEW = 'mnuView'
RADIOBUTTON_MOSAIC = 'btnMosaic'
RADIOBUTTON_TILE = 'btnTiled'
STATUSBAR_MAIN = 'statStatusbarMain'
TOOLBAR_PLAY = 'tbarToolbarPlay'
TOOLBUTTON_ADD_MARK = 'btnAddmark'
TOOLBUTTON_FORWARD = 'btnForward'
TOOLBUTTON_NEXT = 'btnNext'
TOOLBUTTON_PLAY = 'btnPlay'
TOOLBUTTON_PREVIOUS = 'btnPrevious'
TOOLBUTTON_REMOVE_MARK = 'btnRemovemark'
TOOLBUTTON_REWIND = 'btnRewind'
TOOLBUTTON_STOP = 'btnStop'
TREEVIEW_SCRIPTS = 'ttblTreeviewScripts'
WINDOW_MAIN = 'Pybik'

class AppPybik (component):
    def __init__(self):
        component.__init__(self, WINDOW_MAIN)
        
    @classmethod
    def launch(cls, *args):
        cmd = os.path.dirname(__file__) + '/../pybik'
        if args:
            launchapp(cmd, list(args))
        else:
            launchapp(cmd)
        pybik = cls()
        assert pybik.waittillguiexist ()
        return pybik
    
    def quit(self):
        self.selectmenuitem (MENU_QUIT)
        return self.waittillguinotexist ()
        
    def set_formula(self, formula, pos, status):
        '''Sets formula text with cursor position and checks statusbar text'''
        assert self.settextvalue (ENTRY_FORMULA, formula), formula
        assert self.setcursorposition (ENTRY_FORMULA, pos), pos
        assert self.activatetext (ENTRY_FORMULA)
        text = self.getstatusbartext (STATUSBAR_MAIN)
        assert text == status, (text, status)
        return True
        
    def set_formula_pos(self, pos, status):
        '''Sets cursor position in formula and checks statusbar text'''
        assert self.setcursorposition (ENTRY_FORMULA, pos), pos
        assert self.activatetext (ENTRY_FORMULA)
        text = self.getstatusbartext (STATUSBAR_MAIN)
        assert text == status, (text, status)
        return True

class DlgBase (component):
    def __init__(self):
        component.__init__(self, self.DIALOG)
    
    @classmethod
    def open(cls):
        dlg = cls()
        assert dlg.waittillguiexist ()
        return dlg
    
    def close(self):
        assert self.click ('btnClose')
        return self.waittillguinotexist ()
    
    def yes(self):
        assert self.click ('btnYes')
        return self.waittillguinotexist ()
    
    def no(self):
        assert self.click ('btnNo')
        return self.waittillguinotexist ()
        

class DlgQuestion (DlgBase):
    DIALOG = "dlgQuestion"
    

class DlgPreferences (DlgBase):
    DIALOG = DIALOG_PREFERENCES
    
    def close(self, confirm):
        assert self.click ('btnClose')
        if confirm:
            dlgQuestion = DlgQuestion.open()
            assert dlgQuestion.yes()
        return self.waittillguinotexist ()
        
    
class DlgEditColors (DlgBase):
    DIALOG = DIALOG_EDIT_COLORS
    

def test_start_quit():
    '''Verify, that the app starts and some widgets exist'''
    Pybik = AppPybik.launch()
    assert Pybik.verifystatusbar (STATUSBAR_MAIN)
    assert Pybik.quit()


def test_bars_hide_show():
    Pybik = AppPybik.launch()
    
    #TODO
    #assert Pybik.verifystatusbarvisible(TOOLBAR_PLAY)
    #assert Pybik.selectmenuitem(MENU_PLAY_TOOLBAR)
    #assert not Pybik.verifystatusbarvisible(TOOLBAR_PLAY)
    
    assert Pybik.verifystatusbarvisible(STATUSBAR_MAIN)
    assert Pybik.selectmenuitem(MENU_STATUSBAR)
    assert not Pybik.verifystatusbarvisible(STATUSBAR_MAIN)
    
    assert Pybik.quit()


def test_set_pos():
    Pybik = AppPybik.launch()
    
    assert Pybik.set_formula('', 0, '0 / 0 moves')
    assert Pybik.set_formula('ffb', 0, '0 / 3 moves')
    assert Pybik.set_formula_pos(1, '1 / 3 moves')
    assert Pybik.set_formula_pos(3, '3 / 3 moves')
    assert Pybik.set_formula("llr'u2' b2", 0, '0 / 5 moves')
    assert Pybik.set_formula_pos(1, '1 / 5 moves')
    assert Pybik.set_formula_pos(2, '2 / 5 moves')
    assert Pybik.set_formula_pos(3, '3 / 5 moves')
    assert Pybik.set_formula_pos(4, '3 / 5 moves')
    assert Pybik.set_formula_pos(5, '4 / 5 moves')
    assert Pybik.set_formula_pos(6, '4 / 5 moves')
    assert Pybik.set_formula_pos(7, '4 / 5 moves')
    assert Pybik.set_formula_pos(8, '4 / 5 moves')
    assert Pybik.set_formula_pos(9, '5 / 5 moves')
    assert Pybik.set_formula_pos(10,'5 / 5 moves')
    assert Pybik.set_formula_pos(5, '4 / 5 moves')
    
    assert Pybik.quit()
    
    assert confstore.saved_moves == "llr'u2' b2", repr(confstore.saved_moves)
    assert confstore.saved_pos == 8, confstore.saved_pos
    

def test_set_dimension_from_config():
    raise SkipTest
    confstore.dimension = 3
    confstore.saved_state = 'Cube 4 identity:'
    confstore.saved_moves = ''
    
    Pybik = AppPybik.launch()
    assert Pybik.selectmenuitem (MENU_NEW_SOLVED)
    assert Pybik.quit()
    
    assert confstore.dimension == 3, confstore.dimension
    assert confstore.saved_state == 'Cube 3 identity:', repr(confstore.saved_state)
    assert confstore.saved_moves == '', repr(confstore.saved_moves)

def test_set_dimension_cmd():
    '''Set dimension from commandline'''
    confstore.dimension = 3
    confstore.saved_state = 'Cube 3 identity:'
    confstore.saved_moves = ''
    
    Pybik = AppPybik.launch('--size=4')
    assert Pybik.selectmenuitem (MENU_NEW_SOLVED)
    assert Pybik.quit()
    
    assert confstore.dimension == 3, confstore.dimension
    assert confstore.saved_state == 'Cube 3 identity:', repr(confstore.saved_state)
    assert confstore.saved_moves == '', repr(confstore.saved_moves)
    
def test_set_dimension_dlg():
    '''Set dimension with dialog'''
    confstore.dimension = 3
    confstore.saved_state = 'Cube 3 identity:'
    confstore.saved_moves = ''
    
    Pybik = AppPybik.launch()
    assert Pybik.selectmenuitem (MENU_NEW_SOLVED)
    
    assert Pybik.selectmenuitem (MENU_PREFERENCES)
    preferences = DlgPreferences.open()
    assert preferences.verifysetvalue(BUTTON_SIZE, 3)
    assert preferences.close(confirm=False)
    
    confstore.clear_cache()
    assert confstore.dimension == 3, confstore.dimension
    assert confstore.saved_state == 'Cube 3 identity:', repr(confstore.saved_state)
    assert confstore.saved_moves == '', repr(confstore.saved_moves)
    
    assert Pybik.selectmenuitem (MENU_PREFERENCES)
    preferences = DlgPreferences.open()
    assert preferences.verifysetvalue(BUTTON_SIZE, 3)
    assert preferences.setvalue(BUTTON_SIZE, 4)
    assert preferences.verifysetvalue(BUTTON_SIZE, 4)
    assert preferences.close(confirm=True)
    
    assert Pybik.quit()
    
    confstore.clear_cache()
    assert confstore.dimension == 4, confstore.dimension
    assert confstore.saved_state == 'Cube 4 identity:', repr(confstore.saved_state)
    assert confstore.saved_moves == '', repr(confstore.saved_moves)
    
def test_new_random():
    confstore.dimension = 3
    confstore.saved_state = 'Cube 3 identity:'
    confstore.saved_moves = ''
    
    Pybik = AppPybik.launch('--debug=0')
    assert Pybik.selectmenuitem (MENU_NEW_RANDOM)
    assert Pybik.quit()
    
    confstore.clear_cache()
    assert confstore.dimension == 3, confstore.dimension
    assert (confstore.saved_state == "Cube 3 blocks_compact: "
            "0,0,2,l 2,0,1,lu 0,2,0,uu 2,2,1,fll 1,1,0,u 2,1,2,ff 0,2,2,l 1,0,0,uu 2,0,0,f' "
            "2,1,0,fuu 1,0,1,ll 0,0,1,ll 0,1,1,f' 1,1,1, 2,1,1,f 1,2,0,l' 1,2,1,ll 1,0,2,ffl' "
            "2,0,2,l 0,1,2,f'u 2,2,2,u 1,2,2,u' 1,1,2,u 0,2,1,f'u 2,2,0,f'u' 0,1,0,ffu' 0,0,0,ffu'"
            ), repr(confstore.saved_state)
    assert confstore.saved_moves == '', repr(confstore.saved_moves)
    
def test_solver_mellor():
    raise SkipTest
    confstore.dimension = 3
    confstore.saved_state = 'Cube 3 identity:'
    confstore.saved_moves = ''
    
    Pybik = AppPybik.launch('--debug=0')
    assert Pybik.selectmenuitem (MENU_NEW_RANDOM)
    #assert Pybik.expandtablecell(TREEVIEW_SCRIPTS, 'Solvers')
    #assert Pybik.expandtablecell(TREEVIEW_SCRIPTS, 0)
    #assert Pybik.doubleclickrow(TREEVIEW_SCRIPTS, 'Mellor (3x3)')
    #assert Pybik.doesrowexist(TREEVIEW_SCRIPTS, 'Solvers', True)
    print Pybik.getrowcount(TREEVIEW_SCRIPTS)
    print Pybik.getcellvalue(TREEVIEW_SCRIPTS, 0,0)
    print Pybik.expandtablecell(TREEVIEW_SCRIPTS, 0)
    assert Pybik.doubleclickrow(TREEVIEW_SCRIPTS, 0)
    wait(1)
    assert Pybik.click(TOOLBUTTON_STOP)
    wait(3)
    assert Pybik.click(TOOLBUTTON_FORWARD)
    wait(1)
    assert Pybik.quit()
    
    confstore.clear_cache()
    assert confstore.dimension == 3, confstore.dimension
    assert confstore.saved_state == "Cube 3 identity:", repr(confstore.saved_state)
    assert confstore.saved_moves == '', repr(confstore.saved_moves)
    
if __name__ == '__main__':
    import nose
    nose.runmodule()