Merge lp:~acerisara/autopilot/move-to-object into lp:autopilot

Proposed by Andrea Cerisara on 2015-01-24
Status: Merged
Approved by: Christopher Lee on 2016-02-29
Approved revision: 542
Merged at revision: 576
Proposed branch: lp:~acerisara/autopilot/move-to-object
Merge into: lp:autopilot
Diff against target: 203 lines (+26/-76)
6 files modified
autopilot/input/_X11.py (+5/-49)
autopilot/input/__init__.py (+13/-21)
autopilot/input/_common.py (+5/-1)
autopilot/input/_uinput.py (+1/-1)
autopilot/tests/functional/test_input_stack.py (+1/-2)
autopilot/tests/unit/test_input.py (+1/-2)
To merge this branch: bzr merge lp:~acerisara/autopilot/move-to-object
Reviewer Review Type Date Requested Status
platform-qa-bot continuous-integration Approve on 2016-02-29
Christopher Lee (community) Needs Information on 2016-01-25
Nicholas Skaggs (community) 2015-01-24 Approve on 2015-02-17
PS Jenkins bot continuous-integration Approve on 2015-02-04
Thomi Richards 2015-01-24 Pending
Review via email: mp+247524@code.launchpad.net

Commit Message

Refactored autopilot.input._X11.Mouse.move_to_object.

Description of the Change

Refactored autopilot.input._X11.Mouse.move_to_object.

To post a comment you must log in.
537. By Andrea Cerisara on 2015-01-24

Updated doc.

Christopher Lee (veebers) wrote :

Looking good, just a minor nit-pick re: docstring. Thanks :-)

review: Needs Fixing
538. By Andrea Cerisara on 2015-01-31

Updated doc.

Andrea Cerisara (acerisara) wrote :

The idea was to have a reference to the doc at `autopilot.input._common.get_center_point` in `autopilot.input.Mouse.move_to_object`. Not sure if I can do this, since `input._common` is private as well. Left the doc as it was for now.

Christopher Lee (veebers) wrote :

LGTM, thanks :-) Just waiting on CI for this. Not sure why it's not running, will ping CI now.

review: Approve
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:538
http://jenkins.qa.ubuntu.com/job/autopilot-ci/1014/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-vivid-amd64-ci/77
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-vivid-amd64-ci/77/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-vivid-armhf-ci/77
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-vivid-armhf-ci/77/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-vivid-i386-ci/77
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-vivid-i386-ci/77/artifact/work/output/*zip*/output.zip
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-vivid-touch/1179
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-vivid-autopilot/110
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-vivid-mako/1039
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-vivid-armhf/1177
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-vivid-armhf/1177/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/17781
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-vivid-autopilot/106
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-vivid-amd64/655
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-vivid-amd64/655/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/autopilot-ci/1014/rebuild

review: Approve (continuous-integration)
Nicholas Skaggs (nskaggs) wrote :

LGTM.

review: Approve
Nicholas Skaggs (nskaggs) wrote :

Just leaving this here as commentary on the change.

<thomi> balloons: veebers: I'm disturbed by the deletion of the docstring in that MP
<balloons> is there a more elegant way to do it, while still avoiding double documentation?
<thomi> are the two methods identical?
<balloons> mm.. I suppose it should actually have a docstring.. a unique one
<balloons> meh
<thomi> yeah
<thomi> and make that function public, and give it a docstring too
<balloons> I was thinking it was a duplication, but it's not purely one
<thomi> that way the docstring can say "moves the cursor to the center point of the object. See `autopilot.input.get_center_point` for details on how the center point is calculated'

Thomi Richards (thomir) wrote :

just to give a bit more context:

I don't see any problem with making the 'get_center_point' function part of the public autopilot API, and documenting it as such. Once that's done, you can then change the docstring as I suggested on IRC.

To make get_center_point public:

1) Import it in the autopilot.input package. Make sure it appears in __all__. This should cause the docstring to appear in the auto-generated docs.

2) Change any code that uses that function to import it from autopilot.input, NOT from the private module.

3) profit!

Nicholas Skaggs (nskaggs) wrote :

Andrea. any chance you can make the tweaks Thomi suggests?

539. By Andrea Cerisara on 2016-01-08

Merged trunk.

540. By Andrea Cerisara on 2016-01-08

Made get_center_point public.

541. By Andrea Cerisara on 2016-01-08

Made get_center_point public.

Christopher Lee (veebers) wrote :

