Merge lp:~autopilot/autopilot/fix-test-failures into lp:autopilot

Proposed by Thomi Richards
Status: Merged
Approved by: Christopher Lee
Approved revision: 293
Merged at revision: 283
Proposed branch: lp:~autopilot/autopilot/fix-test-failures
Merge into: lp:autopilot
Diff against target: 193 lines (+68/-34)
3 files modified
autopilot/input/_uinput.py (+16/-22)
autopilot/tests/functional/test_input_stack.py (+44/-8)
autopilot/tests/unit/test_platform.py (+8/-4)
To merge this branch: bzr merge lp:~autopilot/autopilot/fix-test-failures
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Christopher Lee (community) Approve
Review via email: mp+176561@code.launchpad.net

This proposal supersedes a proposal from 2013-07-24.

Commit message

Fix failing tests.

Description of the change

Fix autopilot test suite failures.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:291
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~autopilot/autopilot/fix-test-failures/+merge/176561/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/autopilot-ci/171/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-saucy-amd64-ci/99
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-saucy-armhf-ci/99

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

review: Needs Fixing (continuous-integration)
292. By Thomi Richards

fix pep8

293. By Thomi Richards

Link bug report.

Revision history for this message
Christopher Lee (veebers) wrote :

Looks good to me.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
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/_uinput.py'
2--- autopilot/input/_uinput.py 2013-07-14 07:08:12 +0000
3+++ autopilot/input/_uinput.py 2013-07-24 02:38:25 +0000
4@@ -38,16 +38,21 @@
5 _PRESSED_KEYS = []
6
7
8+def _get_devnode_path():
9+ """Provide a fallback uinput node for devices which don't support udev"""
10+ devnode = '/dev/autopilot-uinput'
11+ if not os.path.exists(devnode):
12+ devnode = '/dev/uinput'
13+ return devnode
14+
15+
16 class Keyboard(KeyboardBase):
17
18- def __init__(self):
19- super(Keyboard, self).__init__()
20-
21- self._device = UInput(devnode=_get_devnode_path())
22+ _device = UInput(devnode=_get_devnode_path())
23
24 def _emit(self, event, value):
25- self._device.write(e.EV_KEY, event, value)
26- self._device.syn()
27+ Keyboard._device.write(e.EV_KEY, event, value)
28+ Keyboard._device.syn()
29
30 def _sanitise_keys(self, keys):
31 if keys == '+':
32@@ -91,14 +96,12 @@
33 """
34 if not isinstance(keys, basestring):
35 raise TypeError("'keys' argument must be a string.")
36- # logger.debug("Releasing keys %r with delay %f", keys, delay)
37- # # release keys in the reverse order they were pressed in.
38- # keys = self.__translate_keys(keys)
39+
40 for key in reversed(self._sanitise_keys(keys)):
41 for event in Keyboard._get_events_for_key(key):
42 logger.debug("Releasing %s (%r)", key, event)
43- if key in _PRESSED_KEYS:
44- _PRESSED_KEYS.remove(key)
45+ if event in _PRESSED_KEYS:
46+ _PRESSED_KEYS.remove(event)
47 self._emit(event, RELEASE)
48 sleep(delay)
49
50@@ -144,11 +147,10 @@
51 global _PRESSED_KEYS
52 if len(_PRESSED_KEYS) == 0:
53 return
54- _device = UInput(devnode=_get_devnode_path())
55
56 def _release(event):
57- _device.write(e.EV_KEY, event, RELEASE)
58- _device.syn()
59+ Keyboard._device.write(e.EV_KEY, event, RELEASE)
60+ Keyboard._device.syn()
61 for event in _PRESSED_KEYS:
62 logger.warning("Releasing key %r as part of cleanup call.", event)
63 _release(event)
64@@ -173,14 +175,6 @@
65 return events
66
67
68-def _get_devnode_path():
69- """Provide a fallback uinput node for devices which don't support udev"""
70- devnode = '/dev/autopilot-uinput'
71- if not os.path.exists(devnode):
72- devnode = '/dev/uinput'
73- return devnode
74-
75-
76 last_tracking_id = 0
77
78
79
80=== modified file 'autopilot/tests/functional/test_input_stack.py'
81--- autopilot/tests/functional/test_input_stack.py 2013-07-23 04:04:43 +0000
82+++ autopilot/tests/functional/test_input_stack.py 2013-07-24 02:38:25 +0000
83@@ -85,7 +85,11 @@
84 from autopilot.introspection.qt import QtApplicationLauncher
85 return QtApplicationLauncher()
86
87- def test_some_text(self):
88+ def test_text_typing(self):
89+ """Typing text must produce the correct characters in the target
90+ app.
91+
92+ """
93 app_proxy = self.start_mock_app()
94 text_edit = app_proxy.select_single('QTextEdit')
95
96@@ -96,7 +100,40 @@
97 keyboard = Keyboard.create(self.backend)
98 keyboard.type(self.input, 0.01)
99
100- self.assertThat(text_edit.plainText, Eventually(Equals(self.input)))
101+ self.assertThat(text_edit.plainText,
102+ Eventually(Equals(self.input)),
103+ "app shows: " + text_edit.plainText
104+ )
105+
106+ def test_keyboard_keys_are_released(self):
107+ """Typing characters must not leave keys pressed."""
108+ app_proxy = self.start_mock_app()
109+ text_edit = app_proxy.select_single('QTextEdit')
110+
111+ # make sure the text edit has keyboard focus:
112+ self.mouse.click_object(text_edit)
113+ keyboard = Keyboard.create(self.backend)
114+
115+ for character in self.input:
116+ self.assertThat(self._get_pressed_keys_list(), Equals([]))
117+ keyboard.type(character, 0.01)
118+ self.assertThat(self._get_pressed_keys_list(), Equals([]))
119+
120+ def _get_pressed_keys_list(self):
121+ """Get a list of keys pressed, but not released from the backend we're
122+ using.
123+
124+ """
125+ if self.backend == 'X11':
126+ from autopilot.input._X11 import _PRESSED_KEYS
127+ return _PRESSED_KEYS
128+ elif self.backend == 'UInput':
129+ from autopilot.input._uinput import _PRESSED_KEYS
130+ return _PRESSED_KEYS
131+ else:
132+ self.fail("Don't know how to get pressed keys list for backend "
133+ + self.backend
134+ )
135
136
137 class MouseTestCase(AutopilotTestCase):
138@@ -118,11 +155,10 @@
139
140 """
141 expected_exception = RuntimeError(
142- "Cannot create a mouse on the phablet devices."
143+ "Cannot create a Mouse on the phablet devices."
144 )
145 self.assertThat(lambda: Mouse.create(),
146- raises(expected_exception))
147-
148+ raises(expected_exception))
149
150
151 class TouchTests(AutopilotTestCase):
152@@ -177,15 +213,15 @@
153 self.assertThat(device._y, Equals(56))
154
155 def test_touch_drag_updates_coordinates(self):
156- """The Pointer wrapper must update it's x and y properties when wrapping
157- a touch object and performing a drag operation.
158+ """The Pointer wrapper must update it's x and y properties when
159+ wrapping a touch object and performing a drag operation.
160
161 """
162 class FakeTouch(Touch):
163 def __init__(self):
164 pass
165
166- def drag(self, x1,y1,x2,y2):
167+ def drag(self, x1, y1, x2, y2):
168 pass
169
170 p = Pointer(FakeTouch())
171
172=== modified file 'autopilot/tests/unit/test_platform.py'
173--- autopilot/tests/unit/test_platform.py 2013-07-22 03:27:40 +0000
174+++ autopilot/tests/unit/test_platform.py 2013-07-24 02:38:25 +0000
175@@ -30,10 +30,14 @@
176
177 class PlatformDetectorTests(TestCase):
178
179- def tearDown(self):
180- super(PlatformDetectorTests, self).tearDown()
181- # platform detector is cached, so destroy the cache at the end of each
182- # test:
183+ def setUp(self):
184+ super(PlatformDetectorTests, self).setUp()
185+ # platform detector is cached, so make sure we destroy the cache before
186+ # each test runs, and after each test completes.
187+ self._destroy_platform_detector_cache()
188+ self.addCleanup(self._destroy_platform_detector_cache)
189+
190+ def _destroy_platform_detector_cache(self):
191 platform._PlatformDetector._cached_detector = None
192
193 def test_platform_detector_is_cached(self):

Subscribers

People subscribed via source and target branches