Merge lp:~brandontschaefer/unity/ap-hud-fixes-cjk-ibus into lp:unity

Proposed by Brandon Schaefer on 2012-03-29
Status: Merged
Approved by: Thomi Richards on 2012-03-31
Approved revision: 2196
Merged at revision: 2199
Proposed branch: lp:~brandontschaefer/unity/ap-hud-fixes-cjk-ibus
Merge into: lp:unity
Diff against target: 423 lines (+139/-81)
6 files modified
tests/autopilot/autopilot/emulators/unity/dash.py (+4/-2)
tests/autopilot/autopilot/emulators/unity/hud.py (+70/-53)
tests/autopilot/autopilot/emulators/unity/icons.py (+7/-0)
tests/autopilot/autopilot/tests/__init__.py (+2/-0)
tests/autopilot/autopilot/tests/test_hud.py (+4/-10)
tests/autopilot/autopilot/tests/test_ibus.py (+52/-16)
To merge this branch: bzr merge lp:~brandontschaefer/unity/ap-hud-fixes-cjk-ibus
Reviewer Review Type Date Requested Status
Thomi Richards (community) 2012-03-29 Approve on 2012-03-31
Review via email: mp+100058@code.launchpad.net

Commit Message

* Adds CJK autopilot test for the Hud

Description of the Change

This adds CJK test for the Hud.

To post a comment you must log in.
Brandon Schaefer (brandontschaefer) wrote :

This adds CJK test for the Hud.

Thomi Richards (thomir) wrote :

In diff line 8:

Please just grab the controller instances, and do the assert and assignment from the list, like so:

controllers = DashController.get_all_instances()
assert(len(controllers) == 1)
self.controller = controllers[0]

...you'll notice my assert is more explicit than yours as well. This pattern should be repeated for the Hud class.

I'm not sure where the EmbeddedIcon class ended up, but it should go in icons.py, and it should derive from SimpleLauncherIcon.

In the Hud class, the call to 'super(Hud, self).__init__()' should happen first, before anything else.

Apart from this, the tests look good. I have a feeling we can simplify these tests a lot, especially with the use of some more test scenarios, but I'm happy to merge the code with the fixes mentioned above.

review: Needs Fixing
2195. By Brandon Schaefer on 2012-03-30

* Fixed ap problems!

2196. By Brandon Schaefer on 2012-03-30

* Merged with trunk, and fixed an ap error I commited

Brandon Schaefer (brandontschaefer) wrote :

Ran 42 tests in 158.498s
OK

All Hud ap test pass.