Hi Andrea, thanks for this. It looks good on a quick once over; I'm just in the process of getting the CI infra back up and running for the MPs so we'll have to wait on that unfortunately. I'll keep you in the loop :-)

Christopher Lee (veebers) wrote :

Looking good to me, a single query re: the inclusion of some docstring details.

Other than the docstring, it's LGTM

review: Needs Information
542. By Andrea Cerisara on 2016-01-26

Added missing doc.

review: Approve (continuous-integration)
platform-qa-bot (platform-qa-bot) wrote :

FAILED: Autolanding.
Approved revid is not set in launchpad. This is most likely a launchpad issue and re-approve should fix it. There is also a chance (although a very small one) this is a permission problem of the ps-jenkins bot.
https://platform-qa-jenkins.ubuntu.com/job/autopilot-autoland/1/
Executed test runs:
    SUCCESS: https://platform-qa-jenkins.ubuntu.com/job/build-wily-amd64-package/5
        deb: https://platform-qa-jenkins.ubuntu.com/job/build-wily-amd64-package/5/artifact/work/output/*zip*/output.zip
    SUCCESS: https://platform-qa-jenkins.ubuntu.com/job/build-wily-i386-package/6
        deb: https://platform-qa-jenkins.ubuntu.com/job/build-wily-i386-package/6/artifact/work/output/*zip*/output.zip
    None: https://platform-qa-jenkins.ubuntu.com/job/generic-land-mp/1/console

