Merge lp:~jtatum/mago/gcalctool into lp:~mago-contributors/mago/mago-1.0

Proposed by James Tatum
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
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.

To post a comment you must log in.
Revision history for this message
James Tatum (jtatum) wrote :

Adding tests for gcalctool

lp:~jtatum/mago/gcalctool updated
116. By James Tatum

Fixing a couple of small mistakes

Revision history for this message
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.

Revision history for this message
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_calculations.py you seemed to haved copypasted the skeleton from gedit_chains.py, and added an import (time, sfrtime...) not needed in these cases (minor issue, really).

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.

review: Needs Fixing
lp:~jtatum/mago/gcalctool updated
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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+GCALCTOOL TESTS
7+-----------
8+Tests that verify calculator functionality.
9+
10+Safety
11+------
12+These tests will change the calculator's view, which is loaded at startup.
13+Otherwise, they are safe to run.
14+
15+Configuration
16+-------------
17+No configuration is needed
18+
19+Version
20+-------
21+Tests were updated for Ubuntu Karmic
22+
23+Available Testsuites
24+--------------------
25+
26+* gcalctool views (testcases wiki: cal-001)
27+ Tools that exercise the views in gcalctool
28+ - Advanced
29+ - Financial
30+ - Scientific
31+ - Programming
32+ - Basic
33+* gcalctool calculations (testcases wiki: cal-002)
34+ Tools that perform calculations in gcalctool and verify the results
35+ - 3*4=12
36+ - Square root 9=3
37+ - 1+1=2
38+ - 10-2=8
39+ - 14/2=7
40+ - 5*6=30
41
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+# -*- coding: utf-8 -*-
47+import os
48+from time import time, gmtime, strftime
49+
50+from mago.test_suite.gnome import GCalctoolTestSuite
51+
52+class GCalctoolCalculations(GCalctoolTestSuite):
53+ def calculate(self, input, oracle, view='BASIC'):
54+ if self.application.get_view() != view:
55+ self.application.set_view(view)
56+ self.application.push(input)
57+ value = self.application.get_value()
58+ if unicode(value) == unicode(oracle):
59+ pass
60+ else:
61+ raise AssertionError, "Expected %s, calculator returned %s" % (oracle, value)
62+
63+if __name__ == "__main__":
64+ gcalctool_calculations_test = GCalctoolCalculations()
65+ gcalctool_calculations_test.run()
66
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+<?xml version="1.0"?>
72+<suite name="gcalctool calculations">
73+ <class>gcalctool_calculations.GCalctoolCalculations</class>
74+ <description>
75+ Tests that perform calculations and check the answer (cal-002)
76+ </description>
77+ <case name="1">
78+ <method>calculate</method>
79+ <description>3*4=12</description>
80+ <args>
81+ <input>3*4=</input>
82+ <oracle>12</oracle>
83+ <view>BASIC</view>
84+ </args>
85+ </case>
86+ <case name="2">
87+ <method>calculate</method>
88+ <description>s9=3</description>
89+ <args>
90+ <input>Cs9=</input>
91+ <oracle>3</oracle>
92+ <view>ADVANCED</view>
93+ </args>
94+ </case>
95+ <case name="3">
96+ <method>calculate</method>
97+ <description>1+1=2</description>
98+ <args>
99+ <input>1+1=</input>
100+ <oracle>2</oracle>
101+ <view>ADVANCED</view>
102+ </args>
103+ </case>
104+ <case name="4">
105+ <method>calculate</method>
106+ <description>10-2=8</description>
107+ <args>
108+ <input>10-2=</input>
109+ <oracle>8</oracle>
110+ <view>PROGRAMMING</view>
111+ </args>
112+ </case>
113+ <case name="5">
114+ <method>calculate</method>
115+ <description>14/2=7</description>
116+ <args>
117+ <input>14/2=</input>
118+ <oracle>7</oracle>
119+ <view>FINANCIAL</view>
120+ </args>
121+ </case>
122+ <case name="6">
123+ <method>calculate</method>
124+ <description>5*6=30</description>
125+ <args>
126+ <input>5*6=</input>
127+ <oracle>30</oracle>
128+ <view>SCIENTIFIC</view>
129+ </args>
130+ </case>
131+</suite>
132
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+# -*- coding: utf-8 -*-
138+import os
139+from time import time, gmtime, strftime
140+
141+from mago.test_suite.gnome import GCalctoolViewTestSuite
142+
143+class GCalctoolViews(GCalctoolViewTestSuite):
144+ def changeViews(self, view):
145+ value = self.application.get_value()
146+ self.application.set_view(view)
147+ if value != self.application.get_value():
148+ raise AssertionError, "Displayed value changed upon changing views"
149+
150+if __name__ == "__main__":
151+ gcalctool_views_test = GCalctoolViews()
152+ gcalctool_views_test.run()
153
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+<?xml version="1.0"?>
159+<suite name="gcalctool views">
160+ <class>gcalctool_views.GCalctoolViews</class>
161+ <description>
162+ Tests that iterate through each calculator view (cal-001)
163+ </description>
164+ <case name="Advanced">
165+ <method>changeViews</method>
166+ <description>Change to the 'advanced' view</description>
167+ <args>
168+ <view>ADVANCED</view>
169+ </args>
170+ </case>
171+ <case name="Financial">
172+ <method>changeViews</method>
173+ <description>Change to the 'financial' view</description>
174+ <args>
175+ <view>FINANCIAL</view>
176+ </args>
177+ </case>
178+ <case name="Scientific">
179+ <method>changeViews</method>
180+ <description>Change to the 'scientific' view</description>
181+ <args>
182+ <view>SCIENTIFIC</view>
183+ </args>
184+ </case>
185+ <case name="Programming">
186+ <method>changeViews</method>
187+ <description>Change to the 'programming' view</description>
188+ <args>
189+ <view>PROGRAMMING</view>
190+ </args>
191+ </case>
192+ <case name="Basic">
193+ <method>changeViews</method>
194+ <description>Change to the 'basic' view</description>
195+ <args>
196+ <view>BASIC</view>
197+ </args>
198+ </case>
199+</suite>
200
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 import ooldtp
206 import ldtp
207 from .main import Application
208+from ..gconfwrapper import GConf
209+import time
210+
211+class Calculator(Application):
212+ """
213+ The Calculator class contains methods for exercising the gcalctool application
214+ """
215+ LAUNCHER = "gcalctool"
216+ WINDOW = "frmCalculator"
217+ WINDOW_ADVANCED = "frmCalculator-Advanced"
218+ WINDOW_FINANCIAL = "frmCalculator-Financial"
219+ WINDOW_SCIENTIFIC = "frmCalculator-Scientific"
220+ WINDOW_PROGRAMMING = "frmCalculator-Programming"
221+ MNU_BASIC = "mnuBasic"
222+ MNU_ADVANCED = "mnuAdvanced"
223+ MNU_FINANCIAL = "mnuFinancial"
224+ MNU_SCIENTIFIC = "mnuScientific"
225+ MNU_PROGRAMMING = "mnuProgramming"
226+ VIEWS = {"BASIC" : {"WINDOW" : WINDOW,
227+ "MENU" : MNU_BASIC},
228+ "ADVANCED" : {"WINDOW" : WINDOW_ADVANCED,
229+ "MENU" : MNU_ADVANCED},
230+ "FINANCIAL" : {"WINDOW" : WINDOW_FINANCIAL,
231+ "MENU" : MNU_FINANCIAL},
232+ "SCIENTIFIC" : {"WINDOW" : WINDOW_SCIENTIFIC,
233+ "MENU" : MNU_SCIENTIFIC},
234+ "PROGRAMMING" : {"WINDOW" : WINDOW_PROGRAMMING,
235+ "MENU" : MNU_PROGRAMMING}}
236+ BUTTONS = {"0" : "Numeric 0",
237+ "1" : "Numeric 1",
238+ "2" : "Numeric 2",
239+ "3" : "Numeric 3",
240+ "4" : "Numeric 4",
241+ "5" : "Numeric 5",
242+ "6" : "Numeric 6",
243+ "7" : "Numeric 7",
244+ "8" : "Numeric 8",
245+ "9" : "Numeric 9",
246+ "=" : "Calculate result",
247+ "+" : "Add",
248+ "-" : "Subtract",
249+ "*" : "Multiply",
250+ "/" : "Divide",
251+ "c" : "Clear entry",
252+ "C" : "Clear",
253+ "." : "Numeric point",
254+ "@" : "Square",
255+ "s" : "Square root"}
256+ EDITBAR_ROLE = "edit bar"
257+ EDITBAR_INDEX = 0
258+ SLEEP_DELAY = 2
259+ GCONF_MODE_KEY = "/apps/gcalctool/mode"
260+ GCONF_MODE_VAL = "BASIC"
261+
262+ def __init__(self):
263+ Application.__init__(self)
264+
265+ def open(self):
266+ """
267+ Opens the application
268+ """
269+ try:
270+ GConf.set_item(self.GCONF_MODE_KEY, self.GCONF_MODE_VAL)
271+ except GConf.GConfError:
272+ raise ldtp.LdtpExecutionError, "Could not set default view in gconf"
273+ Application.open(self)
274+
275+ def push(self, buttons):
276+ """
277+ Push the specified buttons in the calculator window.
278+
279+ >>> c = Calculator()
280+ >>> c.open()
281+ >>> c.push('2+2=')
282+
283+ @param buttons: Specify the buttons to push.
284+ @type buttons: string
285+ """
286+ calculator = ooldtp.context(self.name)
287+ for button in buttons:
288+ try:
289+ # The calculator has some buttons with the same names that are
290+ # hidden depending on the view.
291+ children = calculator.getchild(self.BUTTONS[button],'push button')
292+ for child in children:
293+ childName=child.getName()
294+ if calculator.hasstate(childName, ldtp.state.SHOWING):
295+ calculator.click(childName)
296+ break
297+ else:
298+ raise LookupError, "Could not find button %s in current view" % button
299+ except ldtp.LdtpExecutionError:
300+ raise ldtp.LdtpExecutionError, "Error clicking button %s" % button
301+
302+ def get_view(self):
303+ """
304+ Get the current view of the calculator.
305+
306+ >>> c = Calculator()
307+ >>> c.open()
308+ >>> c.get_view()
309+ 'BASIC'
310+
311+ @return: The current view: BASIC, ADVANCED, FINANCIAL, SCIENTIFIC,
312+ or PROGRAMMING
313+ @rtype: string
314+ """
315+ windowname = self.name
316+ for view in self.VIEWS:
317+ if self.VIEWS[view]['WINDOW'] == windowname:
318+ return view
319+ raise LookupError, "Could not identify the current calculator view"
320+
321+ def set_view(self, new_view):
322+ """
323+ Change to the specified view in the calculator
324+
325+ >>> c = Calculator()
326+ >>> c.open()
327+ >>> c.set_view('ADVANCED')
328+
329+ @param new_view: Specify the new view. Valid values are:
330+ BASIC, ADVANCED, FINANCIAL, SCIENTIFIC, PROGRAMMING
331+ @type new_view: string
332+ """
333+ new_window_name = self.VIEWS[new_view]["WINDOW"]
334+ new_view_menu_name = self.VIEWS[new_view]["MENU"]
335+ calculator = ooldtp.context(self.name)
336+ try:
337+ mnu_new_view = calculator.getchild(new_view_menu_name)
338+ except ldtp.LdtpExecutionError:
339+ raise ldtp.LdtpExecutionError, "The menu item for the requested view was not found."
340+
341+ try:
342+ mnu_new_view.selectmenuitem()
343+ except ldtp.LdtpExecutionError:
344+ raise ldtp.LdtpExecutionError, "There was a problem changing views."
345+ self.set_name(new_window_name)
346+ time.sleep(self.SLEEP_DELAY) # need to give mago some time to catch up to calc ui
347+ self.remap # tell mago about the new frm name and remap everything
348+
349+ def get_value(self):
350+ """
351+ Read the value from the calculator screen
352+
353+ >>> c = Calculator()
354+ >>> c.open()
355+ >>> c.push('2+2=')
356+ >>> c.get_value()
357+ u'4'
358+
359+ @return: The contents of the calculator's screen
360+ @rtype: string
361+ """
362+ calculator = ooldtp.context(self.name)
363+ try:
364+ editBar = calculator.getchild('txtResultRegion') # txtResultRegion
365+ value = editBar.gettextvalue()
366+ except ldtp.LdtpExecutionError:
367+ raise ldtp.LdtpExecutionError, "There was a problem reading the value."
368+ return value
369
370 class GnomeScreenshot(Application):
371 """
372@@ -252,7 +413,6 @@
373 except ldtp.LdtpExecutionError:
374 raise ldtp.LdtpExecutionError, "Window " + self.SAVE_FILE_WINDOW + " did not go away"
375
376-
377 class Seahorse(Application):
378 """
379 Seahorse manages the Seahorse application.
380
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 """
386 import ldtp, ooldtp
387 from .main import SingleApplicationTestSuite
388-from ..application.gnome import Application, GnomeScreenshot, Seahorse, GEdit
389+from ..application.gnome import Application, Seahorse, GEdit, GnomeScreenshot, Calculator
390+
391+class GCalctoolTestSuite(SingleApplicationTestSuite):
392+ """
393+ Default test suite for Calculator
394+ """
395+ APPLICATION_FACTORY = Calculator
396+ def setup(self):
397+ self.application.open()
398+ self.application.push("C")
399+
400+ def teardown(self):
401+ self.application.close()
402+
403+class GCalctoolViewTestSuite(GCalctoolTestSuite):
404+ """
405+ Test suite for views populates the screen with some data in setup
406+ """
407+ def setup(self):
408+ GCalctoolTestSuite.setup(self)
409+ self.application.push("13.37")
410
411 class GnomeScreenshotTestSuite(SingleApplicationTestSuite):
412 APPLICATION_FACTORY = GnomeScreenshot

Subscribers

People subscribed via source and target branches

to status/vote changes: