Merge lp:~canonical-platform-qa/autopilot/fix1268782-press_duration into lp:autopilot

Proposed by Leo Arias
Status: Merged
Approved by: Christopher Lee
Approved revision: 517
Merged at revision: 512
Proposed branch: lp:~canonical-platform-qa/autopilot/fix1268782-press_duration
Merge into: lp:autopilot
Diff against target: 157 lines (+63/-13)
3 files modified
autopilot/input/__init__.py (+3/-3)
autopilot/input/_uinput.py (+4/-4)
autopilot/tests/unit/test_input.py (+56/-6)
To merge this branch: bzr merge lp:~canonical-platform-qa/autopilot/fix1268782-press_duration
Reviewer Review Type Date Requested Status
Christopher Lee (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+231678@code.launchpad.net

Commit message

Add the press duration argument to touch clicks.

To post a comment you must log in.
515. By Leo Arias

    No need to mock the sleep again.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:515
http://jenkins.qa.ubuntu.com/job/autopilot-ci/849/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-amd64-ci/124
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-amd64-ci/124/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-armhf-ci/123
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-armhf-ci/123/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-i386-ci/123
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-i386-ci/123/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/3888
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic-autopilot/285
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/3748
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/5135
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/5135/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/11887
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic-autopilot/325
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/3281
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/3281/artifact/work/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Christopher Lee (veebers) wrote :

Looks good, just had one question:
  difflines 110, 119: is there a reason you're doing it this way and not using make_fake_object method (from that same test file?)

review: Needs Information
516. By Leo Arias

Use make_fake_object.

517. By Leo Arias

Also update the other use of make_fake_object.

Revision history for this message
Leo Arias (elopio) wrote :

I didn't see that function. I've pushed a new version following your advice. I also updated other test that wasn't using it, that's where I copied the statement from.

Thanks veebers.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:517
http://jenkins.qa.ubuntu.com/job/autopilot-ci/850/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-amd64-ci/125
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-amd64-ci/125/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-armhf-ci/124
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-armhf-ci/124/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-i386-ci/124
        deb: http://jenkins.qa.ubuntu.com/job/autopilot-utopic-i386-ci/124/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/4021
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic-autopilot/286
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/3863
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/5273
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/5273/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/12091
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic-autopilot/326
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/3384
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/3384/artifact/work/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Christopher Lee (veebers) wrote :

Awesome, cheers.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/input/__init__.py'
2--- autopilot/input/__init__.py 2014-03-25 14:42:25 +0000
3+++ autopilot/input/__init__.py 2014-08-26 05:24:44 +0000
4@@ -440,11 +440,11 @@
5 """
6 raise NotImplementedError("You cannot use this class directly.")
7
8- def tap(self, x, y):
9+ def tap(self, x, y, press_duration=0.1):
10 """Click (or 'tap') at given x,y coordinates."""
11 raise NotImplementedError("You cannot use this class directly.")
12
13- def tap_object(self, object):
14+ def tap_object(self, object, press_duration=0.1):
15 """Tap the center point of a given object.
16
17 It does this by looking for several attributes, in order. The first
18@@ -610,7 +610,7 @@
19 if button != 1:
20 raise ValueError(
21 "Touch devices do not have button %d" % (button))
22- self._device.tap(self._x, self._y)
23+ self._device.tap(self._x, self._y, press_duration=press_duration)
24
25 def move(self, x, y):
26 """Moves the pointer to the specified coordinates.
27
28=== modified file 'autopilot/input/_uinput.py'
29--- autopilot/input/_uinput.py 2014-07-30 10:18:17 +0000
30+++ autopilot/input/_uinput.py 2014-08-26 05:24:44 +0000
31@@ -460,7 +460,7 @@
32 def pressed(self):
33 return self._device.pressed
34
35- def tap(self, x, y):
36+ def tap(self, x, y, press_duration=0.1):
37 """Click (or 'tap') at given x and y coordinates.
38
39 :raises RuntimeError: if the finger is already pressed.
40@@ -469,10 +469,10 @@
41 """
42 _logger.debug("Tapping at: %d,%d", x, y)
43 self._device.finger_down(x, y)
44- sleep(0.1)
45+ sleep(press_duration)
46 self._device.finger_up()
47
48- def tap_object(self, object_):
49+ def tap_object(self, object_, press_duration=0.1):
50 """Click (or 'tap') a given object.
51
52 :raises RuntimeError: if the finger is already pressed.
53@@ -483,7 +483,7 @@
54 """
55 _logger.debug("Tapping object: %r", object)
56 x, y = get_center_point(object_)
57- self.tap(x, y)
58+ self.tap(x, y, press_duration=press_duration)
59
60 def press(self, x, y):
61 """Press and hold a given object or at the given coordinates.
62
63=== modified file 'autopilot/tests/unit/test_input.py'
64--- autopilot/tests/unit/test_input.py 2014-05-20 08:53:21 +0000
65+++ autopilot/tests/unit/test_input.py 2014-08-26 05:24:44 +0000
66@@ -652,24 +652,26 @@
67
68 def get_touch_with_mocked_backend(self):
69 touch = _uinput.Touch(device_class=Mock)
70- touch._device.mock_add_spec(
71- _uinput._UInputTouchDevice, spec_set=True)
72+ touch._device.mock_add_spec(_uinput._UInputTouchDevice)
73 return touch
74
75- def test_tap_must_put_finger_down_and_then_up(self):
76+ def test_tap_must_put_finger_down_then_sleep_and_then_put_finger_up(self):
77 expected_calls = [
78 call.finger_down(0, 0),
79+ call.sleep(ANY),
80 call.finger_up()
81 ]
82
83 touch = self.get_touch_with_mocked_backend()
84- touch.tap(0, 0)
85+ with patch('autopilot.input._uinput.sleep') as mock_sleep:
86+ touch._device.attach_mock(mock_sleep, 'sleep')
87+ touch.tap(0, 0)
88 self.assertEqual(expected_calls, touch._device.mock_calls)
89
90 def test_tap_object_must_put_finger_down_and_then_up_on_the_center(self):
91- object_ = type('Dummy', (object,), {'globalRect': (0, 0, 10, 10)})
92+ object_ = make_fake_object(center=True)
93 expected_calls = [
94- call.finger_down(5, 5),
95+ call.finger_down(object_.center_x, object_.center_y),
96 call.finger_up()
97 ]
98
99@@ -746,6 +748,40 @@
100 touch.drag(0, 0, 0, 0)
101 self.assertEqual(expected_calls, touch._device.mock_calls)
102
103+ def test_tap_without_press_duration_must_sleep_default_time(self):
104+ touch = self.get_touch_with_mocked_backend()
105+
106+ touch.tap(0, 0)
107+
108+ self.assertEqual(utilities.sleep.total_time_slept(), 0.1)
109+
110+ def test_tap_with_press_duration_must_sleep_specified_time(self):
111+ touch = self.get_touch_with_mocked_backend()
112+
113+ touch.tap(0, 0, press_duration=10)
114+
115+ self.assertEqual(utilities.sleep.total_time_slept(), 10)
116+
117+ def test_tap_object_without_duration_must_call_tap_with_default_time(self):
118+ object_ = make_fake_object(center=True)
119+ touch = self.get_touch_with_mocked_backend()
120+
121+ with patch.object(touch, 'tap') as mock_tap:
122+ touch.tap_object(object_)
123+
124+ mock_tap.assert_called_once_with(
125+ object_.center_x, object_.center_y, press_duration=0.1)
126+
127+ def test_tap_object_with_duration_must_call_tap_with_specified_time(self):
128+ object_ = make_fake_object(center=True)
129+ touch = self.get_touch_with_mocked_backend()
130+
131+ with patch.object(touch, 'tap') as mock_tap:
132+ touch.tap_object(object_, press_duration=10)
133+
134+ mock_tap.assert_called_once_with(
135+ object_.center_x, object_.center_y, press_duration=10)
136+
137
138 class MultipleUInputTouchBackend(_uinput._UInputTouchDevice):
139
140@@ -885,3 +921,17 @@
141
142 mock_drag.assert_called_once_with(
143 0, 0, 20, 20, rate=10, time_between_events=0.01)
144+
145+ def test_click_with_default_press_duration(self):
146+ pointer = self.get_pointer_with_touch_backend_with_mock_device()
147+ with patch.object(pointer._device, 'tap') as mock_tap:
148+ pointer.click(1)
149+
150+ mock_tap.assert_called_once_with(0, 0, press_duration=0.1)
151+
152+ def test_press_with_specified_press_duration(self):
153+ pointer = self.get_pointer_with_touch_backend_with_mock_device()
154+ with patch.object(pointer._device, 'tap') as mock_tap:
155+ pointer.click(1, press_duration=10)
156+
157+ mock_tap.assert_called_once_with(0, 0, press_duration=10)

Subscribers

People subscribed via source and target branches