review: Needs Fixing (continuous-integration)
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/input/_X11.py'
2--- autopilot/input/_X11.py 2014-10-30 23:42:46 +0000
3+++ autopilot/input/_X11.py 2016-01-26 08:08:41 +0000
4@@ -26,6 +26,7 @@
5
6 import logging
7
8+from autopilot.input import get_center_point
9 from autopilot.display import is_point_on_any_screen, move_mouse_to_screen
10 from autopilot.utilities import (
11 EventDelay,
12@@ -395,57 +396,12 @@
13 def move_to_object(self, object_proxy):
14 """Attempts to move the mouse to 'object_proxy's centre point.
15
16- It does this by looking for several attributes, in order. The first
17- attribute found will be used. The attributes used are (in order):
18-
19- * globalRect (x,y,w,h)
20- * center_x, center_y
21- * x, y, w, h
22-
23- :raises: **ValueError** if none of these attributes are found, or if an
24- attribute is of an incorrect type.
25+ See :py:meth:`~autopilot.input.get_center_point` for details on how
26+ the center point is calculated.
27
28 """
29- try:
30- x, y, w, h = object_proxy.globalRect
31- _logger.debug("Moving to object's globalRect coordinates.")
32- self.move(x+w/2, y+h/2)
33- return
34- except AttributeError:
35- pass
36- except (TypeError, ValueError):
37- raise ValueError(
38- "Object '%r' has globalRect attribute, but it is not of the "
39- "correct type" % object_proxy)
40-
41- try:
42- x, y = object_proxy.center_x, object_proxy.center_y
43- _logger.debug("Moving to object's center_x, center_y coordinates.")
44- self.move(x, y)
45- return
46- except AttributeError:
47- pass
48- except (TypeError, ValueError):
49- raise ValueError(
50- "Object '%r' has center_x, center_y attributes, but they are "
51- "not of the correct type" % object_proxy)
52-
53- try:
54- x, y, w, h = (
55- object_proxy.x, object_proxy.y, object_proxy.w, object_proxy.h)
56- _logger.debug(
57- "Moving to object's center point calculated from x,y,w,h "
58- "attributes.")
59- self.move(x+w/2, y+h/2)
60- return
61- except AttributeError:
62- raise ValueError(
63- "Object '%r' does not have any recognised position "
64- "attributes" % object_proxy)
65- except (TypeError, ValueError):
66- raise ValueError(
67- "Object '%r' has x,y attribute, but they are not of the "
68- "correct type" % object_proxy)
69+ x, y = get_center_point(object_proxy)
70+ self.move(x, y)
71
72 def position(self):
73 """
74
75=== modified file 'autopilot/input/__init__.py'
76--- autopilot/input/__init__.py 2015-08-19 00:25:00 +0000
77+++ autopilot/input/__init__.py 2016-01-26 08:08:41 +0000
78@@ -57,14 +57,17 @@
79
80 from collections import OrderedDict
81 from contextlib import contextmanager
82+from autopilot.input._common import get_center_point
83 from autopilot.utilities import _pick_backend, CleanupRegistered
84-from autopilot.input._common import get_center_point
85
86 import logging
87
88 _logger = logging.getLogger(__name__)
89
90
91+__all__ = ['get_center_point']
92+
93+
94 class Keyboard(CleanupRegistered):
95
96 """A simple keyboard device class.
97@@ -653,23 +656,19 @@
98 press_duration=0.10,
99 time_between_events=0.1):
100 """
101- Attempts to move the pointer to 'object_proxy's centre point.
102- and click a button
103-
104- It does this by looking for several attributes, in order. The first
105- attribute found will be used. The attributes used are (in order):
106-
107- * globalRect (x,y,w,h)
108- * center_x, center_y
109- * x, y, w, h
110+ Attempts to move the pointer to 'object_proxy's centre point
111+ and click a button.
112+
113+ See :py:meth:`~autopilot.input.get_center_point` for details on how
114+ the center point is calculated.
115
116 If the wrapped device is a mouse, the button specification is used. If
117 it is a touch device, passing anything other than 1 will raise a
118 ValueError exception.
119
120 :param time_between_events: takes floating point to represent the
121- delay time between subsequent clicks/taps. Default value 0.1
122- represents tenth of a second.
123+ delay time between subsequent clicks/taps. Default value 0.1
124+ represents tenth of a second.
125
126 """
127
128@@ -679,15 +678,8 @@
129 def move_to_object(self, object_proxy):
130 """Attempts to move the pointer to 'object_proxy's centre point.
131
132- It does this by looking for several attributes, in order. The first
133- attribute found will be used. The attributes used are (in order):
134-
135- * globalRect (x,y,w,h)
136- * center_x, center_y
137- * x, y, w, h
138-
139- :raises: **ValueError** if none of these attributes are found, or if an
140- attribute is of an incorrect type.
141+ See :py:meth:`~autopilot.input.get_center_point` for details on how
142+ the center point is calculated.
143
144 """
145 x, y = get_center_point(object_proxy)
146
147=== modified file 'autopilot/input/_common.py'
148--- autopilot/input/_common.py 2014-03-25 14:42:25 +0000
149+++ autopilot/input/_common.py 2016-01-26 08:08:41 +0000
150@@ -29,7 +29,11 @@
151 """Get the center point of an object.
152
153 It searches for several different ways of determining exactly where the
154- center is.
155+ center is. The attributes used are (in order):
156+
157+ * globalRect (x,y,w,h)
158+ * center_x, center_y
159+ * x, y, w, h
160
161 :raises ValueError: if `object_proxy` has the globalRect attribute but it
162 is not of the correct type.
163
164=== modified file 'autopilot/input/_uinput.py'
165--- autopilot/input/_uinput.py 2015-07-07 22:12:40 +0000
166+++ autopilot/input/_uinput.py 2016-01-26 08:08:41 +0000
167@@ -25,7 +25,7 @@
168
169 from autopilot.input import Keyboard as KeyboardBase
170 from autopilot.input import Touch as TouchBase
171-from autopilot.input._common import get_center_point
172+from autopilot.input import get_center_point
173 from autopilot.utilities import deprecated, EventDelay, sleep
174
175
176
177=== modified file 'autopilot/tests/functional/test_input_stack.py'
178--- autopilot/tests/functional/test_input_stack.py 2015-08-19 00:25:00 +0000
179+++ autopilot/tests/functional/test_input_stack.py 2016-01-26 08:08:41 +0000
180@@ -43,8 +43,7 @@
181 )
182 from autopilot.display import Display
183 from autopilot.gestures import pinch
184-from autopilot.input import Keyboard, Mouse, Pointer, Touch
185-from autopilot.input._common import get_center_point
186+from autopilot.input import Keyboard, Mouse, Pointer, Touch, get_center_point
187 from autopilot.matchers import Eventually
188 from autopilot.testcase import AutopilotTestCase, multiply_scenarios
189 from autopilot.tests.functional import QmlScriptRunnerMixin
190
191=== modified file 'autopilot/tests/unit/test_input.py'
192--- autopilot/tests/unit/test_input.py 2015-07-07 22:50:24 +0000
193+++ autopilot/tests/unit/test_input.py 2016-01-26 08:08:41 +0000
194@@ -30,8 +30,7 @@
195 tests,
196 utilities
197 )
198-from autopilot.input import _uinput
199-from autopilot.input._common import get_center_point
200+from autopilot.input import _uinput, get_center_point
201
202
203 class Empty(object):

Subscribers

People subscribed via source and target branches