Merge lp:~jtatum/mago/gcalctool into lp:~mago-contributors/mago/mago-1.0
- gcalctool
- Merge into mago-1.0
Status: | Superseded |
---|---|
Proposed branch: | lp:~jtatum/mago/gcalctool |
Merge into: | lp:~mago-contributors/mago/mago-1.0 |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~jtatum/mago/gcalctool |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ara Pulido | Needs Fixing | ||
Review via email: mp+11431@code.launchpad.net |
This proposal has been superseded by a proposal from 2009-09-11.
Commit message
Description of the change
James Tatum (jtatum) wrote : | # |
- 116. By James Tatum
-
Fixing a couple of small mistakes
James Tatum (jtatum) wrote : | # |
Apologies to anyone who tried r115. There was a small typo in the suite code which broke most of the tests. Oops! r116 works properly.
Ara Pulido (ara) wrote : | # |
Hello James,
Excellent addition. I specially liked the way you solved the question of menus and buttons using lists.
Only a couple of comments:
In gcalctool_views.py and gcalctool_
Also, in gcalctool_views suite, you just check that the value has not changed. I don't think this is the correct thing to check. Indeed, it is also good to check that, it can be kept, but I would have also had checked things like:
* Buttons that only exist for that view, are now visible
* Window name has changed
Just some possible improvements to an overall very good job.
- 117. By James Tatum
-
Added tests to verify that specific buttons are showing/hidden in various views
- 118. By James Tatum
-
Remerging
- 119. By James Tatum
-
Merging from trunk
- 120. By James Tatum
-
Removing remap per Nagappan's suggestion
- 121. By James Tatum
-
Integrating the button test with the view change per JCollado's suggestion
- 122. By James Tatum
-
Merging from trunk
Unmerged revisions
Preview Diff
1 | === added directory 'gcalctool' | |||
2 | === added file 'gcalctool/README' | |||
3 | --- gcalctool/README 1970-01-01 00:00:00 +0000 | |||
4 | +++ gcalctool/README 2009-09-03 13:19:29 +0000 | |||
5 | @@ -0,0 +1,35 @@ | |||
6 | 1 | GCALCTOOL TESTS | ||
7 | 2 | ----------- | ||
8 | 3 | Tests that verify calculator functionality. | ||
9 | 4 | |||
10 | 5 | Safety | ||
11 | 6 | ------ | ||
12 | 7 | These tests will change the calculator's view, which is loaded at startup. | ||
13 | 8 | Otherwise, they are safe to run. | ||
14 | 9 | |||
15 | 10 | Configuration | ||
16 | 11 | ------------- | ||
17 | 12 | No configuration is needed | ||
18 | 13 | |||
19 | 14 | Version | ||
20 | 15 | ------- | ||
21 | 16 | Tests were updated for Ubuntu Karmic | ||
22 | 17 | |||
23 | 18 | Available Testsuites | ||
24 | 19 | -------------------- | ||
25 | 20 | |||
26 | 21 | * gcalctool views (testcases wiki: cal-001) | ||
27 | 22 | Tools that exercise the views in gcalctool | ||
28 | 23 | - Advanced | ||
29 | 24 | - Financial | ||
30 | 25 | - Scientific | ||
31 | 26 | - Programming | ||
32 | 27 | - Basic | ||
33 | 28 | * gcalctool calculations (testcases wiki: cal-002) | ||
34 | 29 | Tools that perform calculations in gcalctool and verify the results | ||
35 | 30 | - 3*4=12 | ||
36 | 31 | - Square root 9=3 | ||
37 | 32 | - 1+1=2 | ||
38 | 33 | - 10-2=8 | ||
39 | 34 | - 14/2=7 | ||
40 | 35 | - 5*6=30 | ||
41 | 0 | 36 | ||
42 | === added file 'gcalctool/gcalctool_calculations.py' | |||
43 | --- gcalctool/gcalctool_calculations.py 1970-01-01 00:00:00 +0000 | |||
44 | +++ gcalctool/gcalctool_calculations.py 2009-09-03 12:20:23 +0000 | |||
45 | @@ -0,0 +1,20 @@ | |||
46 | 1 | # -*- coding: utf-8 -*- | ||
47 | 2 | import os | ||
48 | 3 | from time import time, gmtime, strftime | ||
49 | 4 | |||
50 | 5 | from mago.test_suite.gnome import GCalctoolTestSuite | ||
51 | 6 | |||
52 | 7 | class GCalctoolCalculations(GCalctoolTestSuite): | ||
53 | 8 | def calculate(self, input, oracle, view='BASIC'): | ||
54 | 9 | if self.application.get_view() != view: | ||
55 | 10 | self.application.set_view(view) | ||
56 | 11 | self.application.push(input) | ||
57 | 12 | value = self.application.get_value() | ||
58 | 13 | if unicode(value) == unicode(oracle): | ||
59 | 14 | pass | ||
60 | 15 | else: | ||
61 | 16 | raise AssertionError, "Expected %s, calculator returned %s" % (oracle, value) | ||
62 | 17 | |||
63 | 18 | if __name__ == "__main__": | ||
64 | 19 | gcalctool_calculations_test = GCalctoolCalculations() | ||
65 | 20 | gcalctool_calculations_test.run() | ||
66 | 0 | 21 | ||
67 | === added file 'gcalctool/gcalctool_calculations.xml' | |||
68 | --- gcalctool/gcalctool_calculations.xml 1970-01-01 00:00:00 +0000 | |||
69 | +++ gcalctool/gcalctool_calculations.xml 2009-09-03 12:20:23 +0000 | |||
70 | @@ -0,0 +1,61 @@ | |||
71 | 1 | <?xml version="1.0"?> | ||
72 | 2 | <suite name="gcalctool calculations"> | ||
73 | 3 | <class>gcalctool_calculations.GCalctoolCalculations</class> | ||
74 | 4 | <description> | ||
75 | 5 | Tests that perform calculations and check the answer (cal-002) | ||
76 | 6 | </description> | ||
77 | 7 | <case name="1"> | ||
78 | 8 | <method>calculate</method> | ||
79 | 9 | <description>3*4=12</description> | ||
80 | 10 | <args> | ||
81 | 11 | <input>3*4=</input> | ||
82 | 12 | <oracle>12</oracle> | ||
83 | 13 | <view>BASIC</view> | ||
84 | 14 | </args> | ||
85 | 15 | </case> | ||
86 | 16 | <case name="2"> | ||
87 | 17 | <method>calculate</method> | ||
88 | 18 | <description>s9=3</description> | ||
89 | 19 | <args> | ||
90 | 20 | <input>Cs9=</input> | ||
91 | 21 | <oracle>3</oracle> | ||
92 | 22 | <view>ADVANCED</view> | ||
93 | 23 | </args> | ||
94 | 24 | </case> | ||
95 | 25 | <case name="3"> | ||
96 | 26 | <method>calculate</method> | ||
97 | 27 | <description>1+1=2</description> | ||
98 | 28 | <args> | ||
99 | 29 | <input>1+1=</input> | ||
100 | 30 | <oracle>2</oracle> | ||
101 | 31 | <view>ADVANCED</view> | ||
102 | 32 | </args> | ||
103 | 33 | </case> | ||
104 | 34 | <case name="4"> | ||
105 | 35 | <method>calculate</method> | ||
106 | 36 | <description>10-2=8</description> | ||
107 | 37 | <args> | ||
108 | 38 | <input>10-2=</input> | ||
109 | 39 | <oracle>8</oracle> | ||
110 | 40 | <view>PROGRAMMING</view> | ||
111 | 41 | </args> | ||
112 | 42 | </case> | ||
113 | 43 | <case name="5"> | ||
114 | 44 | <method>calculate</method> | ||
115 | 45 | <description>14/2=7</description> | ||
116 | 46 | <args> | ||
117 | 47 | <input>14/2=</input> | ||
118 | 48 | <oracle>7</oracle> | ||
119 | 49 | <view>FINANCIAL</view> | ||
120 | 50 | </args> | ||
121 | 51 | </case> | ||
122 | 52 | <case name="6"> | ||
123 | 53 | <method>calculate</method> | ||
124 | 54 | <description>5*6=30</description> | ||
125 | 55 | <args> | ||
126 | 56 | <input>5*6=</input> | ||
127 | 57 | <oracle>30</oracle> | ||
128 | 58 | <view>SCIENTIFIC</view> | ||
129 | 59 | </args> | ||
130 | 60 | </case> | ||
131 | 61 | </suite> | ||
132 | 0 | 62 | ||
133 | === added file 'gcalctool/gcalctool_views.py' | |||
134 | --- gcalctool/gcalctool_views.py 1970-01-01 00:00:00 +0000 | |||
135 | +++ gcalctool/gcalctool_views.py 2009-09-03 12:20:23 +0000 | |||
136 | @@ -0,0 +1,16 @@ | |||
137 | 1 | # -*- coding: utf-8 -*- | ||
138 | 2 | import os | ||
139 | 3 | from time import time, gmtime, strftime | ||
140 | 4 | |||
141 | 5 | from mago.test_suite.gnome import GCalctoolViewTestSuite | ||
142 | 6 | |||
143 | 7 | class GCalctoolViews(GCalctoolViewTestSuite): | ||
144 | 8 | def changeViews(self, view): | ||
145 | 9 | value = self.application.get_value() | ||
146 | 10 | self.application.set_view(view) | ||
147 | 11 | if value != self.application.get_value(): | ||
148 | 12 | raise AssertionError, "Displayed value changed upon changing views" | ||
149 | 13 | |||
150 | 14 | if __name__ == "__main__": | ||
151 | 15 | gcalctool_views_test = GCalctoolViews() | ||
152 | 16 | gcalctool_views_test.run() | ||
153 | 0 | 17 | ||
154 | === added file 'gcalctool/gcalctool_views.xml' | |||
155 | --- gcalctool/gcalctool_views.xml 1970-01-01 00:00:00 +0000 | |||
156 | +++ gcalctool/gcalctool_views.xml 2009-09-03 12:20:23 +0000 | |||
157 | @@ -0,0 +1,42 @@ | |||
158 | 1 | <?xml version="1.0"?> | ||
159 | 2 | <suite name="gcalctool views"> | ||
160 | 3 | <class>gcalctool_views.GCalctoolViews</class> | ||
161 | 4 | <description> | ||
162 | 5 | Tests that iterate through each calculator view (cal-001) | ||
163 | 6 | </description> | ||
164 | 7 | <case name="Advanced"> | ||
165 | 8 | <method>changeViews</method> | ||
166 | 9 | <description>Change to the 'advanced' view</description> | ||
167 | 10 | <args> | ||
168 | 11 | <view>ADVANCED</view> | ||
169 | 12 | </args> | ||
170 | 13 | </case> | ||
171 | 14 | <case name="Financial"> | ||
172 | 15 | <method>changeViews</method> | ||
173 | 16 | <description>Change to the 'financial' view</description> | ||
174 | 17 | <args> | ||
175 | 18 | <view>FINANCIAL</view> | ||
176 | 19 | </args> | ||
177 | 20 | </case> | ||
178 | 21 | <case name="Scientific"> | ||
179 | 22 | <method>changeViews</method> | ||
180 | 23 | <description>Change to the 'scientific' view</description> | ||
181 | 24 | <args> | ||
182 | 25 | <view>SCIENTIFIC</view> | ||
183 | 26 | </args> | ||
184 | 27 | </case> | ||
185 | 28 | <case name="Programming"> | ||
186 | 29 | <method>changeViews</method> | ||
187 | 30 | <description>Change to the 'programming' view</description> | ||
188 | 31 | <args> | ||
189 | 32 | <view>PROGRAMMING</view> | ||
190 | 33 | </args> | ||
191 | 34 | </case> | ||
192 | 35 | <case name="Basic"> | ||
193 | 36 | <method>changeViews</method> | ||
194 | 37 | <description>Change to the 'basic' view</description> | ||
195 | 38 | <args> | ||
196 | 39 | <view>BASIC</view> | ||
197 | 40 | </args> | ||
198 | 41 | </case> | ||
199 | 42 | </suite> | ||
200 | 0 | 43 | ||
201 | === modified file 'mago/application/gnome.py' | |||
202 | --- mago/application/gnome.py 2009-09-02 19:35:05 +0000 | |||
203 | +++ mago/application/gnome.py 2009-09-08 13:29:58 +0000 | |||
204 | @@ -6,6 +6,167 @@ | |||
205 | 6 | import ooldtp | 6 | import ooldtp |
206 | 7 | import ldtp | 7 | import ldtp |
207 | 8 | from .main import Application | 8 | from .main import Application |
208 | 9 | from ..gconfwrapper import GConf | ||
209 | 10 | import time | ||
210 | 11 | |||
211 | 12 | class Calculator(Application): | ||
212 | 13 | """ | ||
213 | 14 | The Calculator class contains methods for exercising the gcalctool application | ||
214 | 15 | """ | ||
215 | 16 | LAUNCHER = "gcalctool" | ||
216 | 17 | WINDOW = "frmCalculator" | ||
217 | 18 | WINDOW_ADVANCED = "frmCalculator-Advanced" | ||
218 | 19 | WINDOW_FINANCIAL = "frmCalculator-Financial" | ||
219 | 20 | WINDOW_SCIENTIFIC = "frmCalculator-Scientific" | ||
220 | 21 | WINDOW_PROGRAMMING = "frmCalculator-Programming" | ||
221 | 22 | MNU_BASIC = "mnuBasic" | ||
222 | 23 | MNU_ADVANCED = "mnuAdvanced" | ||
223 | 24 | MNU_FINANCIAL = "mnuFinancial" | ||
224 | 25 | MNU_SCIENTIFIC = "mnuScientific" | ||
225 | 26 | MNU_PROGRAMMING = "mnuProgramming" | ||
226 | 27 | VIEWS = {"BASIC" : {"WINDOW" : WINDOW, | ||
227 | 28 | "MENU" : MNU_BASIC}, | ||
228 | 29 | "ADVANCED" : {"WINDOW" : WINDOW_ADVANCED, | ||
229 | 30 | "MENU" : MNU_ADVANCED}, | ||
230 | 31 | "FINANCIAL" : {"WINDOW" : WINDOW_FINANCIAL, | ||
231 | 32 | "MENU" : MNU_FINANCIAL}, | ||
232 | 33 | "SCIENTIFIC" : {"WINDOW" : WINDOW_SCIENTIFIC, | ||
233 | 34 | "MENU" : MNU_SCIENTIFIC}, | ||
234 | 35 | "PROGRAMMING" : {"WINDOW" : WINDOW_PROGRAMMING, | ||
235 | 36 | "MENU" : MNU_PROGRAMMING}} | ||
236 | 37 | BUTTONS = {"0" : "Numeric 0", | ||
237 | 38 | "1" : "Numeric 1", | ||
238 | 39 | "2" : "Numeric 2", | ||
239 | 40 | "3" : "Numeric 3", | ||
240 | 41 | "4" : "Numeric 4", | ||
241 | 42 | "5" : "Numeric 5", | ||
242 | 43 | "6" : "Numeric 6", | ||
243 | 44 | "7" : "Numeric 7", | ||
244 | 45 | "8" : "Numeric 8", | ||
245 | 46 | "9" : "Numeric 9", | ||
246 | 47 | "=" : "Calculate result", | ||
247 | 48 | "+" : "Add", | ||
248 | 49 | "-" : "Subtract", | ||
249 | 50 | "*" : "Multiply", | ||
250 | 51 | "/" : "Divide", | ||
251 | 52 | "c" : "Clear entry", | ||
252 | 53 | "C" : "Clear", | ||
253 | 54 | "." : "Numeric point", | ||
254 | 55 | "@" : "Square", | ||
255 | 56 | "s" : "Square root"} | ||
256 | 57 | EDITBAR_ROLE = "edit bar" | ||
257 | 58 | EDITBAR_INDEX = 0 | ||
258 | 59 | SLEEP_DELAY = 2 | ||
259 | 60 | GCONF_MODE_KEY = "/apps/gcalctool/mode" | ||
260 | 61 | GCONF_MODE_VAL = "BASIC" | ||
261 | 62 | |||
262 | 63 | def __init__(self): | ||
263 | 64 | Application.__init__(self) | ||
264 | 65 | |||
265 | 66 | def open(self): | ||
266 | 67 | """ | ||
267 | 68 | Opens the application | ||
268 | 69 | """ | ||
269 | 70 | try: | ||
270 | 71 | GConf.set_item(self.GCONF_MODE_KEY, self.GCONF_MODE_VAL) | ||
271 | 72 | except GConf.GConfError: | ||
272 | 73 | raise ldtp.LdtpExecutionError, "Could not set default view in gconf" | ||
273 | 74 | Application.open(self) | ||
274 | 75 | |||
275 | 76 | def push(self, buttons): | ||
276 | 77 | """ | ||
277 | 78 | Push the specified buttons in the calculator window. | ||
278 | 79 | |||
279 | 80 | >>> c = Calculator() | ||
280 | 81 | >>> c.open() | ||
281 | 82 | >>> c.push('2+2=') | ||
282 | 83 | |||
283 | 84 | @param buttons: Specify the buttons to push. | ||
284 | 85 | @type buttons: string | ||
285 | 86 | """ | ||
286 | 87 | calculator = ooldtp.context(self.name) | ||
287 | 88 | for button in buttons: | ||
288 | 89 | try: | ||
289 | 90 | # The calculator has some buttons with the same names that are | ||
290 | 91 | # hidden depending on the view. | ||
291 | 92 | children = calculator.getchild(self.BUTTONS[button],'push button') | ||
292 | 93 | for child in children: | ||
293 | 94 | childName=child.getName() | ||
294 | 95 | if calculator.hasstate(childName, ldtp.state.SHOWING): | ||
295 | 96 | calculator.click(childName) | ||
296 | 97 | break | ||
297 | 98 | else: | ||
298 | 99 | raise LookupError, "Could not find button %s in current view" % button | ||
299 | 100 | except ldtp.LdtpExecutionError: | ||
300 | 101 | raise ldtp.LdtpExecutionError, "Error clicking button %s" % button | ||
301 | 102 | |||
302 | 103 | def get_view(self): | ||
303 | 104 | """ | ||
304 | 105 | Get the current view of the calculator. | ||
305 | 106 | |||
306 | 107 | >>> c = Calculator() | ||
307 | 108 | >>> c.open() | ||
308 | 109 | >>> c.get_view() | ||
309 | 110 | 'BASIC' | ||
310 | 111 | |||
311 | 112 | @return: The current view: BASIC, ADVANCED, FINANCIAL, SCIENTIFIC, | ||
312 | 113 | or PROGRAMMING | ||
313 | 114 | @rtype: string | ||
314 | 115 | """ | ||
315 | 116 | windowname = self.name | ||
316 | 117 | for view in self.VIEWS: | ||
317 | 118 | if self.VIEWS[view]['WINDOW'] == windowname: | ||
318 | 119 | return view | ||
319 | 120 | raise LookupError, "Could not identify the current calculator view" | ||
320 | 121 | |||
321 | 122 | def set_view(self, new_view): | ||
322 | 123 | """ | ||
323 | 124 | Change to the specified view in the calculator | ||
324 | 125 | |||
325 | 126 | >>> c = Calculator() | ||
326 | 127 | >>> c.open() | ||
327 | 128 | >>> c.set_view('ADVANCED') | ||
328 | 129 | |||
329 | 130 | @param new_view: Specify the new view. Valid values are: | ||
330 | 131 | BASIC, ADVANCED, FINANCIAL, SCIENTIFIC, PROGRAMMING | ||
331 | 132 | @type new_view: string | ||
332 | 133 | """ | ||
333 | 134 | new_window_name = self.VIEWS[new_view]["WINDOW"] | ||
334 | 135 | new_view_menu_name = self.VIEWS[new_view]["MENU"] | ||
335 | 136 | calculator = ooldtp.context(self.name) | ||
336 | 137 | try: | ||
337 | 138 | mnu_new_view = calculator.getchild(new_view_menu_name) | ||
338 | 139 | except ldtp.LdtpExecutionError: | ||
339 | 140 | raise ldtp.LdtpExecutionError, "The menu item for the requested view was not found." | ||
340 | 141 | |||
341 | 142 | try: | ||
342 | 143 | mnu_new_view.selectmenuitem() | ||
343 | 144 | except ldtp.LdtpExecutionError: | ||
344 | 145 | raise ldtp.LdtpExecutionError, "There was a problem changing views." | ||
345 | 146 | self.set_name(new_window_name) | ||
346 | 147 | time.sleep(self.SLEEP_DELAY) # need to give mago some time to catch up to calc ui | ||
347 | 148 | self.remap # tell mago about the new frm name and remap everything | ||
348 | 149 | |||
349 | 150 | def get_value(self): | ||
350 | 151 | """ | ||
351 | 152 | Read the value from the calculator screen | ||
352 | 153 | |||
353 | 154 | >>> c = Calculator() | ||
354 | 155 | >>> c.open() | ||
355 | 156 | >>> c.push('2+2=') | ||
356 | 157 | >>> c.get_value() | ||
357 | 158 | u'4' | ||
358 | 159 | |||
359 | 160 | @return: The contents of the calculator's screen | ||
360 | 161 | @rtype: string | ||
361 | 162 | """ | ||
362 | 163 | calculator = ooldtp.context(self.name) | ||
363 | 164 | try: | ||
364 | 165 | editBar = calculator.getchild('txtResultRegion') # txtResultRegion | ||
365 | 166 | value = editBar.gettextvalue() | ||
366 | 167 | except ldtp.LdtpExecutionError: | ||
367 | 168 | raise ldtp.LdtpExecutionError, "There was a problem reading the value." | ||
368 | 169 | return value | ||
369 | 9 | 170 | ||
370 | 10 | class GnomeScreenshot(Application): | 171 | class GnomeScreenshot(Application): |
371 | 11 | """ | 172 | """ |
372 | @@ -252,7 +413,6 @@ | |||
373 | 252 | except ldtp.LdtpExecutionError: | 413 | except ldtp.LdtpExecutionError: |
374 | 253 | raise ldtp.LdtpExecutionError, "Window " + self.SAVE_FILE_WINDOW + " did not go away" | 414 | raise ldtp.LdtpExecutionError, "Window " + self.SAVE_FILE_WINDOW + " did not go away" |
375 | 254 | 415 | ||
376 | 255 | |||
377 | 256 | class Seahorse(Application): | 416 | class Seahorse(Application): |
378 | 257 | """ | 417 | """ |
379 | 258 | Seahorse manages the Seahorse application. | 418 | Seahorse manages the Seahorse application. |
380 | 259 | 419 | ||
381 | === modified file 'mago/test_suite/gnome.py' | |||
382 | --- mago/test_suite/gnome.py 2009-08-25 18:33:48 +0000 | |||
383 | +++ mago/test_suite/gnome.py 2009-09-08 13:29:58 +0000 | |||
384 | @@ -4,7 +4,27 @@ | |||
385 | 4 | """ | 4 | """ |
386 | 5 | import ldtp, ooldtp | 5 | import ldtp, ooldtp |
387 | 6 | from .main import SingleApplicationTestSuite | 6 | from .main import SingleApplicationTestSuite |
389 | 7 | from ..application.gnome import Application, GnomeScreenshot, Seahorse, GEdit | 7 | from ..application.gnome import Application, Seahorse, GEdit, GnomeScreenshot, Calculator |
390 | 8 | |||
391 | 9 | class GCalctoolTestSuite(SingleApplicationTestSuite): | ||
392 | 10 | """ | ||
393 | 11 | Default test suite for Calculator | ||
394 | 12 | """ | ||
395 | 13 | APPLICATION_FACTORY = Calculator | ||
396 | 14 | def setup(self): | ||
397 | 15 | self.application.open() | ||
398 | 16 | self.application.push("C") | ||
399 | 17 | |||
400 | 18 | def teardown(self): | ||
401 | 19 | self.application.close() | ||
402 | 20 | |||
403 | 21 | class GCalctoolViewTestSuite(GCalctoolTestSuite): | ||
404 | 22 | """ | ||
405 | 23 | Test suite for views populates the screen with some data in setup | ||
406 | 24 | """ | ||
407 | 25 | def setup(self): | ||
408 | 26 | GCalctoolTestSuite.setup(self) | ||
409 | 27 | self.application.push("13.37") | ||
410 | 8 | 28 | ||
411 | 9 | class GnomeScreenshotTestSuite(SingleApplicationTestSuite): | 29 | class GnomeScreenshotTestSuite(SingleApplicationTestSuite): |
412 | 10 | APPLICATION_FACTORY = GnomeScreenshot | 30 | APPLICATION_FACTORY = GnomeScreenshot |
Adding tests for gcalctool