Merge lp:~chris.gagnon/unity/fix-endless-while-loop-in-launcher-tests into lp:unity

Proposed by Chris Gagnon
Status: Rejected
Rejected by: Brandon Schaefer
Proposed branch: lp:~chris.gagnon/unity/fix-endless-while-loop-in-launcher-tests
Merge into: lp:unity
Diff against target: 116 lines (+38/-12)
1 file modified
tests/autopilot/unity/emulators/launcher.py (+38/-12)
To merge this branch: bzr merge lp:~chris.gagnon/unity/fix-endless-while-loop-in-launcher-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Thomi Richards (community) Approve
Review via email: mp+186090@code.launchpad.net

Commit message

don't get stuck in a while loop in tests/autopilot/unity/emulators/launcher.py

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

This branch is doing the same thing as this one:
https://code.launchpad.net/~townsend/unity/fix-ap-mouse-infinite-loop/+merge/186070

If you think that townsends branch needs to add something from this branch please add a comment there.

Unmerged revisions

3513. By Chris Gagnon

call raise as a statement instead of a function

3512. By Chris Gagnon

don't get stuck in a while loop in tests/autopilot/unity/emulators/launcher.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/unity/emulators/launcher.py'
2--- tests/autopilot/unity/emulators/launcher.py 2013-09-12 15:56:41 +0000
3+++ tests/autopilot/unity/emulators/launcher.py 2013-09-17 17:03:48 +0000
4@@ -12,6 +12,7 @@
5 from autopilot.input import Mouse
6 from autopilot.display import Display, move_mouse_to_screen
7 from autopilot.keybindings import KeybindingsHelper
8+from datetime import datetime, timedelta
9 import logging
10 from testtools.matchers import NotEquals
11 from time import sleep
12@@ -121,15 +122,22 @@
13 logger.debug("Moving mouse to center of launcher.")
14 self._mouse.move(target_x, target_y)
15
16- def move_mouse_to_icon(self, icon):
17+ def move_mouse_to_icon(self, icon, timeout=20):
18+
19+ start = datetime.now()
20+ elapsed = datetime.now() - start
21 # The icon may be off the bottom of screen, so we do this in a loop:
22- while 1:
23+ while elapsed < timedelta(seconds=timeout):
24 target_x = icon.center_x + self.x
25 target_y = icon.center_y
26 if self._mouse.x == target_x and self._mouse.y == target_y:
27- break
28+ return True
29+ elapsed = datetime.now() - start
30 self._mouse.move(target_x, target_y)
31 sleep(0.5)
32+ raise AssertionError(
33+ "move_mouse_to_icon timed out after {} seconds".format(timeout))
34+
35
36 def mouse_reveal_launcher(self):
37 """Reveal this launcher with the mouse.
38@@ -299,7 +307,11 @@
39 self._perform_switcher_binding("launcher/switcher/down")
40 self._get_controller().key_nav_selection.wait_for(NotEquals(old_selection))
41
42- def click_launcher_icon(self, icon, button=1, move_mouse_after=True):
43+ def click_launcher_icon(self,
44+ icon,
45+ button=1,
46+ move_mouse_after=True,
47+ timeout=20):
48 """Move the mouse over the launcher icon, and click it.
49 `icon` must be an instance of SimpleLauncherIcon or it's descendants.
50 `move_mouse_after` moves the mouse outside the launcher if true.
51@@ -311,17 +323,25 @@
52 icon, self.monitor, button)
53 self.mouse_reveal_launcher()
54
55+ start = datetime.now()
56+ elapsed = datetime.now() - start
57 # The icon may be off the screen, so we do this in a loop:
58- while 1:
59+ while elapsed < timedelta(seconds=timeout):
60 target_x = icon.center_x + self.x
61 target_y = icon.center_y
62 if self._mouse.x == target_x and self._mouse.y == target_y:
63- break
64+ self._mouse.click(button)
65+ if (move_mouse_after):
66+ self.move_mouse_to_right_of_launcher()
67+
68+ return True
69+
70+ elapsed = datetime.now() - start
71 self._mouse.move(target_x, target_y )
72 sleep(1)
73- self._mouse.click(button)
74- if (move_mouse_after):
75- self.move_mouse_to_right_of_launcher()
76+
77+ raise AssertionError(
78+ "click_launcher_icon timed out after {} seconds".format(timeout))
79
80 def drag_icon_to_position(self, icon, pos, target, drag_type=IconDragType.INSIDE):
81 """Drag a launcher icon to a new position.
82@@ -422,7 +442,7 @@
83 pin_item = quicklist.get_quicklist_item_by_text('Unlock from Launcher')
84 quicklist.click_item(pin_item)
85
86- def autoscroll_to_icon(self, icon, autoscroll_offset=0):
87+ def autoscroll_to_icon(self, icon, autoscroll_offset=0, timeout=20):
88 """Moves the mouse to the autoscroll zone to scroll the Launcher to the icon
89 in question.
90
91@@ -431,7 +451,10 @@
92 """
93 (x, y, w, h) = self.geometry
94
95- while 1:
96+ start = datetime.now()
97+ elapsed = datetime.now() - start
98+
99+ while elapsed < timedelta(seconds=timeout):
100 mouse_x = target_x = icon.center_x + self.x
101 mouse_y = target_y = icon.center_y
102 if target_y > h:
103@@ -439,9 +462,12 @@
104 elif target_y < 0:
105 mouse_y = y + autoscroll_offset
106 if self._mouse.x == target_x and self._mouse.y == target_y:
107- break
108+ return True
109+ elapsed = datetime.now() - start
110 self._mouse.move(mouse_x, mouse_y)
111 sleep(0.5)
112+ raise AssertionError(
113+ "autoscroll_to_icon timed out after {} seconds".format(timeout))
114
115 @property
116 def geometry(self):