Merge lp:~thomir/unity/hud-tests-to-wait_for-feature into lp:unity

Proposed by Thomi Richards on 2012-04-18
Status: Merged
Approved by: Thomi Richards on 2012-04-18
Approved revision: 2250
Merged at revision: 2309
Proposed branch: lp:~thomir/unity/hud-tests-to-wait_for-feature
Merge into: lp:unity
Diff against target: 256 lines (+50/-50)
1 file modified
tests/autopilot/autopilot/tests/test_hud.py (+50/-50)
To merge this branch: bzr merge lp:~thomir/unity/hud-tests-to-wait_for-feature
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) 2012-04-18 Approve on 2012-04-18
Review via email: mp+102601@code.launchpad.net

Commit Message

Update HUD tests to use the new Eventually() matcher.

Description of the Change

Update the hud tests to use the Eventually() matcher.

To post a comment you must log in.
2250. By Thomi Richards on 2012-04-18

Removed unused import, fixed reference to property being treated as a function.

Brandon Schaefer (brandontschaefer) wrote :

Looks good +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/autopilot/tests/test_hud.py'
2--- tests/autopilot/autopilot/tests/test_hud.py 2012-04-17 22:45:29 +0000
3+++ tests/autopilot/autopilot/tests/test_hud.py 2012-04-18 22:50:25 +0000
4@@ -14,12 +14,12 @@
5 GreaterThan,
6 LessThan,
7 NotEquals,
8- raises,
9 )
10 from time import sleep
11
12 from autopilot.emulators.unity.icons import HudLauncherIcon
13 from autopilot.emulators.X11 import ScreenGeometry
14+from autopilot.matchers import Eventually
15 from autopilot.tests import AutopilotTestCase, multiply_scenarios
16
17
18@@ -70,36 +70,36 @@
19 def test_check_a_values(self):
20 self.hud.ensure_visible()
21 self.keyboard.type('a')
22- self.hud.search_string.wait_for('a')
23- self.hud.num_buttons.wait_for(5)
24- self.hud.selected_button.wait_for(1)
25+ self.assertThat(self.hud.search_string, Eventually(Equals('a')))
26+ self.assertThat(self.hud.num_buttons, Eventually(Equals(5)))
27+ self.assertThat(self.hud.selected_button, Eventually(Equals(1)))
28
29 def test_up_down_arrows(self):
30 self.hud.ensure_visible()
31 self.keyboard.type('a')
32- self.hud.search_string.wait_for('a')
33- self.keyboard.press_and_release('Down')
34- self.hud.selected_button.wait_for(2)
35- self.keyboard.press_and_release('Down')
36- self.hud.selected_button.wait_for(3)
37- self.keyboard.press_and_release('Down')
38- self.hud.selected_button.wait_for(4)
39- self.keyboard.press_and_release('Down')
40- self.hud.selected_button.wait_for(5)
41+ self.assertThat(self.hud.search_string, Eventually(Equals('a')))
42+ self.keyboard.press_and_release('Down')
43+ self.assertThat(self.hud.selected_button, Eventually(Equals(2)))
44+ self.keyboard.press_and_release('Down')
45+ self.assertThat(self.hud.selected_button, Eventually(Equals(3)))
46+ self.keyboard.press_and_release('Down')
47+ self.assertThat(self.hud.selected_button, Eventually(Equals(4)))
48+ self.keyboard.press_and_release('Down')
49+ self.assertThat(self.hud.selected_button, Eventually(Equals(5)))
50 # Down again stays on 5.
51 self.keyboard.press_and_release('Down')
52- self.hud.selected_button.wait_for(5)
53- self.keyboard.press_and_release('Up')
54- self.hud.selected_button.wait_for(4)
55- self.keyboard.press_and_release('Up')
56- self.hud.selected_button.wait_for(3)
57- self.keyboard.press_and_release('Up')
58- self.hud.selected_button.wait_for(2)
59- self.keyboard.press_and_release('Up')
60- self.hud.selected_button.wait_for(1)
61+ self.assertThat(self.hud.selected_button, Eventually(Equals(5)))
62+ self.keyboard.press_and_release('Up')
63+ self.assertThat(self.hud.selected_button, Eventually(Equals(4)))
64+ self.keyboard.press_and_release('Up')
65+ self.assertThat(self.hud.selected_button, Eventually(Equals(3)))
66+ self.keyboard.press_and_release('Up')
67+ self.assertThat(self.hud.selected_button, Eventually(Equals(2)))
68+ self.keyboard.press_and_release('Up')
69+ self.assertThat(self.hud.selected_button, Eventually(Equals(1)))
70 # Up again stays on 1.
71 self.keyboard.press_and_release('Up')
72- self.hud.selected_button.wait_for(1)
73+ self.assertThat(self.hud.selected_button, Eventually(Equals(1)))
74
75 def test_no_reset_selected_button(self):
76 """Hud must not change selected button when results update over time."""
77@@ -107,20 +107,20 @@
78 # ideally we'd send artificial results to the hud from the test.
79 self.hud.ensure_visible()
80 self.keyboard.type('is')
81- self.hud.search_string.wait_for('is')
82+ self.assertThat(self.hud.search_string, Eventually(Equals('is')))
83 self.keyboard.press_and_release('Down')
84- self.hud.selected_button.wait_for(2)
85+ self.assertThat(self.hud.selected_button, Eventually(Equals(2)))
86 # long sleep to let the service send updated results
87 sleep(10)
88 self.assertThat(self.hud.selected_button, Equals(2))
89
90 def test_slow_tap_not_reveal_hud(self):
91 """A slow tap must not reveal the HUD."""
92- # This raises AssertionError since toggle_hud does a wait_for to check
93- # that the hud opened or closed. Since it won't open or close when the
94- # tap delay is too long, we expect that in our test:
95- fn = lambda: self.hud.toggle_reveal(tap_delay=0.3)
96- self.assertThat(fn, raises(AssertionError))
97+ self.keybinding("hud/reveal", 0.3)
98+ # need a long sleep to ensure that we test after the hud controller has
99+ # seen the keypress.
100+ sleep(5)
101+ self.assertThat(self.hud.visible, Equals(False))
102
103 def test_alt_f4_doesnt_show_hud(self):
104 self.start_app('Calculator')
105@@ -179,9 +179,9 @@
106 self.hud.ensure_visible()
107
108 self.keyboard.type("undo")
109- self.hud.search_string.wait_for("undo")
110+ self.assertThat(self.hud.search_string, Eventually(Equals("undo")))
111 self.keyboard.press_and_release('Return')
112- self.hud.visible.wait_for(False)
113+ self.assertThat(self.hud.visible, Eventually(Equals(False)))
114 self.keyboard.press_and_release("Ctrl+s")
115 sleep(1)
116
117@@ -197,7 +197,7 @@
118 # we need a sleep here to ensure that the launcher has had time to start
119 # keynav before we check the key_nav_is_active attribute.
120 #
121- # Ideally we'd do 'key_nav_is_active.wait_for(True)' and expect a test
122+ # Ideally we'd do 'key_nav_is_active, Eventually(Equals(True)' and expect a test
123 # failure.
124 sleep(1)
125
126@@ -219,21 +219,21 @@
127 self.dash.ensure_visible()
128 self.addCleanup(self.dash.ensure_hidden)
129 self.keyboard.type('focus1')
130- self.dash.search_string.wait_for('focus1')
131+ self.assertThat(self.dash.search_string, Eventually(Equals('focus1')))
132
133 def test_dash_to_hud_has_key_focus(self):
134 """When switching from the dash to the hud you don't lose key focus."""
135 self.dash.ensure_visible()
136 self.hud.ensure_visible()
137 self.keyboard.type('focus2')
138- self.hud.search_string.wait_for('focus2')
139+ self.assertThat(self.hud.search_string, Eventually(Equals('focus2')))
140
141 def test_hud_closes_on_workspace_switch(self):
142 """This test shows that when you switch to another workspace the hud closes."""
143 self.hud.ensure_visible()
144 self.workspace.switch_to(1)
145 self.workspace.switch_to(2)
146- self.hud.visible.wait_for(False)
147+ self.assertThat(self.hud.visible, Eventually(Equals(False)))
148
149
150 class HudLauncherInteractionsTests(HudTestsBase):
151@@ -312,16 +312,16 @@
152 hud_icon = self.hud.get_launcher_icon()
153 bfb_icon = self.launcher.model.get_bfb_icon()
154
155- bfb_icon.visible.wait_for(True)
156+ self.assertThat(bfb_icon.visible, Eventually(Equals(True)))
157 self.assertTrue(bfb_icon.is_on_monitor(self.hud_monitor))
158- hud_icon.visible.wait_for(False)
159+ self.assertThat(hud_icon.visible, Eventually(Equals(False)))
160
161 self.hud.ensure_visible()
162
163- hud_icon.visible.wait_for(True)
164+ self.assertThat(hud_icon.visible, Eventually(Equals(True)))
165 self.assertTrue(hud_icon.is_on_monitor(self.hud_monitor))
166 # For some reason the BFB icon is always visible :-/
167- #bfb_icon.visible.wait_for(False)
168+ #bfb_icon.visible, Eventually(Equals(False)
169
170 def test_hud_desaturates_launcher_icons(self):
171 """Launcher icons must desaturate when the HUD is opened."""
172@@ -360,7 +360,7 @@
173 def test_hud_is_on_right_monitor(self):
174 """HUD must be drawn on the monitor where the mouse is."""
175 self.hud.ensure_visible()
176- self.hud.monitor.wait_for(self.hud_monitor)
177+ self.assertThat(self.hud.monitor, Eventually(Equals(self.hud_monitor)))
178 self.assertTrue(self.screen_geo.is_rect_on_monitor(self.hud.monitor, self.hud.geometry))
179
180 def test_hud_geometries(self):
181@@ -383,7 +383,7 @@
182 def test_hud_is_locked_to_launcher(self):
183 """Tests if the HUD is locked to launcher as we expect or not."""
184 self.hud.ensure_visible()
185- self.hud.is_locked_launcher.wait_for(self.hud_locked)
186+ self.assertThat(self.hud.is_locked_launcher, Eventually(Equals(self.hud_locked)))
187
188 def test_hud_icon_is_shown(self):
189 """Tests that the correct HUD icon is shown."""
190@@ -392,14 +392,14 @@
191 hud_embedded_icon = self.hud.get_embedded_icon()
192
193 if self.hud.is_locked_launcher:
194- hud_launcher_icon.visible.wait_for(True)
195+ self.assertThat(hud_launcher_icon.visible, Eventually(Equals(True)))
196 self.assertTrue(hud_launcher_icon.is_on_monitor(self.hud_monitor))
197 self.assertTrue(hud_launcher_icon.active)
198 self.assertThat(hud_launcher_icon.monitor, Equals(self.hud_monitor))
199 self.assertFalse(hud_launcher_icon.desaturated)
200 self.assertThat(hud_embedded_icon, Equals(None))
201 else:
202- hud_launcher_icon.visible.wait_for(False)
203+ self.assertThat(hud_launcher_icon.visible, Eventually(Equals(False)))
204 self.assertFalse(hud_launcher_icon.active)
205 # the embedded icon has no visible property.
206 self.assertThat(hud_embedded_icon, NotEquals(None))
207@@ -411,7 +411,7 @@
208 self.assertTrue(calc.is_active)
209 self.hud.ensure_visible()
210
211- self.hud.icon.icon_name.wait_for(calc.icon)
212+ self.assertThat(self.hud.icon.icon_name, Eventually(Equals(calc.icon)))
213
214 def test_hud_icon_shows_the_ubuntu_emblem_on_empty_desktop(self):
215 """When in 'show desktop' mode the hud icon must be the BFB icon."""
216@@ -420,7 +420,7 @@
217 sleep(1)
218 self.hud.ensure_visible()
219
220- self.hud.icon.icon_name.wait_for(EndsWith("launcher_bfb.png"))
221+ self.assertThat(self.hud.icon.icon_name, Eventually(EndsWith("launcher_bfb.png")))
222
223 def test_switch_dash_hud_does_not_break_the_focused_application_emblem(self):
224 """Switching from Dash to HUD must still show the correct HUD icon."""
225@@ -431,7 +431,7 @@
226 self.dash.ensure_visible()
227 self.hud.ensure_visible()
228
229- self.hud.icon.icon_name.wait_for(calc.icon)
230+ self.assertThat(self.hud.icon.icon_name, Eventually(Equals(calc.icon)))
231
232 def test_switch_hud_dash_does_not_break_the_focused_application_emblem(self):
233 """Switching from HUD to Dash and back must still show the correct HUD icon."""
234@@ -442,7 +442,7 @@
235 self.hud.ensure_visible()
236 self.dash.ensure_visible()
237 self.hud.ensure_visible()
238- self.hud.icon.icon_name.wait_for(calc.icon)
239+ self.assertThat(self.hud.icon.icon_name, Eventually(Equals(calc.icon)))
240
241
242 class HudAlternativeKeybindingTests(HudTestsBase):
243@@ -452,11 +452,11 @@
244 self.set_unity_option("show_hud", "<Super>h")
245 # Don't use reveal_hud, but be explicit in the keybindings.
246 self.keyboard.press_and_release("Super+h")
247- self.hud.visible.wait_for(True)
248+ self.assertThat(self.hud.visible, Eventually(Equals(True)))
249
250 def test_ctrl_alt_h(self):
251 """Test hud reveal on <Contrl><Alt>h."""
252 self.set_unity_option("show_hud", "<Control><Alt>h")
253 # Don't use reveal_hud, but be explicit in the keybindings.
254 self.keyboard.press_and_release("Ctrl+Alt+h")
255- self.hud.visible.wait_for(True)
256+ self.assertThat(self.hud.visible, Eventually(Equals(True)))