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
=== modified file 'autopilot/input/__init__.py'
--- autopilot/input/__init__.py 2014-03-25 14:42:25 +0000
+++ autopilot/input/__init__.py 2014-08-26 05:24:44 +0000
@@ -440,11 +440,11 @@
440 """440 """
441 raise NotImplementedError("You cannot use this class directly.")441 raise NotImplementedError("You cannot use this class directly.")
442442
443 def tap(self, x, y):443 def tap(self, x, y, press_duration=0.1):
444 """Click (or 'tap') at given x,y coordinates."""444 """Click (or 'tap') at given x,y coordinates."""
445 raise NotImplementedError("You cannot use this class directly.")445 raise NotImplementedError("You cannot use this class directly.")
446446
447 def tap_object(self, object):447 def tap_object(self, object, press_duration=0.1):
448 """Tap the center point of a given object.448 """Tap the center point of a given object.
449449
450 It does this by looking for several attributes, in order. The first450 It does this by looking for several attributes, in order. The first
@@ -610,7 +610,7 @@
610 if button != 1:610 if button != 1:
611 raise ValueError(611 raise ValueError(
612 "Touch devices do not have button %d" % (button))612 "Touch devices do not have button %d" % (button))
613 self._device.tap(self._x, self._y)613 self._device.tap(self._x, self._y, press_duration=press_duration)
614614
615 def move(self, x, y):615 def move(self, x, y):
616 """Moves the pointer to the specified coordinates.616 """Moves the pointer to the specified coordinates.
617617
=== modified file 'autopilot/input/_uinput.py'
--- autopilot/input/_uinput.py 2014-07-30 10:18:17 +0000
+++ autopilot/input/_uinput.py 2014-08-26 05:24:44 +0000
@@ -460,7 +460,7 @@
460 def pressed(self):460 def pressed(self):
461 return self._device.pressed461 return self._device.pressed
462462
463 def tap(self, x, y):463 def tap(self, x, y, press_duration=0.1):
464 """Click (or 'tap') at given x and y coordinates.464 """Click (or 'tap') at given x and y coordinates.
465465
466 :raises RuntimeError: if the finger is already pressed.466 :raises RuntimeError: if the finger is already pressed.
@@ -469,10 +469,10 @@
469 """469 """
470 _logger.debug("Tapping at: %d,%d", x, y)470 _logger.debug("Tapping at: %d,%d", x, y)
471 self._device.finger_down(x, y)471 self._device.finger_down(x, y)
472 sleep(0.1)472 sleep(press_duration)
473 self._device.finger_up()473 self._device.finger_up()
474474
475 def tap_object(self, object_):475 def tap_object(self, object_, press_duration=0.1):
476 """Click (or 'tap') a given object.476 """Click (or 'tap') a given object.
477477
478 :raises RuntimeError: if the finger is already pressed.478 :raises RuntimeError: if the finger is already pressed.
@@ -483,7 +483,7 @@
483 """483 """
484 _logger.debug("Tapping object: %r", object)484 _logger.debug("Tapping object: %r", object)
485 x, y = get_center_point(object_)485 x, y = get_center_point(object_)
486 self.tap(x, y)486 self.tap(x, y, press_duration=press_duration)
487487
488 def press(self, x, y):488 def press(self, x, y):
489 """Press and hold a given object or at the given coordinates.489 """Press and hold a given object or at the given coordinates.
490490
=== modified file 'autopilot/tests/unit/test_input.py'
--- autopilot/tests/unit/test_input.py 2014-05-20 08:53:21 +0000
+++ autopilot/tests/unit/test_input.py 2014-08-26 05:24:44 +0000
@@ -652,24 +652,26 @@
652652
653 def get_touch_with_mocked_backend(self):653 def get_touch_with_mocked_backend(self):
654 touch = _uinput.Touch(device_class=Mock)654 touch = _uinput.Touch(device_class=Mock)
655 touch._device.mock_add_spec(655 touch._device.mock_add_spec(_uinput._UInputTouchDevice)
656 _uinput._UInputTouchDevice, spec_set=True)
657 return touch656 return touch
658657
659 def test_tap_must_put_finger_down_and_then_up(self):658 def test_tap_must_put_finger_down_then_sleep_and_then_put_finger_up(self):
660 expected_calls = [659 expected_calls = [
661 call.finger_down(0, 0),660 call.finger_down(0, 0),
661 call.sleep(ANY),
662 call.finger_up()662 call.finger_up()
663 ]663 ]
664664
665 touch = self.get_touch_with_mocked_backend()665 touch = self.get_touch_with_mocked_backend()
666 touch.tap(0, 0)666 with patch('autopilot.input._uinput.sleep') as mock_sleep:
667 touch._device.attach_mock(mock_sleep, 'sleep')
668 touch.tap(0, 0)
667 self.assertEqual(expected_calls, touch._device.mock_calls)669 self.assertEqual(expected_calls, touch._device.mock_calls)
668670
669 def test_tap_object_must_put_finger_down_and_then_up_on_the_center(self):671 def test_tap_object_must_put_finger_down_and_then_up_on_the_center(self):
670 object_ = type('Dummy', (object,), {'globalRect': (0, 0, 10, 10)})672 object_ = make_fake_object(center=True)
671 expected_calls = [673 expected_calls = [
672 call.finger_down(5, 5),674 call.finger_down(object_.center_x, object_.center_y),
673 call.finger_up()675 call.finger_up()
674 ]676 ]
675677
@@ -746,6 +748,40 @@
746 touch.drag(0, 0, 0, 0)748 touch.drag(0, 0, 0, 0)
747 self.assertEqual(expected_calls, touch._device.mock_calls)749 self.assertEqual(expected_calls, touch._device.mock_calls)
748750
751 def test_tap_without_press_duration_must_sleep_default_time(self):
752 touch = self.get_touch_with_mocked_backend()
753
754 touch.tap(0, 0)
755
756 self.assertEqual(utilities.sleep.total_time_slept(), 0.1)
757
758 def test_tap_with_press_duration_must_sleep_specified_time(self):
759 touch = self.get_touch_with_mocked_backend()
760
761 touch.tap(0, 0, press_duration=10)
762
763 self.assertEqual(utilities.sleep.total_time_slept(), 10)
764
765 def test_tap_object_without_duration_must_call_tap_with_default_time(self):
766 object_ = make_fake_object(center=True)
767 touch = self.get_touch_with_mocked_backend()
768
769 with patch.object(touch, 'tap') as mock_tap:
770 touch.tap_object(object_)
771
772 mock_tap.assert_called_once_with(
773 object_.center_x, object_.center_y, press_duration=0.1)
774
775 def test_tap_object_with_duration_must_call_tap_with_specified_time(self):
776 object_ = make_fake_object(center=True)
777 touch = self.get_touch_with_mocked_backend()
778
779 with patch.object(touch, 'tap') as mock_tap:
780 touch.tap_object(object_, press_duration=10)
781
782 mock_tap.assert_called_once_with(
783 object_.center_x, object_.center_y, press_duration=10)
784
749785
750class MultipleUInputTouchBackend(_uinput._UInputTouchDevice):786class MultipleUInputTouchBackend(_uinput._UInputTouchDevice):
751787
@@ -885,3 +921,17 @@
885921
886 mock_drag.assert_called_once_with(922 mock_drag.assert_called_once_with(
887 0, 0, 20, 20, rate=10, time_between_events=0.01)923 0, 0, 20, 20, rate=10, time_between_events=0.01)
924
925 def test_click_with_default_press_duration(self):
926 pointer = self.get_pointer_with_touch_backend_with_mock_device()
927 with patch.object(pointer._device, 'tap') as mock_tap:
928 pointer.click(1)
929
930 mock_tap.assert_called_once_with(0, 0, press_duration=0.1)
931
932 def test_press_with_specified_press_duration(self):
933 pointer = self.get_pointer_with_touch_backend_with_mock_device()
934 with patch.object(pointer._device, 'tap') as mock_tap:
935 pointer.click(1, press_duration=10)
936
937 mock_tap.assert_called_once_with(0, 0, press_duration=10)

Subscribers

People subscribed via source and target branches