Thomi Richards (thomir) :
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/emulators/unity/dash.py'
2--- tests/autopilot/autopilot/emulators/unity/dash.py 2012-03-20 01:06:00 +0000
3+++ tests/autopilot/autopilot/emulators/unity/dash.py 2012-03-30 20:12:24 +0000
4@@ -29,10 +29,12 @@
5 """
6
7 def __init__(self):
8- self.controller = DashController.get_all_instances()[0]
9+ super(Dash, self).__init__()
10
11+ controllers = DashController.get_all_instances()
12+ assert(len(controllers) == 1)
13+ self.controller = controllers[0]
14 self._keyboard = Keyboard()
15- super(Dash, self).__init__()
16
17 @property
18 def view(self):
19
20=== modified file 'tests/autopilot/autopilot/emulators/unity/hud.py'
21--- tests/autopilot/autopilot/emulators/unity/hud.py 2012-03-30 04:00:05 +0000
22+++ tests/autopilot/autopilot/emulators/unity/hud.py 2012-03-30 20:12:24 +0000
23@@ -10,71 +10,81 @@
24 from autopilot.keybindings import KeybindingsHelper
25 from autopilot.emulators.unity import UnityIntrospectionObject
26 from autopilot.emulators.unity.dash import SearchBar
27-
28-
29-class HudView(UnityIntrospectionObject):
30- """Proxy object for the hud view child of the controller."""
31-
32- @property
33- def searchbar(self):
34- """Get the search bar attached to this hud view."""
35- return self.get_children_by_type(SearchBar)[0]
36-
37- @property
38- def geometry(self):
39- return (self.x, self.y, self.width, self.height)
40-
41-class EmbeddedIcon(UnityIntrospectionObject):
42- """Proxy object for the hud embedded icon child of the view."""
43-
44- @property
45- def geometry(self):
46- return (self.x, self.y, self.width, self.height)
47-
48-class HudController(UnityIntrospectionObject, KeybindingsHelper):
49- """Proxy object for the Unity Hud Controller."""
50+from autopilot.emulators.unity.icons import EmbeddedIcon
51+
52+class Hud(KeybindingsHelper):
53+ """An emulator class that makes it easier to iteract with unity hud."""
54+
55+ def __init__(self):
56+ super (Hud, self).__init__()
57+
58+ controllers = HudController.get_all_instances()
59+ assert(len(controllers) == 1)
60+ self.controller = controllers[0]
61
62 def ensure_hidden(self):
63 """Hides the hud if it's not already hidden."""
64- if self.is_visible():
65+ if self.visible:
66 self.toggle_reveal()
67
68 def ensure_visible(self):
69 """Shows the hud if it's not already showing."""
70- if not self.is_visible():
71+ if not self.visible:
72 self.toggle_reveal()
73
74- def is_visible(self):
75- return self.visible
76-
77 def toggle_reveal(self, tap_delay=0.1):
78 """Tap the 'Alt' key to toggle the hud visibility."""
79 self.keybinding("hud/reveal", tap_delay)
80
81 def get_embedded_icon(self):
82 """Returns the HUD view embedded icon or None if is not shown."""
83- view = self._get_view()
84+ view = self.view
85 if (not view):
86- return None
87+ return None
88
89 icons = view.get_children_by_type(EmbeddedIcon)
90 return icons[0] if icons else None
91
92- def _get_view(self):
93- views = self.get_children_by_type(HudView)
94- return views[0] if views else None
95-
96- @property
97- def searchbar(self):
98- """Returns the searchbar attached to the hud."""
99- return self._get_view().searchbar;
100-
101+ @property
102+ def view(self):
103+ """Returns the HudView."""
104+ return self.controller.get_hud_view()
105+
106+ @property
107+ def visible(self):
108+ """Is the Hud visible?"""
109+ return self.controller.visible
110+
111+ @property
112+ def searchbar(self):
113+ """Returns the searchbar attached to the hud."""
114+ return self.controller.get_hud_view().searchbar
115+
116+ @property
117+ def search_string(self):
118+ """Returns the searchbars' search string."""
119+ return self.searchbar.search_string
120+
121+ @property
122+ def is_locked_launcher(self):
123+ return self.controller.locked_to_launcher
124+
125+ @property
126+ def monitor(self):
127+ return self.controller.hud_monitor
128+
129+ @property
130+ def searchbar(self):
131+ """Returns the searchbar attached to the hud."""
132+ return self.controller.get_hud_view().searchbar;
133+
134+ @property
135 def geometry(self):
136- return (self.x, self.y, self.width, self.height)
137+ return (self.controller.x, self.controller.y, self.controller.width, self.controller.height)
138
139 @property
140 def selected_button(self):
141- view = self._get_view()
142+ view = self.controller.get_hud_view()
143 if view:
144 return view.selected_button
145 else:
146@@ -82,20 +92,27 @@
147
148 @property
149 def num_buttons(self):
150- view = self._get_view()
151+ view = self.controller.get_hud_view()
152 if view:
153 return view.num_buttons
154 else:
155 return 0
156
157- @property
158- def is_locked_to_launcher(self):
159- return bool(self.locked_to_launcher)
160-
161- @property
162- def monitor(self):
163- return int(self.hud_monitor)
164-
165- @property
166- def has_embedded_icon(self):
167- return (self.get_embedded_icon() != None)
168+class HudView(UnityIntrospectionObject):
169+ """Proxy object for the hud view child of the controller."""
170+
171+ @property
172+ def searchbar(self):
173+ """Get the search bar attached to this hud view."""
174+ return self.get_children_by_type(SearchBar)[0]
175+
176+ @property
177+ def geometry(self):
178+ return (self.x, self.y, self.width, self.height)
179+
180+class HudController(UnityIntrospectionObject):
181+ """Proxy object for the Unity Hud Controller."""
182+
183+ def get_hud_view(self):
184+ views = self.get_children_by_type(HudView)
185+ return views[0] if views else None
186
187=== modified file 'tests/autopilot/autopilot/emulators/unity/icons.py'
188--- tests/autopilot/autopilot/emulators/unity/icons.py 2012-03-29 20:25:35 +0000
189+++ tests/autopilot/autopilot/emulators/unity/icons.py 2012-03-30 20:12:24 +0000
190@@ -71,3 +71,10 @@
191
192 class SoftwareCenterLauncherIcon(BamfLauncherIcon):
193 """Represents a launcher icon of a Software Center app."""
194+
195+class EmbeddedIcon(SimpleLauncherIcon):
196+ """Proxy object for the hud embedded icon child of the view."""
197+
198+ @property
199+ def geometry(self):
200+ return (self.x, self.y, self.width, self.height)
201
202=== modified file 'tests/autopilot/autopilot/tests/__init__.py'
203--- tests/autopilot/autopilot/tests/__init__.py 2012-03-29 14:31:40 +0000
204+++ tests/autopilot/autopilot/tests/__init__.py 2012-03-30 20:12:24 +0000
205@@ -22,6 +22,7 @@
206 reset_logging,
207 )
208 from autopilot.emulators.unity.dash import Dash
209+from autopilot.emulators.unity.hud import Hud
210 from autopilot.emulators.unity.launcher import LauncherController
211 from autopilot.emulators.unity.switcher import Switcher
212 from autopilot.emulators.unity.workspace import WorkspaceManager
213@@ -227,6 +228,7 @@
214 self.keyboard = Keyboard()
215 self.mouse = Mouse()
216 self.dash = Dash()
217+ self.hud = Hud()
218 self.switcher = Switcher()
219 self.workspace = WorkspaceManager()
220 self.screen_geo = ScreenGeometry()
221
222=== modified file 'tests/autopilot/autopilot/tests/test_hud.py'
223--- tests/autopilot/autopilot/tests/test_hud.py 2012-03-30 17:41:41 +0000
224+++ tests/autopilot/autopilot/tests/test_hud.py 2012-03-30 20:12:24 +0000
225@@ -11,7 +11,6 @@
226 from time import sleep
227
228 from autopilot.emulators.X11 import ScreenGeometry
229-from autopilot.emulators.unity.hud import HudController
230 from autopilot.emulators.unity.icons import HudLauncherIcon
231 from autopilot.tests import AutopilotTestCase, multiply_scenarios
232 from os import remove
233@@ -34,17 +33,11 @@
234 super(HudTestsBase, self).setUp()
235
236 sleep(0.25)
237- self.hud = self.get_hud_controller()
238
239 def tearDown(self):
240 self.hud.ensure_hidden()
241 super(HudTestsBase, self).tearDown()
242
243- def get_hud_controller(self):
244- controllers = HudController.get_all_instances()
245- self.assertEqual(1, len(controllers))
246- return controllers[0]
247-
248 def get_hud_launcher_icon(self):
249 icons = HudLauncherIcon.get_all_instances()
250 self.assertEqual(1, len(icons))
251@@ -399,17 +392,18 @@
252 self.reveal_hud()
253 sleep(.25)
254
255- self.assertThat(self.hud.is_locked_to_launcher, Equals(self.hud_locked))
256+ self.assertThat(self.hud.is_locked_launcher, Equals(self.hud_locked))
257
258 def test_hud_icon_is_shown(self):
259 """Tests that the correct HUD icon is shown"""
260 self.reveal_hud()
261+ self.hud.visible
262 sleep(.5)
263
264 hud_launcher_icon = self.get_hud_launcher_icon()
265 hud_embedded_icon = self.hud.get_embedded_icon()
266
267- if self.hud.is_locked_to_launcher:
268+ if self.hud.is_locked_launcher:
269 self.assertTrue(hud_launcher_icon.is_visible_on_monitor(self.hud_monitor))
270 self.assertTrue(hud_launcher_icon.active)
271 self.assertThat(hud_launcher_icon.monitor, Equals(self.hud_monitor))
272@@ -431,7 +425,7 @@
273 self.reveal_hud()
274 sleep(.5)
275
276- if self.hud.is_locked_to_launcher:
277+ if self.hud.is_locked_launcher:
278 hud_launcher_icon = self.get_hud_launcher_icon()
279 self.assertThat(hud_launcher_icon.icon_name, Equals(calc.icon))
280 else:
281
282=== modified file 'tests/autopilot/autopilot/tests/test_ibus.py'
283--- tests/autopilot/autopilot/tests/test_ibus.py 2012-03-22 22:34:01 +0000
284+++ tests/autopilot/autopilot/tests/test_ibus.py 2012-03-30 20:12:24 +0000
285@@ -12,8 +12,6 @@
286 set_active_engines,
287 get_available_input_engines,
288 )
289-from autopilot.emulators.unity.dash import Dash
290-from autopilot.emulators.X11 import Keyboard
291 from autopilot.tests import AutopilotTestCase, multiply_scenarios
292
293 from time import sleep
294@@ -23,8 +21,6 @@
295
296 def setUp(self):
297 super(IBusTests, self).setUp()
298- self.kb = Keyboard()
299- self.dash = Dash()
300 self._old_engines = None
301
302 def tearDown(self):
303@@ -41,11 +37,11 @@
304
305 def activate_ibus(self):
306 # it would be nice to be able to tell if it's currently active or not.
307- self.kb.press_and_release('Ctrl+Space')
308+ self.keyboard.press_and_release('Ctrl+Space')
309
310 def deactivate_ibus(self):
311 # it would be nice to be able to tell if it's currently active or not.
312- self.kb.press_and_release('Ctrl+Space')
313+ self.keyboard.press_and_release('Ctrl+Space')
314
315
316 class IBusTestsPinyin(IBusTests):
317@@ -59,19 +55,32 @@
318 ('disk_management', {'input': 'cipan guanli ', 'result': u'\u78c1\u76d8\u7ba1\u7406'}),
319 ]
320
321- def test_simple_input(self):
322+ def test_simple_input_dash(self):
323 self.activate_input_engine_or_skip("pinyin")
324 self.dash.ensure_visible()
325 sleep(0.5)
326 self.activate_ibus()
327 sleep(0.5)
328- self.kb.type(self.input)
329- dash_search_string = self.dash.get_searchbar().search_string
330+ self.keyboard.type(self.input)
331+ dash_search_string = self.dash.search_string
332 self.deactivate_ibus()
333 self.dash.ensure_hidden()
334
335 self.assertEqual(self.result, dash_search_string)
336
337+ def test_simple_input_hud(self):
338+ self.activate_input_engine_or_skip("pinyin")
339+ self.hud.ensure_visible()
340+ sleep(0.5)
341+ self.activate_ibus()
342+ sleep(0.5)
343+ self.keyboard.type(self.input)
344+ hud_search_string = self.hud.search_string
345+ self.deactivate_ibus()
346+ self.hud.ensure_hidden()
347+
348+ self.assertEqual(self.result, hud_search_string)
349+
350
351 class IBusTestsHangul(IBusTests):
352 """Tests for the Hangul(Korean) input engine."""
353@@ -82,19 +91,32 @@
354 ('document', {'input': 'anstj ', 'result': u'\ubb38\uc11c '}),
355 ]
356
357- def test_simple_input(self):
358+ def test_simple_input_dash(self):
359 self.activate_input_engine_or_skip("hangul")
360 self.dash.ensure_visible()
361 sleep(0.5)
362 self.activate_ibus()
363 sleep(0.5)
364- self.kb.type(self.input)
365- dash_search_string = self.dash.get_searchbar().search_string
366+ self.keyboard.type(self.input)
367+ dash_search_string = self.dash.search_string
368 self.deactivate_ibus()
369 self.dash.ensure_hidden()
370
371 self.assertEqual(self.result, dash_search_string)
372
373+ def test_simple_input_hud(self):
374+ self.activate_input_engine_or_skip("hangul")
375+ self.hud.ensure_visible()
376+ sleep(0.5)
377+ self.activate_ibus()
378+ sleep(0.5)
379+ self.keyboard.type(self.input)
380+ hud_search_string = self.hud.search_string
381+ self.deactivate_ibus()
382+ self.hud.ensure_hidden()
383+
384+ self.assertEqual(self.result, hud_search_string)
385+
386
387 class IBusTestsAnthy(IBusTests):
388 """Tests for the Anthy(Japanese) input engine."""
389@@ -111,16 +133,30 @@
390 ]
391 )
392
393- def test_simple_input(self):
394+ def test_simple_input_dash(self):
395 self.activate_input_engine_or_skip("anthy")
396 self.dash.ensure_visible()
397 sleep(0.5)
398 self.activate_ibus()
399 sleep(0.5)
400- self.kb.type(self.input)
401- self.kb.press_and_release(self.commit_key)
402- dash_search_string = self.dash.get_searchbar().search_string
403+ self.keyboard.type(self.input)
404+ self.keyboard.press_and_release(self.commit_key)
405+ dash_search_string = self.dash.search_string
406 self.deactivate_ibus()
407 self.dash.ensure_hidden()
408
409 self.assertEqual(self.result, dash_search_string)
410+
411+ def test_simple_input_hud(self):
412+ self.activate_input_engine_or_skip("anthy")
413+ self.hud.ensure_visible()
414+ sleep(0.5)
415+ self.activate_ibus()
416+ sleep(0.5)
417+ self.keyboard.type(self.input)
418+ self.keyboard.press_and_release(self.commit_key)
419+ hud_search_string = self.hud.search_string
420+ self.deactivate_ibus()
421+ self.hud.ensure_hidden()
422+
423+ self.assertEqual(self.result, hud_search_string)