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
=== added directory 'gcalctool'
=== added file 'gcalctool/README'
--- gcalctool/README 1970-01-01 00:00:00 +0000
+++ gcalctool/README 2009-09-03 13:19:29 +0000
@@ -0,0 +1,35 @@
1GCALCTOOL TESTS
2-----------
3Tests that verify calculator functionality.
4
5Safety
6------
7These tests will change the calculator's view, which is loaded at startup.
8Otherwise, they are safe to run.
9
10Configuration
11-------------
12No configuration is needed
13
14Version
15-------
16Tests were updated for Ubuntu Karmic
17
18Available Testsuites
19--------------------
20
21* gcalctool views (testcases wiki: cal-001)
22 Tools that exercise the views in gcalctool
23 - Advanced
24 - Financial
25 - Scientific
26 - Programming
27 - Basic
28* gcalctool calculations (testcases wiki: cal-002)
29 Tools that perform calculations in gcalctool and verify the results
30 - 3*4=12
31 - Square root 9=3
32 - 1+1=2
33 - 10-2=8
34 - 14/2=7
35 - 5*6=30
036
=== added file 'gcalctool/gcalctool_calculations.py'
--- gcalctool/gcalctool_calculations.py 1970-01-01 00:00:00 +0000
+++ gcalctool/gcalctool_calculations.py 2009-09-03 12:20:23 +0000
@@ -0,0 +1,20 @@
1# -*- coding: utf-8 -*-
2import os
3from time import time, gmtime, strftime
4
5from mago.test_suite.gnome import GCalctoolTestSuite
6
7class GCalctoolCalculations(GCalctoolTestSuite):
8 def calculate(self, input, oracle, view='BASIC'):
9 if self.application.get_view() != view:
10 self.application.set_view(view)
11 self.application.push(input)
12 value = self.application.get_value()
13 if unicode(value) == unicode(oracle):
14 pass
15 else:
16 raise AssertionError, "Expected %s, calculator returned %s" % (oracle, value)
17
18if __name__ == "__main__":
19 gcalctool_calculations_test = GCalctoolCalculations()
20 gcalctool_calculations_test.run()
021
=== added file 'gcalctool/gcalctool_calculations.xml'
--- gcalctool/gcalctool_calculations.xml 1970-01-01 00:00:00 +0000
+++ gcalctool/gcalctool_calculations.xml 2009-09-03 12:20:23 +0000
@@ -0,0 +1,61 @@
1<?xml version="1.0"?>
2<suite name="gcalctool calculations">
3 <class>gcalctool_calculations.GCalctoolCalculations</class>
4 <description>
5 Tests that perform calculations and check the answer (cal-002)
6 </description>
7 <case name="1">
8 <method>calculate</method>
9 <description>3*4=12</description>
10 <args>
11 <input>3*4=</input>
12 <oracle>12</oracle>
13 <view>BASIC</view>
14 </args>
15 </case>
16 <case name="2">
17 <method>calculate</method>
18 <description>s9=3</description>
19 <args>
20 <input>Cs9=</input>
21 <oracle>3</oracle>
22 <view>ADVANCED</view>
23 </args>
24 </case>
25 <case name="3">
26 <method>calculate</method>
27 <description>1+1=2</description>
28 <args>
29 <input>1+1=</input>
30 <oracle>2</oracle>
31 <view>ADVANCED</view>
32 </args>
33 </case>
34 <case name="4">
35 <method>calculate</method>
36 <description>10-2=8</description>
37 <args>
38 <input>10-2=</input>
39 <oracle>8</oracle>
40 <view>PROGRAMMING</view>
41 </args>
42 </case>
43 <case name="5">
44 <method>calculate</method>
45 <description>14/2=7</description>
46 <args>
47 <input>14/2=</input>
48 <oracle>7</oracle>
49 <view>FINANCIAL</view>
50 </args>
51 </case>
52 <case name="6">
53 <method>calculate</method>
54 <description>5*6=30</description>
55 <args>
56 <input>5*6=</input>
57 <oracle>30</oracle>
58 <view>SCIENTIFIC</view>
59 </args>
60 </case>
61</suite>
062
=== added file 'gcalctool/gcalctool_views.py'
--- gcalctool/gcalctool_views.py 1970-01-01 00:00:00 +0000
+++ gcalctool/gcalctool_views.py 2009-09-03 12:20:23 +0000
@@ -0,0 +1,16 @@
1# -*- coding: utf-8 -*-
2import os
3from time import time, gmtime, strftime
4
5from mago.test_suite.gnome import GCalctoolViewTestSuite
6
7class GCalctoolViews(GCalctoolViewTestSuite):
8 def changeViews(self, view):
9 value = self.application.get_value()
10 self.application.set_view(view)
11 if value != self.application.get_value():
12 raise AssertionError, "Displayed value changed upon changing views"
13
14if __name__ == "__main__":
15 gcalctool_views_test = GCalctoolViews()
16 gcalctool_views_test.run()
017
=== added file 'gcalctool/gcalctool_views.xml'
--- gcalctool/gcalctool_views.xml 1970-01-01 00:00:00 +0000
+++ gcalctool/gcalctool_views.xml 2009-09-03 12:20:23 +0000
@@ -0,0 +1,42 @@
1<?xml version="1.0"?>
2<suite name="gcalctool views">
3 <class>gcalctool_views.GCalctoolViews</class>
4 <description>
5 Tests that iterate through each calculator view (cal-001)
6 </description>
7 <case name="Advanced">
8 <method>changeViews</method>
9 <description>Change to the 'advanced' view</description>
10 <args>
11 <view>ADVANCED</view>
12 </args>
13 </case>
14 <case name="Financial">
15 <method>changeViews</method>
16 <description>Change to the 'financial' view</description>
17 <args>
18 <view>FINANCIAL</view>
19 </args>
20 </case>
21 <case name="Scientific">
22 <method>changeViews</method>
23 <description>Change to the 'scientific' view</description>
24 <args>
25 <view>SCIENTIFIC</view>
26 </args>
27 </case>
28 <case name="Programming">
29 <method>changeViews</method>
30 <description>Change to the 'programming' view</description>
31 <args>
32 <view>PROGRAMMING</view>
33 </args>
34 </case>
35 <case name="Basic">
36 <method>changeViews</method>
37 <description>Change to the 'basic' view</description>
38 <args>
39 <view>BASIC</view>
40 </args>
41 </case>
42</suite>
043
=== modified file 'mago/application/gnome.py'
--- mago/application/gnome.py 2009-09-02 19:35:05 +0000
+++ mago/application/gnome.py 2009-09-08 13:29:58 +0000
@@ -6,6 +6,167 @@
6import ooldtp6import ooldtp
7import ldtp7import ldtp
8from .main import Application8from .main import Application
9from ..gconfwrapper import GConf
10import time
11
12class Calculator(Application):
13 """
14 The Calculator class contains methods for exercising the gcalctool application
15 """
16 LAUNCHER = "gcalctool"
17 WINDOW = "frmCalculator"
18 WINDOW_ADVANCED = "frmCalculator-Advanced"
19 WINDOW_FINANCIAL = "frmCalculator-Financial"
20 WINDOW_SCIENTIFIC = "frmCalculator-Scientific"
21 WINDOW_PROGRAMMING = "frmCalculator-Programming"
22 MNU_BASIC = "mnuBasic"
23 MNU_ADVANCED = "mnuAdvanced"
24 MNU_FINANCIAL = "mnuFinancial"
25 MNU_SCIENTIFIC = "mnuScientific"
26 MNU_PROGRAMMING = "mnuProgramming"
27 VIEWS = {"BASIC" : {"WINDOW" : WINDOW,
28 "MENU" : MNU_BASIC},
29 "ADVANCED" : {"WINDOW" : WINDOW_ADVANCED,
30 "MENU" : MNU_ADVANCED},
31 "FINANCIAL" : {"WINDOW" : WINDOW_FINANCIAL,
32 "MENU" : MNU_FINANCIAL},
33 "SCIENTIFIC" : {"WINDOW" : WINDOW_SCIENTIFIC,
34 "MENU" : MNU_SCIENTIFIC},
35 "PROGRAMMING" : {"WINDOW" : WINDOW_PROGRAMMING,
36 "MENU" : MNU_PROGRAMMING}}
37 BUTTONS = {"0" : "Numeric 0",
38 "1" : "Numeric 1",
39 "2" : "Numeric 2",
40 "3" : "Numeric 3",
41 "4" : "Numeric 4",
42 "5" : "Numeric 5",
43 "6" : "Numeric 6",
44 "7" : "Numeric 7",
45 "8" : "Numeric 8",
46 "9" : "Numeric 9",
47 "=" : "Calculate result",
48 "+" : "Add",
49 "-" : "Subtract",
50 "*" : "Multiply",
51 "/" : "Divide",
52 "c" : "Clear entry",
53 "C" : "Clear",
54 "." : "Numeric point",
55 "@" : "Square",
56 "s" : "Square root"}
57 EDITBAR_ROLE = "edit bar"
58 EDITBAR_INDEX = 0
59 SLEEP_DELAY = 2
60 GCONF_MODE_KEY = "/apps/gcalctool/mode"
61 GCONF_MODE_VAL = "BASIC"
62
63 def __init__(self):
64 Application.__init__(self)
65
66 def open(self):
67 """
68 Opens the application
69 """
70 try:
71 GConf.set_item(self.GCONF_MODE_KEY, self.GCONF_MODE_VAL)
72 except GConf.GConfError:
73 raise ldtp.LdtpExecutionError, "Could not set default view in gconf"
74 Application.open(self)
75
76 def push(self, buttons):
77 """
78 Push the specified buttons in the calculator window.
79
80 >>> c = Calculator()
81 >>> c.open()
82 >>> c.push('2+2=')
83
84 @param buttons: Specify the buttons to push.
85 @type buttons: string
86 """
87 calculator = ooldtp.context(self.name)
88 for button in buttons:
89 try:
90 # The calculator has some buttons with the same names that are
91 # hidden depending on the view.
92 children = calculator.getchild(self.BUTTONS[button],'push button')
93 for child in children:
94 childName=child.getName()
95 if calculator.hasstate(childName, ldtp.state.SHOWING):
96 calculator.click(childName)
97 break
98 else:
99 raise LookupError, "Could not find button %s in current view" % button
100 except ldtp.LdtpExecutionError:
101 raise ldtp.LdtpExecutionError, "Error clicking button %s" % button
102
103 def get_view(self):
104 """
105 Get the current view of the calculator.
106
107 >>> c = Calculator()
108 >>> c.open()
109 >>> c.get_view()
110 'BASIC'
111
112 @return: The current view: BASIC, ADVANCED, FINANCIAL, SCIENTIFIC,
113 or PROGRAMMING
114 @rtype: string
115 """
116 windowname = self.name
117 for view in self.VIEWS:
118 if self.VIEWS[view]['WINDOW'] == windowname:
119 return view
120 raise LookupError, "Could not identify the current calculator view"
121
122 def set_view(self, new_view):
123 """
124 Change to the specified view in the calculator
125
126 >>> c = Calculator()
127 >>> c.open()
128 >>> c.set_view('ADVANCED')
129
130 @param new_view: Specify the new view. Valid values are:
131 BASIC, ADVANCED, FINANCIAL, SCIENTIFIC, PROGRAMMING
132 @type new_view: string
133 """
134 new_window_name = self.VIEWS[new_view]["WINDOW"]
135 new_view_menu_name = self.VIEWS[new_view]["MENU"]
136 calculator = ooldtp.context(self.name)
137 try:
138 mnu_new_view = calculator.getchild(new_view_menu_name)
139 except ldtp.LdtpExecutionError:
140 raise ldtp.LdtpExecutionError, "The menu item for the requested view was not found."
141
142 try:
143 mnu_new_view.selectmenuitem()
144 except ldtp.LdtpExecutionError:
145 raise ldtp.LdtpExecutionError, "There was a problem changing views."
146 self.set_name(new_window_name)
147 time.sleep(self.SLEEP_DELAY) # need to give mago some time to catch up to calc ui
148 self.remap # tell mago about the new frm name and remap everything
149
150 def get_value(self):
151 """
152 Read the value from the calculator screen
153
154 >>> c = Calculator()
155 >>> c.open()
156 >>> c.push('2+2=')
157 >>> c.get_value()
158 u'4'
159
160 @return: The contents of the calculator's screen
161 @rtype: string
162 """
163 calculator = ooldtp.context(self.name)
164 try:
165 editBar = calculator.getchild('txtResultRegion') # txtResultRegion
166 value = editBar.gettextvalue()
167 except ldtp.LdtpExecutionError:
168 raise ldtp.LdtpExecutionError, "There was a problem reading the value."
169 return value
9170
10class GnomeScreenshot(Application):171class GnomeScreenshot(Application):
11 """172 """
@@ -252,7 +413,6 @@
252 except ldtp.LdtpExecutionError:413 except ldtp.LdtpExecutionError:
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"
254415
255
256class Seahorse(Application):416class Seahorse(Application):
257 """417 """
258 Seahorse manages the Seahorse application.418 Seahorse manages the Seahorse application.
259419
=== modified file 'mago/test_suite/gnome.py'
--- mago/test_suite/gnome.py 2009-08-25 18:33:48 +0000
+++ mago/test_suite/gnome.py 2009-09-08 13:29:58 +0000
@@ -4,7 +4,27 @@
4"""4"""
5import ldtp, ooldtp5import ldtp, ooldtp
6from .main import SingleApplicationTestSuite6from .main import SingleApplicationTestSuite
7from ..application.gnome import Application, GnomeScreenshot, Seahorse, GEdit7from ..application.gnome import Application, Seahorse, GEdit, GnomeScreenshot, Calculator
8
9class GCalctoolTestSuite(SingleApplicationTestSuite):
10 """
11 Default test suite for Calculator
12 """
13 APPLICATION_FACTORY = Calculator
14 def setup(self):
15 self.application.open()
16 self.application.push("C")
17
18 def teardown(self):
19 self.application.close()
20
21class GCalctoolViewTestSuite(GCalctoolTestSuite):
22 """
23 Test suite for views populates the screen with some data in setup
24 """
25 def setup(self):
26 GCalctoolTestSuite.setup(self)
27 self.application.push("13.37")
828
9class GnomeScreenshotTestSuite(SingleApplicationTestSuite):29class GnomeScreenshotTestSuite(SingleApplicationTestSuite):
10 APPLICATION_FACTORY = GnomeScreenshot 30 APPLICATION_FACTORY = GnomeScreenshot

Subscribers

People subscribed via source and target branches

to status/vote changes: