Merge lp:~thomir-deactivatedaccount/autopilot/merge-private-code into lp:autopilot
- merge-private-code
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Thomi Richards | ||||
Approved revision: | 197 | ||||
Merged at revision: | 158 | ||||
Proposed branch: | lp:~thomir-deactivatedaccount/autopilot/merge-private-code | ||||
Merge into: | lp:autopilot | ||||
Diff against target: |
5734 lines (+2705/-1947) 60 files modified
autopilot/compizconfig.py (+0/-57) autopilot/display/_X11.py (+50/-0) autopilot/display/__init__.py (+136/-0) autopilot/display/_upa.py (+40/-0) autopilot/emulators.py (+21/-0) autopilot/emulators/X11.py (+0/-187) autopilot/emulators/__init__.py (+0/-11) autopilot/emulators/processmanager.py (+0/-66) autopilot/emulators/zeitgeist.py (+0/-66) autopilot/gestures.py (+62/-0) autopilot/glibrunner.py (+0/-26) autopilot/globals.py (+123/-21) autopilot/input/_X11.py (+4/-147) autopilot/input/__init__.py (+170/-76) autopilot/input/_common.py (+46/-0) autopilot/input/_uinput.py (+171/-275) autopilot/introspection/__init__.py (+85/-93) autopilot/introspection/dbus.py (+1/-1) autopilot/introspection/gtk.py (+4/-4) autopilot/introspection/qt.py (+3/-3) autopilot/keybindings.py (+50/-5) autopilot/matchers/__init__.py (+48/-3) autopilot/platform.py (+105/-0) autopilot/process/__init__.py (+403/-0) autopilot/process/_bamf.py (+145/-34) autopilot/testcase.py (+128/-390) autopilot/tests/test_ap_apps.py (+10/-6) autopilot/tests/test_application_mixin.py (+12/-25) autopilot/tests/test_application_registration.py (+0/-94) autopilot/tests/test_compiz_key_translate.py (+0/-69) autopilot/tests/test_compiz_option_support.py (+0/-31) autopilot/tests/test_keyboard.py (+2/-2) autopilot/tests/test_mouse_emulator.py (+2/-2) autopilot/tests/test_open_window.py (+4/-3) autopilot/tests/test_out_of_test_addcleanup.py (+34/-0) autopilot/tests/test_platform.py (+134/-0) autopilot/tests/test_process_emulator.py (+4/-4) autopilot/utilities.py (+43/-94) bin/autopilot (+11/-19) debian/changelog (+6/-0) debian/control (+1/-1) docs/_templates/indexcontent.html (+45/-0) docs/api/autopilot.rst (+7/-100) docs/api/display.rst (+7/-0) docs/api/emulators.rst (+20/-0) docs/api/gestures.rst (+6/-0) docs/api/input.rst (+7/-0) docs/api/introspection.rst (+6/-0) docs/api/matchers.rst (+6/-0) docs/api/platform.rst (+7/-0) docs/api/testcase.rst (+7/-0) docs/conf.py (+23/-6) docs/faq/faq.rst (+95/-15) docs/images/test_pyramid.svg (+134/-0) docs/images/test_stages.svg (+166/-0) docs/index.rst (+6/-10) docs/porting/porting.rst (+31/-0) docs/tutorial/tutorial.rst (+3/-0) docs/tutorial/what_is_autopilot.rst (+62/-0) setup.py (+9/-1) |
||||
To merge this branch: | bzr merge lp:~thomir-deactivatedaccount/autopilot/merge-private-code | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Sergio Schvezov | Needs Fixing | ||
Michael Zanetti (community) | Needs Fixing | ||
Review via email: mp+156425@code.launchpad.net |
Commit message
Merge in large changes for version 1.3.
Description of the change
This branch contains the 'new hotness' - large scale changes for autopilot 1.3.
Michael Zanetti (mzanetti) wrote : | # |
Olivier Tilloy (osomon) wrote : | # |
I built a package from this MR, installed on my raring desktop, and tried to run the autopilot tests for lp:webbrowser-app.
Listing the tests fails with the following error:
ImportError: cannot import name QtIntrospection
but can be easily fixed by simply removing this import, and not inheriting from QtIntrospection
Running the tests fails with the following error:
_StringException: Traceback (most recent call last):
File "/tmp/webbrowse
super(
File "/tmp/webbrowse
super(
File "/tmp/webbrowse
self.
File "/tmp/webbrowse
*self.ARGS)
File "/usr/lib/
process = launch_
File "/usr/lib/
path, args = launcher.
AttributeError: 'NoneType' object has no attribute 'prepare_
Looks like a problem in autopilot itself.
Michael Zanetti (mzanetti) wrote : | # |
I'd like to see some section in the docs that describe how to upgrade tests to be compatible with this version.
Sergio Schvezov (sergiusens) wrote : | # |
Packaging/docs need fixing
$ bzr bd
...
/home/sergiusen
make[1]: *** [override_
make[1]: Leaving directory `/home/
make: *** [build] Error 2
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:184
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:/
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 185. By Thomi Richards
-
Bump current version to v1.3.
Thomi Richards (thomir-deactivatedaccount) wrote : | # |
Hi Michael,
> There is no qmlscene in Qt4. It was the QWidget based "qmlviewer" back then.
> qmlscene is the new Qt5 version which directly paints qml on a openGL
> scenegraph.
Fixed. I'll add a second example that uses 'wmlscene' and specifies that it's for Qt5 as well. Note that the tutorial section of the documentation is unfinished - once that's complete this should become clearer.
Thomi Richards (thomir-deactivatedaccount) wrote : | # |
Hi Oliver
> I built a package from this MR, installed on my raring desktop, and tried to
> run the autopilot tests for lp:webbrowser-app.
>
Autopilot 1.3 (the version number has now been updated) contains API breaks from 1.2, you won't be able to run your old tests without changing them. However, see my comments below:
> Listing the tests fails with the following error:
>
> ImportError: cannot import name QtIntrospection
>
> but can be easily fixed by simply removing this import, and not inheriting
> from QtIntrospection
Yes - these Mixin Classes were rather nasty, and were the cause of many errors.
>
> Running the tests fails with the following error:
>
> _StringException: Traceback (most recent call last):
> File "/tmp/webbrowser-
> app/tests/
> setUp
> super(TestMainW
> File "/tmp/webbrowse
> line 161, in setUp
> super(BrowserTe
> File "/tmp/webbrowse
> line 45, in setUp
> self.launch_
> File "/tmp/webbrowse
> line 62, in launch_test_local
> *self.ARGS)
> File "/usr/lib/
> launch_
> process = launch_
> File "/usr/lib/
> line 80, in launch_application
> path, args = launcher.
> AttributeError: 'NoneType' object has no attribute 'prepare_
>
> Looks like a problem in autopilot itself.
Kind of :)
We should raise a better exception in this case, which I have just comitted to this branch:
if launcher is None:
raise RuntimeError(
the AutopilotTestCa
What's happening is that autopilot is trying to guess what kind of introspection support to load - Gtk or Qt. Currently it simply does 'ldd <app_path>' and looks for 'qtcore' or 'gtk' - clearly this isn't going to work for python/Qt or python/Gtk apps. I have plans to extend that auto-detection routine, so it works for python scripts automatically. However, you can specify the introspection type manually, by overriding the pick_app_launcher method. In fact, there' san autopilot test that does exactly that, in autopilot/
class QtTests(
def pick_app_
# force Qt app introspection:
from autopilot.
return QtApplicationLa
def test_can_
path = self.write_
from PyQt4.QtGui import QMainWindow, QAppli...
Thomi Richards (thomir-deactivatedaccount) wrote : | # |
> I'd like to see some section in the docs that describe how to upgrade tests to
> be compatible with this version.
Agreed:
- 186. By Thomi Richards
-
Fix problem with Qml launch example in documentation.
- 187. By Thomi Richards
-
Better error when autopilot cannot auto-detect the introspection type.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:185
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 188. By Thomi Richards
-
Marked top-level pages as :orphan: sphinx docs, since we have our own custom html page, instead of an index toctree element.
Thomi Richards (thomir-deactivatedaccount) wrote : | # |
Hi Sergio,
> Packaging/docs need fixing
>
> $ bzr bd
> ...
> /home/sergiusen
> area/autopilot-
> isn't included in any toctree
>
Fixed - this is because we have our own custom index page now.
Thanks,
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:188
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 189. By Thomi Richards
-
Merged chris's work with the process managaer.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:189
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 190. By Thomi Richards
-
Made a good start on new, better, introductory tutorial page.
- 191. By Thomi Richards
-
Documentation and setup.py now get version numbers from debian/changelog, rather than maintaining separate strings.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:191
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 192. By Thomi Richards
-
Merged trunk, resolved conflicts.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:192
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 193. By Thomi Richards
-
More docs.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:193
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 194. By Thomi Richards
-
Added the start of a porting document.
- 195. By Thomi Richards
-
Merge in process test fixes.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:195
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 196. By Thomi Richards
-
Turn off intersphinx support since we can't build it anyway, and testtools doesn't use sphinx for it's API docs.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:196
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 197. By Thomi Richards
-
Fix bullet list in porting document.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:197
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === renamed file 'autopilot/emulators/clipboard.py' => 'autopilot/clipboard.py' | |||
2 | === removed file 'autopilot/compizconfig.py' | |||
3 | --- autopilot/compizconfig.py 2012-08-27 21:26:45 +0000 | |||
4 | +++ autopilot/compizconfig.py 1970-01-01 00:00:00 +0000 | |||
5 | @@ -1,57 +0,0 @@ | |||
6 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
7 | 2 | # Copyright 2012 Canonical | ||
8 | 3 | # Author: Thomi Richards | ||
9 | 4 | # | ||
10 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
11 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
12 | 7 | # by the Free Software Foundation. | ||
13 | 8 | # | ||
14 | 9 | # This script is designed to run unity in a test drive manner. It will drive | ||
15 | 10 | # X and test the GL calls that Unity makes, so that we can easily find out if | ||
16 | 11 | # we are triggering graphics driver/X bugs. | ||
17 | 12 | |||
18 | 13 | """Functions that wrap compizconfig to avoid some unpleasantness in that module.""" | ||
19 | 14 | |||
20 | 15 | from __future__ import absolute_import | ||
21 | 16 | |||
22 | 17 | |||
23 | 18 | from autopilot.utilities import Silence | ||
24 | 19 | |||
25 | 20 | _global_context = None | ||
26 | 21 | |||
27 | 22 | def get_global_context(): | ||
28 | 23 | """Get the compizconfig global context object.""" | ||
29 | 24 | global _global_context | ||
30 | 25 | if _global_context is None: | ||
31 | 26 | with Silence(): | ||
32 | 27 | from compizconfig import Context | ||
33 | 28 | _global_context = Context() | ||
34 | 29 | return _global_context | ||
35 | 30 | |||
36 | 31 | |||
37 | 32 | def get_plugin(plugin_name): | ||
38 | 33 | """Get a compizconfig plugin with the specified name. | ||
39 | 34 | |||
40 | 35 | Raises KeyError of the plugin named does not exist. | ||
41 | 36 | |||
42 | 37 | """ | ||
43 | 38 | ctx = get_global_context() | ||
44 | 39 | with Silence(): | ||
45 | 40 | try: | ||
46 | 41 | return ctx.Plugins[plugin_name] | ||
47 | 42 | except KeyError: | ||
48 | 43 | raise KeyError("Compiz plugin '%s' does not exist." % (plugin_name)) | ||
49 | 44 | |||
50 | 45 | |||
51 | 46 | def get_setting(plugin_name, setting_name): | ||
52 | 47 | """Get a compizconfig setting object, given a plugin name and setting name. | ||
53 | 48 | |||
54 | 49 | Raises KeyError if the plugin or setting is not found. | ||
55 | 50 | |||
56 | 51 | """ | ||
57 | 52 | plugin = get_plugin(plugin_name) | ||
58 | 53 | with Silence(): | ||
59 | 54 | try: | ||
60 | 55 | return plugin.Screen[setting_name] | ||
61 | 56 | except KeyError: | ||
62 | 57 | raise KeyError("Compiz setting '%s' does not exist in plugin '%s'." % (setting_name, plugin_name)) | ||
63 | 58 | 0 | ||
64 | === renamed file 'autopilot/emulators/dbus_handler.py' => 'autopilot/dbus_handler.py' | |||
65 | === added directory 'autopilot/display' | |||
66 | === added file 'autopilot/display/_X11.py' | |||
67 | --- autopilot/display/_X11.py 1970-01-01 00:00:00 +0000 | |||
68 | +++ autopilot/display/_X11.py 2013-04-15 21:43:32 +0000 | |||
69 | @@ -0,0 +1,50 @@ | |||
70 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
71 | 2 | # Copyright 2013 Canonical | ||
72 | 3 | # Author: Christopher Lee | ||
73 | 4 | # | ||
74 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
75 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
76 | 7 | # by the Free Software Foundation. | ||
77 | 8 | |||
78 | 9 | import logging | ||
79 | 10 | |||
80 | 11 | from autopilot.display import Display as DisplayBase | ||
81 | 12 | |||
82 | 13 | logger = logging.getLogger(__name__) | ||
83 | 14 | |||
84 | 15 | class Display(DisplayBase): | ||
85 | 16 | def __init__(self): | ||
86 | 17 | # Note: MUST import these here, rather than at the top of the file. Why? | ||
87 | 18 | # Because sphinx imports these modules to build the API documentation, | ||
88 | 19 | # which in turn tries to import Gdk, which in turn fails because there's | ||
89 | 20 | # no DISPlAY environment set in the package builder. | ||
90 | 21 | from gi.repository import Gdk | ||
91 | 22 | self._default_screen = Gdk.Screen.get_default() | ||
92 | 23 | self._blacklisted_drivers = ["NVIDIA"] | ||
93 | 24 | |||
94 | 25 | def get_num_screens(self): | ||
95 | 26 | """Get the number of screens attached to the PC.""" | ||
96 | 27 | return self._default_screen.get_n_monitors() | ||
97 | 28 | |||
98 | 29 | def get_primary_screen(self): | ||
99 | 30 | """Returns an integer of which screen is considered the primary""" | ||
100 | 31 | return self._default_screen.get_primary_monitor() | ||
101 | 32 | |||
102 | 33 | def get_screen_width(self, screen_number=0): | ||
103 | 34 | # return self._default_screen.get_width() | ||
104 | 35 | return self.get_screen_geometry(screen_number)[2] | ||
105 | 36 | |||
106 | 37 | def get_screen_height(self, screen_number=0): | ||
107 | 38 | #return self._default_screen.get_height() | ||
108 | 39 | return self.get_screen_geometry(screen_number)[3] | ||
109 | 40 | |||
110 | 41 | def get_screen_geometry(self, screen_number): | ||
111 | 42 | """Get the geometry for a particular screen. | ||
112 | 43 | |||
113 | 44 | :return: Tuple containing (x, y, width, height). | ||
114 | 45 | |||
115 | 46 | """ | ||
116 | 47 | if screen_number < 0 or screen_number >= self.get_num_screens(): | ||
117 | 48 | raise ValueError('Specified screen number is out of range.') | ||
118 | 49 | rect = self._default_screen.get_monitor_geometry(screen_number) | ||
119 | 50 | return (rect.x, rect.y, rect.width, rect.height) | ||
120 | 0 | 51 | ||
121 | === added file 'autopilot/display/__init__.py' | |||
122 | --- autopilot/display/__init__.py 1970-01-01 00:00:00 +0000 | |||
123 | +++ autopilot/display/__init__.py 2013-04-15 21:43:32 +0000 | |||
124 | @@ -0,0 +1,136 @@ | |||
125 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
126 | 2 | # Copyright 2013 Canonical | ||
127 | 3 | # Author: Christopher Lee | ||
128 | 4 | # | ||
129 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
130 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
131 | 7 | # by the Free Software Foundation. | ||
132 | 8 | |||
133 | 9 | """The display module contaions support for getting screen information.""" | ||
134 | 10 | |||
135 | 11 | from collections import OrderedDict | ||
136 | 12 | from autopilot.utilities import _pick_variant | ||
137 | 13 | from autopilot.input import Mouse | ||
138 | 14 | |||
139 | 15 | |||
140 | 16 | def is_rect_on_screen(screen_number, rect): | ||
141 | 17 | """Returns True if *rect* is **entirely** on the specified screen, with no overlap.""" | ||
142 | 18 | (x, y, w, h) = rect | ||
143 | 19 | (mx, my, mw, mh) = Display.create().get_screen_geometry(screen_number) | ||
144 | 20 | return (x >= mx and x + w <= mx + mw and y >= my and y + h <= my + mh) | ||
145 | 21 | |||
146 | 22 | |||
147 | 23 | def is_point_on_screen(screen_number, point): | ||
148 | 24 | """Returns True if *point* is on the specified screen. | ||
149 | 25 | |||
150 | 26 | *point* must be an iterable type with two elements: (x, y) | ||
151 | 27 | |||
152 | 28 | """ | ||
153 | 29 | x, y = point | ||
154 | 30 | (mx, my, mw, mh) = Display.create().get_screen_geometry(screen_number) | ||
155 | 31 | return (x >= mx and x < mx + mw and y >= my and y < my + mh) | ||
156 | 32 | |||
157 | 33 | |||
158 | 34 | def is_point_on_any_screen(point): | ||
159 | 35 | """Returns true if *point* is on any currently configured screen.""" | ||
160 | 36 | return any([is_point_on_screen(m, point) for m in range(Display.create().get_num_screens())]) | ||
161 | 37 | |||
162 | 38 | |||
163 | 39 | def move_mouse_to_screen(screen_number): | ||
164 | 40 | """Move the mouse to the center of the specified screen.""" | ||
165 | 41 | geo = Display.create().get_screen_geometry(screen_number) | ||
166 | 42 | x = geo[0] + (geo[2] / 2) | ||
167 | 43 | y = geo[1] + (geo[3] / 2) | ||
168 | 44 | #dont animate this or it might not get there due to barriers | ||
169 | 45 | Mouse.create().move(x, y, False) | ||
170 | 46 | |||
171 | 47 | |||
172 | 48 | # veebers TODO: Write this so it's usable. | ||
173 | 49 | # def drag_window_to_screen(self, window, screen): | ||
174 | 50 | # """Drags *window* to *screen* | ||
175 | 51 | |||
176 | 52 | # :param BamfWindow window: The window to drag | ||
177 | 53 | # :param integer screen: The screen to drag the *window* to | ||
178 | 54 | # :raises: **TypeError** if *window* is not a BamfWindow | ||
179 | 55 | |||
180 | 56 | # """ | ||
181 | 57 | # if not isinstance(window, BamfWindow): | ||
182 | 58 | # raise TypeError("Window must be a BamfWindow") | ||
183 | 59 | |||
184 | 60 | # if window.monitor == screen: | ||
185 | 61 | # logger.debug("Window %r is already on screen %d." % (window.x_id, screen)) | ||
186 | 62 | # return | ||
187 | 63 | |||
188 | 64 | # assert(not window.is_maximized) | ||
189 | 65 | # (win_x, win_y, win_w, win_h) = window.geometry | ||
190 | 66 | # (mx, my, mw, mh) = self.get_screen_geometry(screen) | ||
191 | 67 | |||
192 | 68 | # logger.debug("Dragging window %r to screen %d." % (window.x_id, screen)) | ||
193 | 69 | |||
194 | 70 | # mouse = Mouse() | ||
195 | 71 | # keyboard = Keyboard() | ||
196 | 72 | # mouse.move(win_x + win_w/2, win_y + win_h/2) | ||
197 | 73 | # keyboard.press("Alt") | ||
198 | 74 | # mouse.press() | ||
199 | 75 | # keyboard.release("Alt") | ||
200 | 76 | |||
201 | 77 | # # We do the movements in two steps, to reduce the risk of being | ||
202 | 78 | # # blocked by the pointer barrier | ||
203 | 79 | # target_x = mx + mw/2 | ||
204 | 80 | # target_y = my + mh/2 | ||
205 | 81 | # mouse.move(win_x, target_y, rate=20, time_between_events=0.005) | ||
206 | 82 | # mouse.move(target_x, target_y, rate=20, time_between_events=0.005) | ||
207 | 83 | # mouse.release() | ||
208 | 84 | |||
209 | 85 | |||
210 | 86 | class Display: | ||
211 | 87 | """The base class/inteface for the display devices""" | ||
212 | 88 | |||
213 | 89 | @staticmethod | ||
214 | 90 | def create(preferred_variant=''): | ||
215 | 91 | """Get an instance of the Display class. | ||
216 | 92 | |||
217 | 93 | If variant is specified, it should be a string that specifies a backend to | ||
218 | 94 | use. However, this hint can be ignored - autopilot will prefer to return a | ||
219 | 95 | variant other than the one requested, rather than fail to return anything at | ||
220 | 96 | all. | ||
221 | 97 | |||
222 | 98 | If autopilot cannot instantate any of the possible backends, a RuntimeError | ||
223 | 99 | will be raised. | ||
224 | 100 | """ | ||
225 | 101 | def get_x11_display(): | ||
226 | 102 | from autopilot.display._X11 import Display | ||
227 | 103 | return Display() | ||
228 | 104 | |||
229 | 105 | def get_upa_display(): | ||
230 | 106 | from autopilot.display._upa import Display | ||
231 | 107 | return Display() | ||
232 | 108 | |||
233 | 109 | variants = OrderedDict() | ||
234 | 110 | variants['X11'] = get_x11_display | ||
235 | 111 | variants['UPA'] = get_upa_display | ||
236 | 112 | return _pick_variant(variants, preferred_variant) | ||
237 | 113 | |||
238 | 114 | class BlacklistedDriverError(RuntimeError): | ||
239 | 115 | """Cannot set primary monitor when running drivers listed in the driver blacklist.""" | ||
240 | 116 | |||
241 | 117 | def get_num_screens(self): | ||
242 | 118 | """Get the number of screens attached to the PC.""" | ||
243 | 119 | raise NotImplementedError("You cannot use this class directly.") | ||
244 | 120 | |||
245 | 121 | def get_primary_screen(self): | ||
246 | 122 | raise NotImplementedError("You cannot use this class directly.") | ||
247 | 123 | |||
248 | 124 | def get_screen_width(self, screen_number=0): | ||
249 | 125 | raise NotImplementedError("You cannot use this class directly.") | ||
250 | 126 | |||
251 | 127 | def get_screen_height(self, screen_number=0): | ||
252 | 128 | raise NotImplementedError("You cannot use this class directly.") | ||
253 | 129 | |||
254 | 130 | def get_screen_geometry(self, monitor_number): | ||
255 | 131 | """Get the geometry for a particular monitor. | ||
256 | 132 | |||
257 | 133 | :return: Tuple containing (x, y, width, height). | ||
258 | 134 | |||
259 | 135 | """ | ||
260 | 136 | raise NotImplementedError("You cannot use this class directly.") | ||
261 | 0 | 137 | ||
262 | === added file 'autopilot/display/_upa.py' | |||
263 | --- autopilot/display/_upa.py 1970-01-01 00:00:00 +0000 | |||
264 | +++ autopilot/display/_upa.py 2013-04-15 21:43:32 +0000 | |||
265 | @@ -0,0 +1,40 @@ | |||
266 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
267 | 2 | # Copyright 2013 Canonical | ||
268 | 3 | # Author: Christopher Lee | ||
269 | 4 | # | ||
270 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
271 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
272 | 7 | # by the Free Software Foundation. | ||
273 | 8 | |||
274 | 9 | import logging | ||
275 | 10 | |||
276 | 11 | from autopilot.display import Display as DisplayBase | ||
277 | 12 | from upa import get_resolution | ||
278 | 13 | |||
279 | 14 | logger = logging.getLogger(__name__) | ||
280 | 15 | |||
281 | 16 | class Display(DisplayBase): | ||
282 | 17 | """The base class/inteface for the display devices""" | ||
283 | 18 | |||
284 | 19 | def get_num_screens(self): | ||
285 | 20 | """Get the number of screens attached to the PC.""" | ||
286 | 21 | return 1 | ||
287 | 22 | |||
288 | 23 | def get_primary_screen(self): | ||
289 | 24 | """Returns an integer of which screen is considered the primary""" | ||
290 | 25 | return 0 | ||
291 | 26 | |||
292 | 27 | def get_screen_width(self): | ||
293 | 28 | return get_resolution()[0] | ||
294 | 29 | |||
295 | 30 | def get_screen_height(self): | ||
296 | 31 | return get_resolution()[1] | ||
297 | 32 | |||
298 | 33 | def get_screen_geometry(self, screen_number): | ||
299 | 34 | """Get the geometry for a particular screen. | ||
300 | 35 | |||
301 | 36 | :return: Tuple containing (x, y, width, height). | ||
302 | 37 | |||
303 | 38 | """ | ||
304 | 39 | res = get_resolution() | ||
305 | 40 | return (0, 0, res[0], res[1]) | ||
306 | 0 | 41 | ||
307 | === removed directory 'autopilot/emulators' | |||
308 | === added file 'autopilot/emulators.py' | |||
309 | --- autopilot/emulators.py 1970-01-01 00:00:00 +0000 | |||
310 | +++ autopilot/emulators.py 2013-04-15 21:43:32 +0000 | |||
311 | @@ -0,0 +1,21 @@ | |||
312 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
313 | 2 | # Copyright 2013 Canonical | ||
314 | 3 | # Author: Thomi Richards | ||
315 | 4 | # | ||
316 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
317 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
318 | 7 | # by the Free Software Foundation. | ||
319 | 8 | # | ||
320 | 9 | # This script is designed to run unity in a test drive manner. It will drive | ||
321 | 10 | # X and test the GL calls that Unity makes, so that we can easily find out if | ||
322 | 11 | # we are triggering graphics driver/X bugs. | ||
323 | 12 | |||
324 | 13 | import autopilot.display as display | ||
325 | 14 | import autopilot.clipboard as clipboard | ||
326 | 15 | import autopilot.dbus_handler as dbus_handler | ||
327 | 16 | import autopilot.ibus as ibus | ||
328 | 17 | import autopilot.input as input | ||
329 | 18 | |||
330 | 19 | |||
331 | 20 | """ | ||
332 | 21 | """ | ||
333 | 0 | 22 | ||
334 | === removed file 'autopilot/emulators/X11.py' | |||
335 | --- autopilot/emulators/X11.py 2013-03-03 21:21:08 +0000 | |||
336 | +++ autopilot/emulators/X11.py 1970-01-01 00:00:00 +0000 | |||
337 | @@ -1,187 +0,0 @@ | |||
338 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
339 | 2 | # Copyright 2010 Canonical | ||
340 | 3 | # Author: Alex Launi | ||
341 | 4 | # | ||
342 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
343 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
344 | 7 | # by the Free Software Foundation. | ||
345 | 8 | # | ||
346 | 9 | # This script is designed to run unity in a test drive manner. It will drive | ||
347 | 10 | # X and test the GL calls that Unity makes, so that we can easily find out if | ||
348 | 11 | # we are triggering graphics driver/X bugs. | ||
349 | 12 | |||
350 | 13 | """A collection of emulators for X11 - namely keyboards and mice. | ||
351 | 14 | |||
352 | 15 | In the future we may also need other devices. | ||
353 | 16 | |||
354 | 17 | """ | ||
355 | 18 | |||
356 | 19 | from __future__ import absolute_import | ||
357 | 20 | |||
358 | 21 | import logging | ||
359 | 22 | import os | ||
360 | 23 | import subprocess | ||
361 | 24 | |||
362 | 25 | from autopilot.emulators.bamf import BamfWindow | ||
363 | 26 | from autopilot.emulators.input import get_keyboard, get_mouse | ||
364 | 27 | from autopilot.utilities import deprecated | ||
365 | 28 | |||
366 | 29 | |||
367 | 30 | logger = logging.getLogger(__name__) | ||
368 | 31 | |||
369 | 32 | |||
370 | 33 | def reset_display(): | ||
371 | 34 | from autopilot.emulators.input._X11 import reset_display | ||
372 | 35 | reset_display() | ||
373 | 36 | |||
374 | 37 | |||
375 | 38 | # Keyboard and Mouse are no longer here. This is for backwards compatibility, | ||
376 | 39 | # but will eventually dissapear. | ||
377 | 40 | @deprecated('autopilot.emulators.input.get_keyboard') | ||
378 | 41 | def Keyboard(): | ||
379 | 42 | return get_keyboard() | ||
380 | 43 | |||
381 | 44 | |||
382 | 45 | @deprecated('autopilot.emulators.input.get_mouse') | ||
383 | 46 | def Mouse(): | ||
384 | 47 | return get_mouse() | ||
385 | 48 | |||
386 | 49 | |||
387 | 50 | class ScreenGeometry: | ||
388 | 51 | """Get details about screen geometry.""" | ||
389 | 52 | |||
390 | 53 | class BlacklistedDriverError(RuntimeError): | ||
391 | 54 | """Cannot set primary monitor when running drivers listed in the driver blacklist.""" | ||
392 | 55 | |||
393 | 56 | def __init__(self): | ||
394 | 57 | # Note: MUST import these here, rather than at the top of the file. Why? | ||
395 | 58 | # Because sphinx imports these modules to build the API documentation, | ||
396 | 59 | # which in turn tries to import Gdk, which in turn fails because there's | ||
397 | 60 | # no DISPlAY environment set in the package builder. | ||
398 | 61 | from gi.repository import Gdk | ||
399 | 62 | self._default_screen = Gdk.Screen.get_default() | ||
400 | 63 | self._blacklisted_drivers = ["NVIDIA"] | ||
401 | 64 | |||
402 | 65 | def get_num_monitors(self): | ||
403 | 66 | """Get the number of monitors attached to the PC.""" | ||
404 | 67 | return self._default_screen.get_n_monitors() | ||
405 | 68 | |||
406 | 69 | def get_primary_monitor(self): | ||
407 | 70 | return self._default_screen.get_primary_monitor() | ||
408 | 71 | |||
409 | 72 | def set_primary_monitor(self, monitor): | ||
410 | 73 | """Set *monitor* to be the primary monitor. | ||
411 | 74 | |||
412 | 75 | :param int monitor: Must be between 0 and the number of configured | ||
413 | 76 | monitors. | ||
414 | 77 | :raises: **ValueError** if an invalid monitor is specified. | ||
415 | 78 | :raises: **BlacklistedDriverError** if your video driver does not | ||
416 | 79 | support this. | ||
417 | 80 | |||
418 | 81 | """ | ||
419 | 82 | try: | ||
420 | 83 | glxinfo_out = subprocess.check_output("glxinfo") | ||
421 | 84 | except OSError, e: | ||
422 | 85 | raise OSError("Failed to run glxinfo: %s. (do you have mesa-utils installed?)" % e) | ||
423 | 86 | |||
424 | 87 | for dri in self._blacklisted_drivers: | ||
425 | 88 | if dri in glxinfo_out: | ||
426 | 89 | raise ScreenGeometry.BlacklistedDriverError('Impossible change the primary monitor for the given driver') | ||
427 | 90 | |||
428 | 91 | if monitor < 0 or monitor >= self.get_num_monitors(): | ||
429 | 92 | raise ValueError('Monitor %d is not in valid range of 0 <= monitor < %d.' % (self.get_num_monitors())) | ||
430 | 93 | |||
431 | 94 | monitor_name = self._default_screen.get_monitor_plug_name(monitor) | ||
432 | 95 | |||
433 | 96 | if not monitor_name: | ||
434 | 97 | raise ValueError('Could not get monitor name from monitor number %d.' % (monitor)) | ||
435 | 98 | |||
436 | 99 | ret = os.spawnlp(os.P_WAIT, "xrandr", "xrandr", "--output", monitor_name, "--primary") | ||
437 | 100 | |||
438 | 101 | if ret != 0: | ||
439 | 102 | raise RuntimeError('Xrandr can\'t set the primary monitor. error code: %d' % (ret)) | ||
440 | 103 | |||
441 | 104 | def get_screen_width(self): | ||
442 | 105 | return self._default_screen.get_width() | ||
443 | 106 | |||
444 | 107 | def get_screen_height(self): | ||
445 | 108 | return self._default_screen.get_height() | ||
446 | 109 | |||
447 | 110 | def get_monitor_geometry(self, monitor_number): | ||
448 | 111 | """Get the geometry for a particular monitor. | ||
449 | 112 | |||
450 | 113 | :return: Tuple containing (x, y, width, height). | ||
451 | 114 | |||
452 | 115 | """ | ||
453 | 116 | if monitor_number < 0 or monitor_number >= self.get_num_monitors(): | ||
454 | 117 | raise ValueError('Specified monitor number is out of range.') | ||
455 | 118 | rect = self._default_screen.get_monitor_geometry(monitor_number) | ||
456 | 119 | return (rect.x, rect.y, rect.width, rect.height) | ||
457 | 120 | |||
458 | 121 | def is_rect_on_monitor(self, monitor_number, rect): | ||
459 | 122 | """Returns True if *rect* is **entirely** on the specified monitor, with no overlap.""" | ||
460 | 123 | |||
461 | 124 | if type(rect) is not tuple or len(rect) != 4: | ||
462 | 125 | raise TypeError("rect must be a tuple of 4 int elements.") | ||
463 | 126 | |||
464 | 127 | (x, y, w, h) = rect | ||
465 | 128 | (mx, my, mw, mh) = self.get_monitor_geometry(monitor_number) | ||
466 | 129 | return (x >= mx and x + w <= mx + mw and y >= my and y + h <= my + mh) | ||
467 | 130 | |||
468 | 131 | def is_point_on_monitor(self, monitor_number, point): | ||
469 | 132 | """Returns True if *point* is on the specified monitor. | ||
470 | 133 | |||
471 | 134 | *point* must be an iterable type with two elements: (x, y) | ||
472 | 135 | |||
473 | 136 | """ | ||
474 | 137 | x,y = point | ||
475 | 138 | (mx, my, mw, mh) = self.get_monitor_geometry(monitor_number) | ||
476 | 139 | return (x >= mx and x < mx + mw and y >= my and y < my + mh) | ||
477 | 140 | |||
478 | 141 | def is_point_on_any_monitor(self, point): | ||
479 | 142 | """Returns true if *point* is on any currently configured monitor.""" | ||
480 | 143 | return any([self.is_point_on_monitor(m, point) for m in range(self.get_num_monitors())]) | ||
481 | 144 | |||
482 | 145 | def move_mouse_to_monitor(self, monitor_number): | ||
483 | 146 | """Move the mouse to the center of the specified monitor.""" | ||
484 | 147 | geo = self.get_monitor_geometry(monitor_number) | ||
485 | 148 | x = geo[0] + (geo[2] / 2) | ||
486 | 149 | y = geo[1] + (geo[3] / 2) | ||
487 | 150 | #dont animate this or it might not get there due to barriers | ||
488 | 151 | Mouse().move(x, y, False) | ||
489 | 152 | |||
490 | 153 | def drag_window_to_monitor(self, window, monitor): | ||
491 | 154 | """Drags *window* to *monitor* | ||
492 | 155 | |||
493 | 156 | :param BamfWindow window: The window to drag | ||
494 | 157 | :param integer monitor: The monitor to drag the *window* to | ||
495 | 158 | :raises: **TypeError** if *window* is not a BamfWindow | ||
496 | 159 | |||
497 | 160 | """ | ||
498 | 161 | if not isinstance(window, BamfWindow): | ||
499 | 162 | raise TypeError("Window must be a BamfWindow") | ||
500 | 163 | |||
501 | 164 | if window.monitor == monitor: | ||
502 | 165 | logger.debug("Window %r is already on monitor %d." % (window.x_id, monitor)) | ||
503 | 166 | return | ||
504 | 167 | |||
505 | 168 | assert(not window.is_maximized) | ||
506 | 169 | (win_x, win_y, win_w, win_h) = window.geometry | ||
507 | 170 | (mx, my, mw, mh) = self.get_monitor_geometry(monitor) | ||
508 | 171 | |||
509 | 172 | logger.debug("Dragging window %r to monitor %d." % (window.x_id, monitor)) | ||
510 | 173 | |||
511 | 174 | mouse = Mouse() | ||
512 | 175 | keyboard = Keyboard() | ||
513 | 176 | mouse.move(win_x + win_w/2, win_y + win_h/2) | ||
514 | 177 | keyboard.press("Alt") | ||
515 | 178 | mouse.press() | ||
516 | 179 | keyboard.release("Alt") | ||
517 | 180 | |||
518 | 181 | # We do the movements in two steps, to reduce the risk of being | ||
519 | 182 | # blocked by the pointer barrier | ||
520 | 183 | target_x = mx + mw/2 | ||
521 | 184 | target_y = my + mh/2 | ||
522 | 185 | mouse.move(win_x, target_y, rate=20, time_between_events=0.005) | ||
523 | 186 | mouse.move(target_x, target_y, rate=20, time_between_events=0.005) | ||
524 | 187 | mouse.release() | ||
525 | 188 | 0 | ||
526 | === removed file 'autopilot/emulators/__init__.py' | |||
527 | --- autopilot/emulators/__init__.py 2012-08-20 23:57:20 +0000 | |||
528 | +++ autopilot/emulators/__init__.py 1970-01-01 00:00:00 +0000 | |||
529 | @@ -1,11 +0,0 @@ | |||
530 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
531 | 2 | # Copyright 2012 Canonical | ||
532 | 3 | # Author: Thomi Richards | ||
533 | 4 | # | ||
534 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
535 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
536 | 7 | # by the Free Software Foundation. | ||
537 | 8 | |||
538 | 9 | """ | ||
539 | 10 | A collection of emulators that make it easier to interact with X11 and Unity. | ||
540 | 11 | """ | ||
541 | 12 | 0 | ||
542 | === removed file 'autopilot/emulators/processmanager.py' | |||
543 | --- autopilot/emulators/processmanager.py 2012-06-07 04:52:04 +0000 | |||
544 | +++ autopilot/emulators/processmanager.py 1970-01-01 00:00:00 +0000 | |||
545 | @@ -1,66 +0,0 @@ | |||
546 | 1 | # Copyright 2012 Canonical | ||
547 | 2 | # Author: Thomi Richards | ||
548 | 3 | # | ||
549 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
550 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
551 | 6 | # by the Free Software Foundation. | ||
552 | 7 | |||
553 | 8 | """The processmanager module contains utilities for starting, stopping, and | ||
554 | 9 | generally managing processes during a test.""" | ||
555 | 10 | |||
556 | 11 | from __future__ import absolute_import | ||
557 | 12 | import logging | ||
558 | 13 | from time import sleep | ||
559 | 14 | |||
560 | 15 | from autopilot.emulators.bamf import Bamf | ||
561 | 16 | |||
562 | 17 | |||
563 | 18 | logger = logging.getLogger(__name__) | ||
564 | 19 | |||
565 | 20 | class ProcessManager(object): | ||
566 | 21 | """Manage Processes during a test cycle.""" | ||
567 | 22 | |||
568 | 23 | def __init__(self): | ||
569 | 24 | self._bamf = Bamf() | ||
570 | 25 | self.snapshot = None | ||
571 | 26 | |||
572 | 27 | def snapshot_running_apps(self): | ||
573 | 28 | """Make a list of all the running applications, and store it. | ||
574 | 29 | |||
575 | 30 | The stored list can later be used to detect any applications that have | ||
576 | 31 | been launched during a test and not shut down. | ||
577 | 32 | |||
578 | 33 | You may only call this method once before calling | ||
579 | 34 | compare_system_with_snapshot. Calling this method multiple times will | ||
580 | 35 | cause a RuntimeError to be raised. | ||
581 | 36 | """ | ||
582 | 37 | |||
583 | 38 | if self.snapshot: | ||
584 | 39 | raise RuntimeError("You may only call snapshot_running_apps once \ | ||
585 | 40 | before calling compare_system_with_snapshot.") | ||
586 | 41 | |||
587 | 42 | self.snapshot = self._bamf.get_running_applications() | ||
588 | 43 | |||
589 | 44 | def compare_system_with_snapshot(self): | ||
590 | 45 | """Compare the currently running application with the last snapshot. | ||
591 | 46 | |||
592 | 47 | This method will raise an AssertionError if there are any new applications | ||
593 | 48 | currently running that were not running when the snapshot was taken. | ||
594 | 49 | |||
595 | 50 | This method should typically be called at the every end of a test. | ||
596 | 51 | """ | ||
597 | 52 | if self.snapshot is None: | ||
598 | 53 | raise RuntimeError("No snapshot to match against.") | ||
599 | 54 | |||
600 | 55 | new_apps = [] | ||
601 | 56 | for i in range(10): | ||
602 | 57 | current_apps = self._bamf.get_running_applications() | ||
603 | 58 | new_apps = filter(lambda i: i not in self.snapshot, current_apps) | ||
604 | 59 | if not new_apps: | ||
605 | 60 | self.snapshot = None | ||
606 | 61 | return | ||
607 | 62 | sleep(1) | ||
608 | 63 | self.snapshot = None | ||
609 | 64 | raise AssertionError("The following apps were started during the test and not closed: %r", new_apps) | ||
610 | 65 | |||
611 | 66 | |||
612 | 67 | 0 | ||
613 | === removed file 'autopilot/emulators/zeitgeist.py' | |||
614 | --- autopilot/emulators/zeitgeist.py 2012-10-26 14:15:43 +0000 | |||
615 | +++ autopilot/emulators/zeitgeist.py 1970-01-01 00:00:00 +0000 | |||
616 | @@ -1,66 +0,0 @@ | |||
617 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
618 | 2 | # Copyright 2012 Canonical | ||
619 | 3 | # Author: Brandon Schaefer | ||
620 | 4 | # | ||
621 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
622 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
623 | 7 | # by the Free Software Foundation. | ||
624 | 8 | |||
625 | 9 | """Provide ability to register text files with the file lens.""" | ||
626 | 10 | |||
627 | 11 | from __future__ import absolute_import | ||
628 | 12 | |||
629 | 13 | import logging | ||
630 | 14 | import os.path | ||
631 | 15 | from zeitgeist.client import ZeitgeistClient | ||
632 | 16 | from zeitgeist.datamodel import Event, Interpretation, Manifestation, ResultType | ||
633 | 17 | |||
634 | 18 | |||
635 | 19 | class Zeitgeist(object): | ||
636 | 20 | """Provide access zeitgeist.""" | ||
637 | 21 | |||
638 | 22 | def __init__(self): | ||
639 | 23 | self.zg = ZeitgeistClient() | ||
640 | 24 | self.logger = logging.getLogger(__name__) | ||
641 | 25 | |||
642 | 26 | def add_existing_file(self, path): | ||
643 | 27 | """Registers *file* with zeitgeist. | ||
644 | 28 | |||
645 | 29 | :param string file: full path to an existing text file to register. | ||
646 | 30 | :raises: **RuntimeError** if *file* does not exist. | ||
647 | 31 | |||
648 | 32 | """ | ||
649 | 33 | if os.path.exists(path): | ||
650 | 34 | self.__add_text_file(path) | ||
651 | 35 | else: | ||
652 | 36 | raise RuntimeError("File not found on path: %s." % (path)) | ||
653 | 37 | |||
654 | 38 | def __add_text_file(self, path): | ||
655 | 39 | """Takes a path to a file and creates an event for it then querys it.""" | ||
656 | 40 | file_lens = "file://" | ||
657 | 41 | dir_path = os.path.dirname(path) | ||
658 | 42 | name = os.path.basename(path) | ||
659 | 43 | |||
660 | 44 | event = Event.new_for_values (interpretation=Interpretation.ACCESS_EVENT, | ||
661 | 45 | manifestation=Manifestation.USER_ACTIVITY, | ||
662 | 46 | subject_uri=file_lens + path, | ||
663 | 47 | subject_interpretation=Interpretation.TEXT_DOCUMENT, | ||
664 | 48 | subject_manifestation=Manifestation.FILE_DATA_OBJECT, | ||
665 | 49 | subject_origin=file_lens + dir_path, | ||
666 | 50 | subject_text=name) | ||
667 | 51 | self.zg.insert_event(event) | ||
668 | 52 | |||
669 | 53 | template = Event.new_for_values (interpretation=Interpretation.ACCESS_EVENT, | ||
670 | 54 | manifestation=Manifestation.USER_ACTIVITY) | ||
671 | 55 | |||
672 | 56 | self.zg.find_events_for_template (template, | ||
673 | 57 | self.__log_events_cb, | ||
674 | 58 | num_events=1, | ||
675 | 59 | result_type=ResultType.MostRecentSubjects) | ||
676 | 60 | |||
677 | 61 | def __log_events_cb(self, events): | ||
678 | 62 | """Callback to recive events, we are just using it to log each event.""" | ||
679 | 63 | self.logger.info("Found Events") | ||
680 | 64 | for event in events: | ||
681 | 65 | for subject in event.subjects: | ||
682 | 66 | self.logger.info(" * %s" % (subject.uri)) | ||
683 | 67 | 0 | ||
684 | === added file 'autopilot/gestures.py' | |||
685 | --- autopilot/gestures.py 1970-01-01 00:00:00 +0000 | |||
686 | +++ autopilot/gestures.py 2013-04-15 21:43:32 +0000 | |||
687 | @@ -0,0 +1,62 @@ | |||
688 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
689 | 2 | # Copyright 2013 Canonical | ||
690 | 3 | # Author: Thomi Richards | ||
691 | 4 | # | ||
692 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
693 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
694 | 7 | # by the Free Software Foundation. | ||
695 | 8 | |||
696 | 9 | """Gestural support for autopilot. | ||
697 | 10 | |||
698 | 11 | This module contains functions that can generate touch and multi-tuch gestures | ||
699 | 12 | for you. This is a convenience for the test author - there is nothing to prevent | ||
700 | 13 | you from generating your own gestures! | ||
701 | 14 | |||
702 | 15 | """ | ||
703 | 16 | |||
704 | 17 | from autopilot.input import Touch | ||
705 | 18 | from time import sleep | ||
706 | 19 | |||
707 | 20 | |||
708 | 21 | def pinch(center, vector_start, vector_end): | ||
709 | 22 | """Perform a two finger pinch (zoom) gesture. | ||
710 | 23 | |||
711 | 24 | :param center: The coordinates (x,y) of the center of the pinch gesture. | ||
712 | 25 | :param vector_start: The (x,y) values to move away from the center for the start. | ||
713 | 26 | :param vector_end: The (x,y) values to move away from the center for the end. | ||
714 | 27 | |||
715 | 28 | The fingers will move in 100 steps between the start and the end points. | ||
716 | 29 | If start is smaller than end, the gesture will zoom in, otherwise it | ||
717 | 30 | will zoom out. | ||
718 | 31 | |||
719 | 32 | """ | ||
720 | 33 | |||
721 | 34 | finger_1_start = [center[0] - vector_start[0], center[1] - vector_start[1]] | ||
722 | 35 | finger_2_start = [center[0] + vector_start[0], center[1] + vector_start[1]] | ||
723 | 36 | finger_1_end = [center[0] - vector_end[0], center[1] - vector_end[1]] | ||
724 | 37 | finger_2_end = [center[0] + vector_end[0], center[1] + vector_end[1]] | ||
725 | 38 | |||
726 | 39 | dx = 1.0 * (finger_1_end[0] - finger_1_start[0]) / 100 | ||
727 | 40 | dy = 1.0 * (finger_1_end[1] - finger_1_start[1]) / 100 | ||
728 | 41 | |||
729 | 42 | finger_1 = Touch.create() | ||
730 | 43 | finger_2 = Touch.create() | ||
731 | 44 | |||
732 | 45 | finger_1.press(*finger_1_start) | ||
733 | 46 | finger_2.press(*finger_2_start) | ||
734 | 47 | |||
735 | 48 | finger_1_cur = [finger_1_start[0] + dx, finger_1_start[1] + dy] | ||
736 | 49 | finger_2_cur = [finger_2_start[0] - dx, finger_2_start[1] - dy] | ||
737 | 50 | |||
738 | 51 | for i in range(0, 100): | ||
739 | 52 | finger_1.move(*finger_1_cur) | ||
740 | 53 | finger_2.move(*finger_2_cur) | ||
741 | 54 | sleep(0.005) | ||
742 | 55 | |||
743 | 56 | finger_1_cur = [finger_1_cur[0] + dx, finger_1_cur[1] + dy] | ||
744 | 57 | finger_2_cur = [finger_2_cur[0] - dx, finger_2_cur[1] - dy] | ||
745 | 58 | |||
746 | 59 | finger_1.move(*finger_1_end) | ||
747 | 60 | finger_2.move(*finger_2_end) | ||
748 | 61 | finger_1.release() | ||
749 | 62 | finger_2.release() | ||
750 | 0 | 63 | ||
751 | === removed file 'autopilot/glibrunner.py' | |||
752 | --- autopilot/glibrunner.py 2012-09-26 23:21:20 +0000 | |||
753 | +++ autopilot/glibrunner.py 1970-01-01 00:00:00 +0000 | |||
754 | @@ -1,26 +0,0 @@ | |||
755 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
756 | 2 | # Copyright 2012 Canonical | ||
757 | 3 | # Author: Thomi Richards | ||
758 | 4 | # | ||
759 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
760 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
761 | 7 | # by the Free Software Foundation. | ||
762 | 8 | |||
763 | 9 | from __future__ import absolute_import | ||
764 | 10 | |||
765 | 11 | import testtools | ||
766 | 12 | |||
767 | 13 | try: | ||
768 | 14 | import faulthandler | ||
769 | 15 | faulthandler.enable() | ||
770 | 16 | except: | ||
771 | 17 | pass | ||
772 | 18 | |||
773 | 19 | |||
774 | 20 | __all__ = [ | ||
775 | 21 | 'AutopilotTestRunner', | ||
776 | 22 | ] | ||
777 | 23 | |||
778 | 24 | class AutopilotTestRunner(testtools.RunTest): | ||
779 | 25 | pass | ||
780 | 26 | |||
781 | 27 | 0 | ||
782 | === modified file 'autopilot/globals.py' | |||
783 | --- autopilot/globals.py 2012-09-19 23:31:57 +0000 | |||
784 | +++ autopilot/globals.py 2013-04-15 21:43:32 +0000 | |||
785 | @@ -7,12 +7,16 @@ | |||
786 | 7 | # by the Free Software Foundation. | 7 | # by the Free Software Foundation. |
787 | 8 | 8 | ||
788 | 9 | from __future__ import absolute_import | 9 | from __future__ import absolute_import |
795 | 10 | 10 | from StringIO import StringIO | |
796 | 11 | # this can be set to True, in which case tests will be recorded. | 11 | from autopilot.utilities import LogFormatter |
797 | 12 | __video_recording_enabled = False | 12 | from testtools.content import text_content |
798 | 13 | 13 | import subprocess | |
799 | 14 | # this is where videos will be put after being encoded. | 14 | import os.path |
800 | 15 | __video_record_directory = "/tmp/autopilot" | 15 | import logging |
801 | 16 | from autopilot.utilities import addCleanup | ||
802 | 17 | |||
803 | 18 | logger = logging.getLogger(__name__) | ||
804 | 19 | |||
805 | 16 | 20 | ||
806 | 17 | # if set to true, autopilot will output all pythong logging to stderr | 21 | # if set to true, autopilot will output all pythong logging to stderr |
807 | 18 | __log_verbose = False | 22 | __log_verbose = False |
808 | @@ -23,12 +27,114 @@ | |||
809 | 23 | return __log_verbose | 27 | return __log_verbose |
810 | 24 | 28 | ||
811 | 25 | 29 | ||
812 | 30 | class _TestLogger(object): | ||
813 | 31 | """A class that handles adding test logs as test result content.""" | ||
814 | 32 | |||
815 | 33 | def __call__(self, test_instance): | ||
816 | 34 | self._setUpTestLogging(test_instance) | ||
817 | 35 | if get_log_verbose(): | ||
818 | 36 | global logger | ||
819 | 37 | logger.info("*" * 60) | ||
820 | 38 | logger.info("Starting test %s", test_instance.shortDescription()) | ||
821 | 39 | |||
822 | 40 | def _setUpTestLogging(self, test_instance): | ||
823 | 41 | self._log_buffer = StringIO() | ||
824 | 42 | root_logger = logging.getLogger() | ||
825 | 43 | root_logger.setLevel(logging.DEBUG) | ||
826 | 44 | formatter = LogFormatter() | ||
827 | 45 | self._log_handler = logging.StreamHandler(stream=self._log_buffer) | ||
828 | 46 | self._log_handler.setFormatter(formatter) | ||
829 | 47 | root_logger.addHandler(self._log_handler) | ||
830 | 48 | test_instance.addCleanup(self._tearDownLogging, test_instance) | ||
831 | 49 | |||
832 | 50 | def _tearDownLogging(self, test_instance): | ||
833 | 51 | root_logger = logging.getLogger() | ||
834 | 52 | self._log_handler.flush() | ||
835 | 53 | self._log_buffer.seek(0) | ||
836 | 54 | test_instance.addDetail('test-log', text_content(self._log_buffer.getvalue())) | ||
837 | 55 | root_logger.removeHandler(self._log_handler) | ||
838 | 56 | # Calling del to remove the handler and flush the buffer. We are | ||
839 | 57 | # abusing the log handlers here a little. | ||
840 | 58 | del self._log_buffer | ||
841 | 59 | |||
842 | 60 | |||
843 | 26 | def set_log_verbose(verbose): | 61 | def set_log_verbose(verbose): |
844 | 27 | """Set whether or not we should log verbosely.""" | 62 | """Set whether or not we should log verbosely.""" |
845 | 63 | |||
846 | 28 | if type(verbose) is not bool: | 64 | if type(verbose) is not bool: |
847 | 29 | raise TypeError("Verbose flag must be a boolean.") | 65 | raise TypeError("Verbose flag must be a boolean.") |
848 | 30 | global __log_verbose | 66 | global __log_verbose |
849 | 31 | __log_verbose = verbose | 67 | __log_verbose = verbose |
850 | 68 | if verbose: | ||
851 | 69 | logger = _TestLogger() | ||
852 | 70 | _on_test_started_call.append(logger) | ||
853 | 71 | |||
854 | 72 | |||
855 | 73 | class _VideoCaptureTestCase(object): | ||
856 | 74 | """Video capture autopilot tests, saving the results if the test failed.""" | ||
857 | 75 | |||
858 | 76 | _recording_app = '/usr/bin/recordmydesktop' | ||
859 | 77 | _recording_opts = ['--no-sound', '--no-frame', '-o',] | ||
860 | 78 | |||
861 | 79 | def __init__(self, recording_directory): | ||
862 | 80 | self.recording_directory = recording_directory | ||
863 | 81 | |||
864 | 82 | def __call__(self, test_instance): | ||
865 | 83 | if not self._have_recording_app(): | ||
866 | 84 | logger.warning("Disabling video capture since '%s' is not present", self._recording_app) | ||
867 | 85 | |||
868 | 86 | self._test_passed = True | ||
869 | 87 | test_instance.addOnException(self._on_test_failed) | ||
870 | 88 | test_instance.addCleanup(self._stop_video_capture, test_instance) | ||
871 | 89 | self._start_video_capture(test_instance.shortDescription()) | ||
872 | 90 | |||
873 | 91 | def _have_recording_app(self): | ||
874 | 92 | return os.path.exists(self._recording_app) | ||
875 | 93 | |||
876 | 94 | def _start_video_capture(self, test_id): | ||
877 | 95 | args = self._get_capture_command_line() | ||
878 | 96 | self._capture_file = os.path.join( | ||
879 | 97 | self.recording_directory, | ||
880 | 98 | '%s.ogv' % (test_id) | ||
881 | 99 | ) | ||
882 | 100 | self._ensure_directory_exists_but_not_file(self._capture_file) | ||
883 | 101 | args.append(self._capture_file) | ||
884 | 102 | logger.debug("Starting: %r", args) | ||
885 | 103 | self._capture_process = subprocess.Popen( | ||
886 | 104 | args, | ||
887 | 105 | stdout=subprocess.PIPE, | ||
888 | 106 | stderr=subprocess.STDOUT | ||
889 | 107 | ) | ||
890 | 108 | |||
891 | 109 | def _stop_video_capture(self, test_instance): | ||
892 | 110 | """Stop the video capture. If the test failed, save the resulting file.""" | ||
893 | 111 | |||
894 | 112 | if self._test_passed: | ||
895 | 113 | # We use kill here because we don't want the recording app to start | ||
896 | 114 | # encoding the video file (since we're removing it anyway.) | ||
897 | 115 | self._capture_process.kill() | ||
898 | 116 | self._capture_process.wait() | ||
899 | 117 | else: | ||
900 | 118 | self._capture_process.terminate() | ||
901 | 119 | self._capture_process.wait() | ||
902 | 120 | if self._capture_process.returncode != 0: | ||
903 | 121 | test_instance.addDetail('video capture log', text_content(self._capture_process.stdout.read())) | ||
904 | 122 | self._capture_process = None | ||
905 | 123 | |||
906 | 124 | def _get_capture_command_line(self): | ||
907 | 125 | return [self._recording_app] + self._recording_opts | ||
908 | 126 | |||
909 | 127 | def _ensure_directory_exists_but_not_file(self, file_path): | ||
910 | 128 | dirpath = os.path.dirname(file_path) | ||
911 | 129 | if not os.path.exists(dirpath): | ||
912 | 130 | os.makedirs(dirpath) | ||
913 | 131 | elif os.path.exists(file_path): | ||
914 | 132 | logger.warning("Video capture file '%s' already exists, deleting.", file_path) | ||
915 | 133 | os.remove(file_path) | ||
916 | 134 | |||
917 | 135 | def _on_test_failed(self, ex_info): | ||
918 | 136 | """Called when a test fails.""" | ||
919 | 137 | self._test_passed = False | ||
920 | 32 | 138 | ||
921 | 33 | 139 | ||
922 | 34 | def configure_video_recording(enable_recording, record_dir): | 140 | def configure_video_recording(enable_recording, record_dir): |
923 | @@ -43,18 +149,14 @@ | |||
924 | 43 | if not isinstance(record_dir, basestring): | 149 | if not isinstance(record_dir, basestring): |
925 | 44 | raise TypeError("record_dir must be a string.") | 150 | raise TypeError("record_dir must be a string.") |
926 | 45 | 151 | ||
942 | 46 | global __video_recording_enabled | 152 | if enable_recording: |
943 | 47 | global __video_record_directory | 153 | recorder = _VideoCaptureTestCase(record_dir) |
944 | 48 | 154 | _on_test_started_call.append(recorder) | |
945 | 49 | __video_recording_enabled = enable_recording | 155 | |
946 | 50 | __video_record_directory = record_dir | 156 | |
947 | 51 | 157 | _on_test_started_call = [addCleanup.set_test_instance] | |
948 | 52 | 158 | ||
949 | 53 | def get_video_recording_enabled(): | 159 | def on_test_started(test_case_instance): |
950 | 54 | global __video_recording_enabled | 160 | global _on_test_started_call |
951 | 55 | return __video_recording_enabled | 161 | for fun in _on_test_started_call: |
952 | 56 | 162 | fun(test_case_instance) | |
938 | 57 | |||
939 | 58 | def get_video_record_directory(): | ||
940 | 59 | global __video_record_directory | ||
941 | 60 | return __video_record_directory | ||
953 | 61 | 163 | ||
954 | === renamed file 'autopilot/emulators/ibus.py' => 'autopilot/ibus.py' | |||
955 | === renamed directory 'autopilot/emulators/input' => 'autopilot/input' | |||
956 | === modified file 'autopilot/input/_X11.py' | |||
957 | --- autopilot/emulators/input/_X11.py 2013-02-28 03:18:15 +0000 | |||
958 | +++ autopilot/input/_X11.py 2013-04-15 21:43:32 +0000 | |||
959 | @@ -19,13 +19,11 @@ | |||
960 | 19 | from __future__ import absolute_import | 19 | from __future__ import absolute_import |
961 | 20 | 20 | ||
962 | 21 | import logging | 21 | import logging |
963 | 22 | import os | ||
964 | 23 | import subprocess | ||
965 | 24 | from time import sleep | 22 | from time import sleep |
966 | 25 | 23 | ||
968 | 26 | from autopilot.emulators.bamf import BamfWindow | 24 | from autopilot.display import is_point_on_any_screen, move_mouse_to_screen |
969 | 27 | from autopilot.utilities import Silence | 25 | from autopilot.utilities import Silence |
971 | 28 | from autopilot.emulators.input import ( | 26 | from autopilot.input import ( |
972 | 29 | Keyboard as KeyboardBase, | 27 | Keyboard as KeyboardBase, |
973 | 30 | Mouse as MouseBase, | 28 | Mouse as MouseBase, |
974 | 31 | ) | 29 | ) |
975 | @@ -321,7 +319,7 @@ | |||
976 | 321 | 319 | ||
977 | 322 | dest_x, dest_y = x, y | 320 | dest_x, dest_y = x, y |
978 | 323 | curr_x, curr_y = self.position() | 321 | curr_x, curr_y = self.position() |
980 | 324 | coordinate_valid = ScreenGeometry().is_point_on_any_monitor((x,y)) | 322 | coordinate_valid = is_point_on_any_screen((x,y)) |
981 | 325 | 323 | ||
982 | 326 | while curr_x != dest_x or curr_y != dest_y: | 324 | while curr_x != dest_x or curr_y != dest_y: |
983 | 327 | dx = abs(dest_x - curr_x) | 325 | dx = abs(dest_x - curr_x) |
984 | @@ -416,145 +414,4 @@ | |||
985 | 416 | logger.debug("Releasing mouse button %d as part of cleanup", btn) | 414 | logger.debug("Releasing mouse button %d as part of cleanup", btn) |
986 | 417 | fake_input(get_display(), X.ButtonRelease, btn) | 415 | fake_input(get_display(), X.ButtonRelease, btn) |
987 | 418 | _PRESSED_MOUSE_BUTTONS = [] | 416 | _PRESSED_MOUSE_BUTTONS = [] |
1130 | 419 | sg = ScreenGeometry() | 417 | move_mouse_to_screen(0) |
989 | 420 | sg.move_mouse_to_monitor(0) | ||
990 | 421 | |||
991 | 422 | |||
992 | 423 | class ScreenGeometry: | ||
993 | 424 | """Get details about screen geometry.""" | ||
994 | 425 | |||
995 | 426 | class BlacklistedDriverError(RuntimeError): | ||
996 | 427 | """Cannot set primary monitor when running drivers listed in the driver blacklist.""" | ||
997 | 428 | |||
998 | 429 | def __init__(self): | ||
999 | 430 | # Note: MUST import these here, rather than at the top of the file. Why? | ||
1000 | 431 | # Because sphinx imports these modules to build the API documentation, | ||
1001 | 432 | # which in turn tries to import Gdk, which in turn fails because there's | ||
1002 | 433 | # no DISPlAY environment set in the package builder. | ||
1003 | 434 | from gi.repository import Gdk | ||
1004 | 435 | self._default_screen = Gdk.Screen.get_default() | ||
1005 | 436 | self._blacklisted_drivers = ["NVIDIA"] | ||
1006 | 437 | |||
1007 | 438 | def get_num_monitors(self): | ||
1008 | 439 | """Get the number of monitors attached to the PC.""" | ||
1009 | 440 | return self._default_screen.get_n_monitors() | ||
1010 | 441 | |||
1011 | 442 | def get_primary_monitor(self): | ||
1012 | 443 | return self._default_screen.get_primary_monitor() | ||
1013 | 444 | |||
1014 | 445 | def set_primary_monitor(self, monitor): | ||
1015 | 446 | """Set *monitor* to be the primary monitor. | ||
1016 | 447 | |||
1017 | 448 | :param int monitor: Must be between 0 and the number of configured | ||
1018 | 449 | monitors. | ||
1019 | 450 | :raises: **ValueError** if an invalid monitor is specified. | ||
1020 | 451 | :raises: **BlacklistedDriverError** if your video driver does not | ||
1021 | 452 | support this. | ||
1022 | 453 | |||
1023 | 454 | """ | ||
1024 | 455 | try: | ||
1025 | 456 | glxinfo_out = subprocess.check_output("glxinfo") | ||
1026 | 457 | except OSError, e: | ||
1027 | 458 | raise OSError("Failed to run glxinfo: %s. (do you have mesa-utils installed?)" % e) | ||
1028 | 459 | |||
1029 | 460 | for dri in self._blacklisted_drivers: | ||
1030 | 461 | if dri in glxinfo_out: | ||
1031 | 462 | raise ScreenGeometry.BlacklistedDriverError('Impossible change the primary monitor for the given driver') | ||
1032 | 463 | |||
1033 | 464 | if monitor < 0 or monitor >= self.get_num_monitors(): | ||
1034 | 465 | raise ValueError('Monitor %d is not in valid range of 0 <= monitor < %d.' % (self.get_num_monitors())) | ||
1035 | 466 | |||
1036 | 467 | monitor_name = self._default_screen.get_monitor_plug_name(monitor) | ||
1037 | 468 | |||
1038 | 469 | if not monitor_name: | ||
1039 | 470 | raise ValueError('Could not get monitor name from monitor number %d.' % (monitor)) | ||
1040 | 471 | |||
1041 | 472 | ret = os.spawnlp(os.P_WAIT, "xrandr", "xrandr", "--output", monitor_name, "--primary") | ||
1042 | 473 | |||
1043 | 474 | if ret != 0: | ||
1044 | 475 | raise RuntimeError('Xrandr can\'t set the primary monitor. error code: %d' % (ret)) | ||
1045 | 476 | |||
1046 | 477 | def get_screen_width(self): | ||
1047 | 478 | return self._default_screen.get_width() | ||
1048 | 479 | |||
1049 | 480 | def get_screen_height(self): | ||
1050 | 481 | return self._default_screen.get_height() | ||
1051 | 482 | |||
1052 | 483 | def get_monitor_geometry(self, monitor_number): | ||
1053 | 484 | """Get the geometry for a particular monitor. | ||
1054 | 485 | |||
1055 | 486 | :return: Tuple containing (x, y, width, height). | ||
1056 | 487 | |||
1057 | 488 | """ | ||
1058 | 489 | if monitor_number < 0 or monitor_number >= self.get_num_monitors(): | ||
1059 | 490 | raise ValueError('Specified monitor number is out of range.') | ||
1060 | 491 | rect = self._default_screen.get_monitor_geometry(monitor_number) | ||
1061 | 492 | return (rect.x, rect.y, rect.width, rect.height) | ||
1062 | 493 | |||
1063 | 494 | def is_rect_on_monitor(self, monitor_number, rect): | ||
1064 | 495 | """Returns True if *rect* is **entirely** on the specified monitor, with no overlap.""" | ||
1065 | 496 | |||
1066 | 497 | if type(rect) is not tuple or len(rect) != 4: | ||
1067 | 498 | raise TypeError("rect must be a tuple of 4 int elements.") | ||
1068 | 499 | |||
1069 | 500 | (x, y, w, h) = rect | ||
1070 | 501 | (mx, my, mw, mh) = self.get_monitor_geometry(monitor_number) | ||
1071 | 502 | return (x >= mx and x + w <= mx + mw and y >= my and y + h <= my + mh) | ||
1072 | 503 | |||
1073 | 504 | def is_point_on_monitor(self, monitor_number, point): | ||
1074 | 505 | """Returns True if *point* is on the specified monitor. | ||
1075 | 506 | |||
1076 | 507 | *point* must be an iterable type with two elements: (x, y) | ||
1077 | 508 | |||
1078 | 509 | """ | ||
1079 | 510 | x,y = point | ||
1080 | 511 | (mx, my, mw, mh) = self.get_monitor_geometry(monitor_number) | ||
1081 | 512 | return (x >= mx and x < mx + mw and y >= my and y < my + mh) | ||
1082 | 513 | |||
1083 | 514 | def is_point_on_any_monitor(self, point): | ||
1084 | 515 | """Returns true if *point* is on any currently configured monitor.""" | ||
1085 | 516 | return any([self.is_point_on_monitor(m, point) for m in range(self.get_num_monitors())]) | ||
1086 | 517 | |||
1087 | 518 | def move_mouse_to_monitor(self, monitor_number): | ||
1088 | 519 | """Move the mouse to the center of the specified monitor.""" | ||
1089 | 520 | geo = self.get_monitor_geometry(monitor_number) | ||
1090 | 521 | x = geo[0] + (geo[2] / 2) | ||
1091 | 522 | y = geo[1] + (geo[3] / 2) | ||
1092 | 523 | #dont animate this or it might not get there due to barriers | ||
1093 | 524 | Mouse().move(x, y, False) | ||
1094 | 525 | |||
1095 | 526 | def drag_window_to_monitor(self, window, monitor): | ||
1096 | 527 | """Drags *window* to *monitor* | ||
1097 | 528 | |||
1098 | 529 | :param BamfWindow window: The window to drag | ||
1099 | 530 | :param integer monitor: The monitor to drag the *window* to | ||
1100 | 531 | :raises: **TypeError** if *window* is not a BamfWindow | ||
1101 | 532 | |||
1102 | 533 | """ | ||
1103 | 534 | if not isinstance(window, BamfWindow): | ||
1104 | 535 | raise TypeError("Window must be a BamfWindow") | ||
1105 | 536 | |||
1106 | 537 | if window.monitor == monitor: | ||
1107 | 538 | logger.debug("Window %r is already on monitor %d." % (window.x_id, monitor)) | ||
1108 | 539 | return | ||
1109 | 540 | |||
1110 | 541 | assert(not window.is_maximized) | ||
1111 | 542 | (win_x, win_y, win_w, win_h) = window.geometry | ||
1112 | 543 | (mx, my, mw, mh) = self.get_monitor_geometry(monitor) | ||
1113 | 544 | |||
1114 | 545 | logger.debug("Dragging window %r to monitor %d." % (window.x_id, monitor)) | ||
1115 | 546 | |||
1116 | 547 | mouse = Mouse() | ||
1117 | 548 | keyboard = Keyboard() | ||
1118 | 549 | mouse.move(win_x + win_w/2, win_y + win_h/2) | ||
1119 | 550 | keyboard.press("Alt") | ||
1120 | 551 | mouse.press() | ||
1121 | 552 | keyboard.release("Alt") | ||
1122 | 553 | |||
1123 | 554 | # We do the movements in two steps, to reduce the risk of being | ||
1124 | 555 | # blocked by the pointer barrier | ||
1125 | 556 | target_x = mx + mw/2 | ||
1126 | 557 | target_y = my + mh/2 | ||
1127 | 558 | mouse.move(win_x, target_y, rate=20, time_between_events=0.005) | ||
1128 | 559 | mouse.move(target_x, target_y, rate=20, time_between_events=0.005) | ||
1129 | 560 | mouse.release() | ||
1131 | 561 | 418 | ||
1132 | === modified file 'autopilot/input/__init__.py' | |||
1133 | --- autopilot/emulators/input/__init__.py 2013-02-28 03:18:15 +0000 | |||
1134 | +++ autopilot/input/__init__.py 2013-04-15 21:43:32 +0000 | |||
1135 | @@ -6,99 +6,81 @@ | |||
1136 | 6 | # under the terms of the GNU General Public License version 3, as published | 6 | # under the terms of the GNU General Public License version 3, as published |
1137 | 7 | # by the Free Software Foundation. | 7 | # by the Free Software Foundation. |
1138 | 8 | 8 | ||
1143 | 9 | from collections import OrderedDict | 9 | """ |
1144 | 10 | from autopilot.utilities import get_debug_logger | 10 | Autopilot unified input system. |
1145 | 11 | 11 | =============================== | |
1142 | 12 | """Autopilot unified input system. | ||
1146 | 13 | 12 | ||
1147 | 14 | This package provides input methods for various platforms. Autopilot aims to | 13 | This package provides input methods for various platforms. Autopilot aims to |
1148 | 15 | provide an appropriate implementation for the currently running system. For | 14 | provide an appropriate implementation for the currently running system. For |
1149 | 16 | example, not all systems have an X11 stack running: on those systems, autopilot | 15 | example, not all systems have an X11 stack running: on those systems, autopilot |
1158 | 17 | will instantiate a Keyboard class that uses something other than X11 to generate | 16 | will instantiate input classes class that use something other than X11 to generate |
1159 | 18 | key events (possibly UInput). | 17 | events (possibly UInput). |
1160 | 19 | 18 | ||
1161 | 20 | Test authors are encouraged to instantiate the input devices they need for their | 19 | Test authors should instantiate the appropriate class using the ``create`` method |
1162 | 21 | tests using the get_keyboard and get_mouse methods directly. In the case where | 20 | on each class. Tests can provide a hint to this method to suggest that a particular |
1163 | 22 | these methods don't do the right thing, authors may access the underlying input | 21 | subsystem be used. However, autopilot will prefer to return a subsystem other than |
1164 | 23 | systems directly. However, these are not documented, and are liable to change | 22 | the one specified, if the requested subsystem is unavailable. |
1165 | 24 | without notice. | 23 | |
1166 | 24 | There are three basic input types available: | ||
1167 | 25 | |||
1168 | 26 | * :class:`Keyboard` - traditional keyboard devices. | ||
1169 | 27 | * :class:`Mouse` - traditional mouse devices. | ||
1170 | 28 | * :class:`Touch` - single point-of-contact touch device. | ||
1171 | 29 | * For multitouch capabilities, see the :mod:`autopilot.gestures` module. | ||
1172 | 25 | 30 | ||
1173 | 26 | """ | 31 | """ |
1174 | 27 | 32 | ||
1233 | 28 | 33 | from collections import OrderedDict | |
1234 | 29 | def get_keyboard(preferred_variant=""): | 34 | from autopilot.utilities import _pick_variant |
1235 | 30 | """Get an instance of the Keyboard class. | 35 | |
1178 | 31 | |||
1179 | 32 | If variant is specified, it should be a string that specifies a backend to | ||
1180 | 33 | use. However, this hint can be ignored - autopilot will prefer to return a | ||
1181 | 34 | keyboard variant other than the one requested, rather than fail to return | ||
1182 | 35 | anything at all. | ||
1183 | 36 | |||
1184 | 37 | If autopilot cannot instantate any of the possible backends, a RuntimeError | ||
1185 | 38 | will be raised. | ||
1186 | 39 | """ | ||
1187 | 40 | def get_x11_kb(): | ||
1188 | 41 | from autopilot.emulators.input._X11 import Keyboard | ||
1189 | 42 | return Keyboard() | ||
1190 | 43 | def get_uinput_kb(): | ||
1191 | 44 | from autopilot.emulators.input._uinput import Keyboard | ||
1192 | 45 | return Keyboard() | ||
1193 | 46 | |||
1194 | 47 | variants = OrderedDict() | ||
1195 | 48 | variants['X11'] = get_x11_kb | ||
1196 | 49 | variants['UInput'] = get_uinput_kb | ||
1197 | 50 | return _pick_variant(variants, preferred_variant) | ||
1198 | 51 | |||
1199 | 52 | |||
1200 | 53 | def get_mouse(preferred_variant=""): | ||
1201 | 54 | """Get an instance of the Mouse class. | ||
1202 | 55 | |||
1203 | 56 | If variant is specified, it should be a string that specifies a backend to | ||
1204 | 57 | use. However, this hint can be ignored - autopilot will prefer to return a | ||
1205 | 58 | mouse variant other than the one requested, rather than fail to return | ||
1206 | 59 | anything at all. | ||
1207 | 60 | |||
1208 | 61 | If autopilot cannot instantate any of the possible backends, a RuntimeError | ||
1209 | 62 | will be raised. | ||
1210 | 63 | """ | ||
1211 | 64 | def get_x11_mouse(): | ||
1212 | 65 | from autopilot.emulators.input._X11 import Mouse | ||
1213 | 66 | return Mouse() | ||
1214 | 67 | |||
1215 | 68 | variants = OrderedDict() | ||
1216 | 69 | variants['X11'] = get_x11_mouse | ||
1217 | 70 | return _pick_variant(variants, preferred_variant) | ||
1218 | 71 | |||
1219 | 72 | |||
1220 | 73 | def _pick_variant(variants, preferred_variant): | ||
1221 | 74 | possible_backends = variants.keys() | ||
1222 | 75 | get_debug_logger().debug("Possible keyboard variants: %s", ','.join(possible_backends)) | ||
1223 | 76 | if preferred_variant in possible_backends: | ||
1224 | 77 | possible_backends.sort(lambda a,b: -1 if a == preferred_variant else 0) | ||
1225 | 78 | failure_reasons = [] | ||
1226 | 79 | for be in possible_backends: | ||
1227 | 80 | try: | ||
1228 | 81 | return variants[be]() | ||
1229 | 82 | except Exception as e: | ||
1230 | 83 | get_debug_logger().warning("Can't create keyboard variant %s: %r", be, e) | ||
1231 | 84 | failure_reasons.append('%s: %r' % (be, e)) | ||
1232 | 85 | raise RuntimeError("Unable to instantiate any Keyboard backends\n%s" % '\n'.join(failure_reasons)) | ||
1236 | 86 | 36 | ||
1237 | 87 | 37 | ||
1238 | 88 | class Keyboard(object): | 38 | class Keyboard(object): |
1239 | 89 | 39 | ||
1241 | 90 | """A base class for all keyboard-type devices.""" | 40 | """A simple keyboard device class. |
1242 | 41 | |||
1243 | 42 | The keyboard class is used to generate key events while in an autopilot | ||
1244 | 43 | test. This class should not be instantiated directly however. To get an | ||
1245 | 44 | instance of the keyboard class, call :py:meth:`create` instead. | ||
1246 | 45 | |||
1247 | 46 | """ | ||
1248 | 47 | |||
1249 | 48 | @staticmethod | ||
1250 | 49 | def create(preferred_variant=''): | ||
1251 | 50 | """Get an instance of the :py:class:`Keyboard` class. | ||
1252 | 51 | |||
1253 | 52 | :param preferred_variant: A string containing a hint as to which variant you | ||
1254 | 53 | would like. However, this hint can be ignored - autopilot will prefer to | ||
1255 | 54 | return a keyboard variant other than the one requested, rather than fail | ||
1256 | 55 | to return anything at all. | ||
1257 | 56 | :raises: a RuntimeError will be raised if autopilot cannot instantate any of | ||
1258 | 57 | the possible backends. | ||
1259 | 58 | |||
1260 | 59 | """ | ||
1261 | 60 | def get_x11_kb(): | ||
1262 | 61 | from autopilot.input._X11 import Keyboard | ||
1263 | 62 | return Keyboard() | ||
1264 | 63 | def get_uinput_kb(): | ||
1265 | 64 | from autopilot.input._uinput import Keyboard | ||
1266 | 65 | return Keyboard() | ||
1267 | 66 | |||
1268 | 67 | variants = OrderedDict() | ||
1269 | 68 | variants['X11'] = get_x11_kb | ||
1270 | 69 | variants['UInput'] = get_uinput_kb | ||
1271 | 70 | return _pick_variant(variants, preferred_variant) | ||
1272 | 91 | 71 | ||
1273 | 92 | def press(self, keys, delay=0.2): | 72 | def press(self, keys, delay=0.2): |
1274 | 93 | """Send key press events only. | 73 | """Send key press events only. |
1275 | 94 | 74 | ||
1277 | 95 | :param string keys: Keys you want pressed. | 75 | :param keys: Keys you want pressed. |
1278 | 76 | :param delay: The delay (in Seconds) after pressing the keys before | ||
1279 | 77 | returning control to the caller. | ||
1280 | 96 | 78 | ||
1281 | 97 | Example: | 79 | Example: |
1282 | 98 | 80 | ||
1283 | 99 | >>> press('Alt+F2') | 81 | >>> press('Alt+F2') |
1284 | 100 | 82 | ||
1286 | 101 | presses the 'Alt' and 'F2' keys. | 83 | presses the 'Alt' and 'F2' keys, but does not release them. |
1287 | 102 | 84 | ||
1288 | 103 | """ | 85 | """ |
1289 | 104 | raise NotImplementedError("You cannot use this class directly.") | 86 | raise NotImplementedError("You cannot use this class directly.") |
1290 | @@ -106,7 +88,9 @@ | |||
1291 | 106 | def release(self, keys, delay=0.2): | 88 | def release(self, keys, delay=0.2): |
1292 | 107 | """Send key release events only. | 89 | """Send key release events only. |
1293 | 108 | 90 | ||
1295 | 109 | :param string keys: Keys you want released. | 91 | :param keys: Keys you want released. |
1296 | 92 | :param delay: The delay (in Seconds) after releasing the keys before | ||
1297 | 93 | returning control to the caller. | ||
1298 | 110 | 94 | ||
1299 | 111 | Example: | 95 | Example: |
1300 | 112 | 96 | ||
1301 | @@ -122,7 +106,9 @@ | |||
1302 | 122 | 106 | ||
1303 | 123 | This is the same as calling 'press(keys);release(keys)'. | 107 | This is the same as calling 'press(keys);release(keys)'. |
1304 | 124 | 108 | ||
1306 | 125 | :param string keys: Keys you want pressed and released. | 109 | :param keys: Keys you want pressed and released. |
1307 | 110 | :param delay: The delay (in Seconds) after pressing and releasing each | ||
1308 | 111 | key. | ||
1309 | 126 | 112 | ||
1310 | 127 | Example: | 113 | Example: |
1311 | 128 | 114 | ||
1312 | @@ -137,6 +123,11 @@ | |||
1313 | 137 | def type(self, string, delay=0.1): | 123 | def type(self, string, delay=0.1): |
1314 | 138 | """Simulate a user typing a string of text. | 124 | """Simulate a user typing a string of text. |
1315 | 139 | 125 | ||
1316 | 126 | :param string: The string to text to type. | ||
1317 | 127 | :param delay: The delay (in Seconds) after pressing and releasing each | ||
1318 | 128 | key. Note that the default value here is shorter than for the press, | ||
1319 | 129 | release and press_and_release methods. | ||
1320 | 130 | |||
1321 | 140 | .. note:: Only 'normal' keys can be typed with this method. Control | 131 | .. note:: Only 'normal' keys can be typed with this method. Control |
1322 | 141 | characters (such as 'Alt' will be interpreted as an 'A', and 'l', | 132 | characters (such as 'Alt' will be interpreted as an 'A', and 'l', |
1323 | 142 | and a 't'). | 133 | and a 't'). |
1324 | @@ -156,7 +147,40 @@ | |||
1325 | 156 | 147 | ||
1326 | 157 | 148 | ||
1327 | 158 | class Mouse(object): | 149 | class Mouse(object): |
1329 | 159 | """A base class for all mouse-type classes.""" | 150 | |
1330 | 151 | """A simple mouse device class. | ||
1331 | 152 | |||
1332 | 153 | The mouse class is used to generate mouse events while in an autopilot | ||
1333 | 154 | test. This class should not be instantiated directly however. To get an | ||
1334 | 155 | instance of the mouse class, call :py:meth:`create` instead. | ||
1335 | 156 | |||
1336 | 157 | For example, to create a mouse object and click at (100,50): | ||
1337 | 158 | |||
1338 | 159 | >>> mouse = autopilot.input.Mouse.create() | ||
1339 | 160 | >>> mouse.move(100, 50) | ||
1340 | 161 | >>> mouse.click() | ||
1341 | 162 | |||
1342 | 163 | """ | ||
1343 | 164 | |||
1344 | 165 | @staticmethod | ||
1345 | 166 | def create(preferred_variant=''): | ||
1346 | 167 | """Get an instance of the :py:class:`Mouse` class. | ||
1347 | 168 | |||
1348 | 169 | :param preferred_variant: A string containing a hint as to which variant you | ||
1349 | 170 | would like. However, this hint can be ignored - autopilot will prefer to | ||
1350 | 171 | return a mouse variant other than the one requested, rather than fail | ||
1351 | 172 | to return anything at all. | ||
1352 | 173 | :raises: a RuntimeError will be raised if autopilot cannot instantate any of | ||
1353 | 174 | the possible backends. | ||
1354 | 175 | |||
1355 | 176 | """ | ||
1356 | 177 | def get_x11_mouse(): | ||
1357 | 178 | from autopilot.input._X11 import Mouse | ||
1358 | 179 | return Mouse() | ||
1359 | 180 | |||
1360 | 181 | variants = OrderedDict() | ||
1361 | 182 | variants['X11'] = get_x11_mouse | ||
1362 | 183 | return _pick_variant(variants, preferred_variant) | ||
1363 | 160 | 184 | ||
1364 | 161 | @property | 185 | @property |
1365 | 162 | def x(self): | 186 | def x(self): |
1366 | @@ -222,3 +246,73 @@ | |||
1367 | 222 | def cleanup(): | 246 | def cleanup(): |
1368 | 223 | """Put mouse in a known safe state.""" | 247 | """Put mouse in a known safe state.""" |
1369 | 224 | raise NotImplementedError("You cannot use this class directly.") | 248 | raise NotImplementedError("You cannot use this class directly.") |
1370 | 249 | |||
1371 | 250 | |||
1372 | 251 | class Touch(object): | ||
1373 | 252 | """A simple touch driver class. | ||
1374 | 253 | |||
1375 | 254 | This class can be used for any touch events that require a single active | ||
1376 | 255 | touch at once. If you want to do complex gestures (including multi-touch | ||
1377 | 256 | gestures), look at the :py:mod:`autopilot.gestures` module. | ||
1378 | 257 | |||
1379 | 258 | """ | ||
1380 | 259 | |||
1381 | 260 | @staticmethod | ||
1382 | 261 | def create(preferred_variant=''): | ||
1383 | 262 | """Get an instance of the :py:class:`Touch` class. | ||
1384 | 263 | |||
1385 | 264 | :param preferred_variant: A string containing a hint as to which variant you | ||
1386 | 265 | would like. However, this hint can be ignored - autopilot will prefer to | ||
1387 | 266 | return a touch variant other than the one requested, rather than fail | ||
1388 | 267 | to return anything at all. | ||
1389 | 268 | :raises: a RuntimeError will be raised if autopilot cannot instantate any of | ||
1390 | 269 | the possible backends. | ||
1391 | 270 | |||
1392 | 271 | """ | ||
1393 | 272 | def get_uinput_touch(): | ||
1394 | 273 | from autopilot.input._uinput import Touch | ||
1395 | 274 | return Touch() | ||
1396 | 275 | |||
1397 | 276 | variants = OrderedDict() | ||
1398 | 277 | variants['UInput'] = get_uinput_touch | ||
1399 | 278 | return _pick_variant(variants, preferred_variant) | ||
1400 | 279 | |||
1401 | 280 | @property | ||
1402 | 281 | def pressed(self): | ||
1403 | 282 | """Return True if this touch is currently in use (i.e.- pressed on the | ||
1404 | 283 | 'screen'). | ||
1405 | 284 | |||
1406 | 285 | """ | ||
1407 | 286 | raise NotImplementedError("You cannot use this class directly.") | ||
1408 | 287 | |||
1409 | 288 | def tap(self, x, y): | ||
1410 | 289 | """Click (or 'tap') at given x and y coordinates.""" | ||
1411 | 290 | raise NotImplementedError("You cannot use this class directly.") | ||
1412 | 291 | |||
1413 | 292 | def tap_object(self, object): | ||
1414 | 293 | """Tap the center point of a given object. | ||
1415 | 294 | |||
1416 | 295 | It does this by looking for several attributes, in order. The first | ||
1417 | 296 | attribute found will be used. The attributes used are (in order): | ||
1418 | 297 | |||
1419 | 298 | * globalRect (x,y,w,h) | ||
1420 | 299 | * center_x, center_y | ||
1421 | 300 | * x, y, w, h | ||
1422 | 301 | |||
1423 | 302 | :raises: **ValueError** if none of these attributes are found, or if an | ||
1424 | 303 | attribute is of an incorrect type. | ||
1425 | 304 | |||
1426 | 305 | """ | ||
1427 | 306 | raise NotImplementedError("You cannot use this class directly.") | ||
1428 | 307 | |||
1429 | 308 | def press(self, x, y): | ||
1430 | 309 | """Press and hold.""" | ||
1431 | 310 | raise NotImplementedError("You cannot use this class directly.") | ||
1432 | 311 | |||
1433 | 312 | def release(self): | ||
1434 | 313 | """Release a previously pressed finger""" | ||
1435 | 314 | raise NotImplementedError("You cannot use this class directly.") | ||
1436 | 315 | |||
1437 | 316 | def drag(self, x1, y1, x2, y2): | ||
1438 | 317 | """Perform a drag gesture from (x1,y1) to (x2,y2)""" | ||
1439 | 318 | raise NotImplementedError("You cannot use this class directly.") | ||
1440 | 225 | 319 | ||
1441 | === added file 'autopilot/input/_common.py' | |||
1442 | --- autopilot/input/_common.py 1970-01-01 00:00:00 +0000 | |||
1443 | +++ autopilot/input/_common.py 2013-04-15 21:43:32 +0000 | |||
1444 | @@ -0,0 +1,46 @@ | |||
1445 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
1446 | 2 | # Copyright 2013 Canonical | ||
1447 | 3 | # Author: Thomi Richards | ||
1448 | 4 | # | ||
1449 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
1450 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
1451 | 7 | # by the Free Software Foundation. | ||
1452 | 8 | |||
1453 | 9 | """Common, private utility code for input emulators.""" | ||
1454 | 10 | |||
1455 | 11 | import logging | ||
1456 | 12 | |||
1457 | 13 | logger = logging.getLogger(__name__) | ||
1458 | 14 | |||
1459 | 15 | |||
1460 | 16 | def get_center_point(object_proxy): | ||
1461 | 17 | """Get the center point of an object, searching for several different ways | ||
1462 | 18 | of determining exactly where the center is. | ||
1463 | 19 | |||
1464 | 20 | """ | ||
1465 | 21 | try: | ||
1466 | 22 | x,y,w,h = object_proxy.globalRect | ||
1467 | 23 | logger.debug("Moving to object's globalRect coordinates.") | ||
1468 | 24 | return x+w/2, y+h/2 | ||
1469 | 25 | except AttributeError: | ||
1470 | 26 | pass | ||
1471 | 27 | except (TypeError, ValueError): | ||
1472 | 28 | raise ValueError("Object '%r' has globalRect attribute, but it is not of the correct type" % object_proxy) | ||
1473 | 29 | |||
1474 | 30 | try: | ||
1475 | 31 | x,y = object_proxy.center_x, object_proxy.center_y | ||
1476 | 32 | logger.debug("Moving to object's center_x, center_y coordinates.") | ||
1477 | 33 | return x,y | ||
1478 | 34 | except AttributeError: | ||
1479 | 35 | pass | ||
1480 | 36 | except (TypeError, ValueError): | ||
1481 | 37 | raise ValueError("Object '%r' has center_x, center_y attributes, but they are not of the correct type" % object_proxy) | ||
1482 | 38 | |||
1483 | 39 | try: | ||
1484 | 40 | x,y,w,h = object_proxy.x, object_proxy.y, object_proxy.w, object_proxy.h | ||
1485 | 41 | logger.debug("Moving to object's center point calculated from x,y,w,h attributes.") | ||
1486 | 42 | return x+w/2,y+h/2 | ||
1487 | 43 | except AttributeError: | ||
1488 | 44 | raise ValueError("Object '%r' does not have any recognised position attributes" % object_proxy) | ||
1489 | 45 | except (TypeError, ValueError): | ||
1490 | 46 | raise ValueError("Object '%r' has x,y attribute, but they are not of the correct type" % object_proxy) | ||
1491 | 0 | 47 | ||
1492 | === modified file 'autopilot/input/_uinput.py' | |||
1493 | --- autopilot/emulators/input/_uinput.py 2013-02-28 01:00:50 +0000 | |||
1494 | +++ autopilot/input/_uinput.py 2013-04-15 21:43:32 +0000 | |||
1495 | @@ -9,11 +9,14 @@ | |||
1496 | 9 | 9 | ||
1497 | 10 | """UInput device drivers.""" | 10 | """UInput device drivers.""" |
1498 | 11 | 11 | ||
1500 | 12 | from autopilot.emulators.input import Keyboard as KeyboardBase | 12 | from autopilot.input import Keyboard as KeyboardBase |
1501 | 13 | from autopilot.input import Touch as TouchBase | ||
1502 | 14 | from autopilot.input._common import get_center_point | ||
1503 | 15 | import autopilot.platform | ||
1504 | 16 | |||
1505 | 13 | import logging | 17 | import logging |
1506 | 14 | from time import sleep | 18 | from time import sleep |
1509 | 15 | from evdev import AbsData, InputDevice, UInput, ecodes as e | 19 | from evdev import AbsData, UInput, ecodes as e |
1508 | 16 | import os.path | ||
1510 | 17 | 20 | ||
1511 | 18 | logger = logging.getLogger(__name__) | 21 | logger = logging.getLogger(__name__) |
1512 | 19 | 22 | ||
1513 | @@ -22,6 +25,7 @@ | |||
1514 | 22 | 25 | ||
1515 | 23 | PRESSED_KEYS = [] | 26 | PRESSED_KEYS = [] |
1516 | 24 | 27 | ||
1517 | 28 | |||
1518 | 25 | class Keyboard(KeyboardBase): | 29 | class Keyboard(KeyboardBase): |
1519 | 26 | 30 | ||
1520 | 27 | def __init__(self): | 31 | def __init__(self): |
1521 | @@ -46,7 +50,7 @@ | |||
1522 | 46 | raise TypeError("'keys' argument must be a string.") | 50 | raise TypeError("'keys' argument must be a string.") |
1523 | 47 | 51 | ||
1524 | 48 | for key in keys.split('+'): | 52 | for key in keys.split('+'): |
1526 | 49 | for event in _get_events_for_key(key): | 53 | for event in Keyboard._get_events_for_key(key): |
1527 | 50 | self._emit(event, PRESS) | 54 | self._emit(event, PRESS) |
1528 | 51 | sleep(delay) | 55 | sleep(delay) |
1529 | 52 | 56 | ||
1530 | @@ -69,7 +73,7 @@ | |||
1531 | 69 | # # release keys in the reverse order they were pressed in. | 73 | # # release keys in the reverse order they were pressed in. |
1532 | 70 | # keys = self.__translate_keys(keys) | 74 | # keys = self.__translate_keys(keys) |
1533 | 71 | for key in reversed(keys.split('+')): | 75 | for key in reversed(keys.split('+')): |
1535 | 72 | for event in _get_events_for_key(key): | 76 | for event in Keyboard._get_events_for_key(key): |
1536 | 73 | self._emit(event, RELEASE) | 77 | self._emit(event, RELEASE) |
1537 | 74 | sleep(delay) | 78 | sleep(delay) |
1538 | 75 | 79 | ||
1539 | @@ -118,78 +122,58 @@ | |||
1540 | 118 | # fake_input(get_display(), X.KeyRelease, keycode) | 122 | # fake_input(get_display(), X.KeyRelease, keycode) |
1541 | 119 | # _PRESSED_KEYS = [] | 123 | # _PRESSED_KEYS = [] |
1542 | 120 | 124 | ||
1543 | 125 | @staticmethod | ||
1544 | 126 | def _get_events_for_key(key): | ||
1545 | 127 | """Return a list of events required to generate 'key' as an input. | ||
1546 | 128 | |||
1547 | 129 | Multiple keys will be returned when the key specified requires more than one | ||
1548 | 130 | keypress to generate (for example, upper-case letters). | ||
1549 | 131 | |||
1550 | 132 | """ | ||
1551 | 133 | events = [] | ||
1552 | 134 | if key.isupper(): | ||
1553 | 135 | events.append(e.KEY_LEFTSHIFT) | ||
1554 | 136 | keyname = _UINPUT_CODE_TRANSLATIONS.get(key.upper(), key) | ||
1555 | 137 | evt = getattr(e, 'KEY_' + keyname.upper(), None) | ||
1556 | 138 | if evt is None: | ||
1557 | 139 | raise ValueError("Unknown key name: '%s'" % key) | ||
1558 | 140 | events.append(evt) | ||
1559 | 141 | return events | ||
1560 | 142 | |||
1561 | 143 | |||
1562 | 121 | last_tracking_id = 0 | 144 | last_tracking_id = 0 |
1563 | 122 | def get_next_tracking_id(): | 145 | def get_next_tracking_id(): |
1564 | 123 | global last_tracking_id | 146 | global last_tracking_id |
1565 | 124 | last_tracking_id += 1 | 147 | last_tracking_id += 1 |
1566 | 125 | return last_tracking_id | 148 | return last_tracking_id |
1567 | 126 | 149 | ||
1568 | 150 | |||
1569 | 127 | def create_touch_device(res_x=None, res_y=None): | 151 | def create_touch_device(res_x=None, res_y=None): |
1570 | 128 | """Create and return a UInput touch device. | 152 | """Create and return a UInput touch device. |
1571 | 129 | 153 | ||
1616 | 130 | If res_x and res_y are not specified, they will be queried from X11. | 154 | If res_x and res_y are not specified, they will be queried from the system. |
1617 | 131 | 155 | ||
1574 | 132 | The following needs to go into /system/usr/idc/autopilot-finger.idc | ||
1575 | 133 | |||
1576 | 134 | # Copyright (C) 2011 The Android Open Source Project | ||
1577 | 135 | # | ||
1578 | 136 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
1579 | 137 | # you may not use this file except in compliance with the License. | ||
1580 | 138 | # You may obtain a copy of the License at | ||
1581 | 139 | # | ||
1582 | 140 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
1583 | 141 | # | ||
1584 | 142 | # Unless required by applicable law or agreed to in writing, software | ||
1585 | 143 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
1586 | 144 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
1587 | 145 | # See the License for the specific language governing permissions and | ||
1588 | 146 | # limitations under the License. | ||
1589 | 147 | |||
1590 | 148 | # | ||
1591 | 149 | # Input Device Calibration File for the Tuna touch screen. | ||
1592 | 150 | # | ||
1593 | 151 | |||
1594 | 152 | device.internal = 1 | ||
1595 | 153 | |||
1596 | 154 | # Basic Parameters | ||
1597 | 155 | touch.deviceType = touchScreen | ||
1598 | 156 | touch.orientationAware = 1 | ||
1599 | 157 | |||
1600 | 158 | # Size | ||
1601 | 159 | touch.size.calibration = diameter | ||
1602 | 160 | touch.size.scale = 10 | ||
1603 | 161 | touch.size.bias = 0 | ||
1604 | 162 | touch.size.isSummed = 0 | ||
1605 | 163 | |||
1606 | 164 | # Pressure | ||
1607 | 165 | # Driver reports signal strength as pressure. | ||
1608 | 166 | # | ||
1609 | 167 | # A normal thumb touch typically registers about 200 signal strength | ||
1610 | 168 | # units although we don't expect these values to be accurate. | ||
1611 | 169 | touch.pressure.calibration = amplitude | ||
1612 | 170 | touch.pressure.scale = 0.005 | ||
1613 | 171 | |||
1614 | 172 | # Orientation | ||
1615 | 173 | touch.orientation.calibration = none | ||
1618 | 174 | """ | 156 | """ |
1619 | 175 | 157 | ||
1620 | 176 | # FIXME: remove the harcoded values and determine ScreenGeometry without X11 | ||
1621 | 177 | res_x = 720 | ||
1622 | 178 | res_y = 1280 | ||
1623 | 179 | |||
1624 | 180 | if res_x is None or res_y is None: | 158 | if res_x is None or res_y is None: |
1629 | 181 | from autopilot.emulators.X11 import ScreenGeometry | 159 | from autopilot.display import Display |
1630 | 182 | sg = ScreenGeometry() | 160 | display = Display.create() |
1631 | 183 | res_x = sg.get_screen_width() | 161 | res_x = display.get_screen_width() |
1632 | 184 | res_y = sg.get_screen_height() | 162 | res_y = display.get_screen_height() |
1633 | 163 | |||
1634 | 164 | # android uses BTN_TOOL_FINGER, whereas desktop uses BTN_TOUCH. I have no | ||
1635 | 165 | # idea why... | ||
1636 | 166 | touch_tool = e.BTN_TOOL_FINGER | ||
1637 | 167 | if autopilot.platform.model() == 'Desktop': | ||
1638 | 168 | touch_tool = e.BTN_TOUCH | ||
1639 | 185 | 169 | ||
1640 | 186 | cap_mt = { | 170 | cap_mt = { |
1641 | 187 | e.EV_ABS : [ | 171 | e.EV_ABS : [ |
1642 | 188 | (e.ABS_X, AbsData(0, res_x, 0, 0)), | 172 | (e.ABS_X, AbsData(0, res_x, 0, 0)), |
1643 | 189 | (e.ABS_Y, AbsData(0, res_y, 0, 0)), | 173 | (e.ABS_Y, AbsData(0, res_y, 0, 0)), |
1644 | 190 | (e.ABS_PRESSURE, AbsData(0, 65535, 0, 0)), | 174 | (e.ABS_PRESSURE, AbsData(0, 65535, 0, 0)), |
1647 | 191 | (e.ABS_DISTANCE, AbsData(0, 65535, 0, 0)), | 175 | # (e.ABS_DISTANCE, AbsData(0, 65535, 0, 0)), |
1648 | 192 | (e.ABS_TOOL_WIDTH, AbsData(0, 65535, 0, 0)), | 176 | # (e.ABS_TOOL_WIDTH, AbsData(0, 65535, 0, 0)), |
1649 | 193 | (e.ABS_MT_POSITION_X, AbsData(0, res_x, 0, 0)), | 177 | (e.ABS_MT_POSITION_X, AbsData(0, res_x, 0, 0)), |
1650 | 194 | (e.ABS_MT_POSITION_Y, AbsData(0, res_y, 0, 0)), | 178 | (e.ABS_MT_POSITION_Y, AbsData(0, res_y, 0, 0)), |
1651 | 195 | (e.ABS_MT_TOUCH_MAJOR, AbsData(0, 30, 0, 0)), | 179 | (e.ABS_MT_TOUCH_MAJOR, AbsData(0, 30, 0, 0)), |
1652 | @@ -198,147 +182,122 @@ | |||
1653 | 198 | (e.ABS_MT_SLOT, (0, 9, 0, 0)), | 182 | (e.ABS_MT_SLOT, (0, 9, 0, 0)), |
1654 | 199 | ], | 183 | ], |
1655 | 200 | e.EV_KEY: [ | 184 | e.EV_KEY: [ |
1657 | 201 | e.BTN_TOOL_FINGER, | 185 | touch_tool, |
1658 | 202 | ] | 186 | ] |
1659 | 203 | } | 187 | } |
1660 | 204 | 188 | ||
1746 | 205 | try: | 189 | return UInput(cap_mt, name='autopilot-finger', version=0x2) |
1747 | 206 | device = UInput(cap_mt, name='autopilot-finger', version=0x2) | 190 | |
1748 | 207 | return device | 191 | _touch_device = create_touch_device() |
1749 | 208 | except: | 192 | |
1750 | 209 | logger.warning("Failed to open uinput device. Finger will not be available") | 193 | # Multiouch notes: |
1751 | 210 | return None | 194 | # ---------------- |
1752 | 211 | 195 | ||
1753 | 212 | 196 | # We're simulating a class of device that can track multiple touches, and keep | |
1754 | 213 | def find_touch_device(): | 197 | # them separate. This is how most modern track devices work anyway. The device |
1755 | 214 | """Return a list of touch devices found on the local machine. | 198 | # is created with a capability to track a certain number of distinct touches at |
1756 | 215 | 199 | # once. This is the ABS_MT_SLOT capability. Since our target device can track 9 | |
1757 | 216 | :returns: A list of evdev.inputDevice objects, possibly an empty list. | 200 | # separate touches, we'll do the same. |
1758 | 217 | 201 | ||
1759 | 218 | """ | 202 | # Each finger contact starts by registering a slot number (0-8) with a tracking |
1760 | 219 | def device_cmp(dev_a, dev_b): | 203 | # Id. The Id should be unique for this touch - this can be an auto-inctrementing |
1761 | 220 | def get_track_slot(dev): | 204 | # integer. The very first packets to tell the kernel that we have a touch happening |
1762 | 221 | capabilities = dev.capabilities() | 205 | # should look like this: |
1763 | 222 | for track_feature in capabilities[e.EV_ABS]: | 206 | |
1764 | 223 | if track_feature[0] == e.ABS_MT_SLOT: | 207 | # ABS_MT_SLOT 0 |
1765 | 224 | return track_feature[1][1] | 208 | # ABS_MT_TRACKING_ID 45 |
1766 | 225 | return get_track_slot(dev_a) < get_track_slot(dev_b) | 209 | # ABS_MT_POSITION_X x[0] |
1767 | 226 | 210 | # ABS_MT_POSITION_Y y[0] | |
1768 | 227 | i = 0 | 211 | |
1769 | 228 | touch_devices = [] | 212 | # This associates Tracking id 45 (could be any number) with slot 0. Slot 0 can now |
1770 | 229 | while True: | 213 | # not be use by any other touch until it is released. |
1771 | 230 | path = '/dev/input/event%d' % (i) | 214 | |
1772 | 231 | if not os.path.exists(path): | 215 | # If we want to move this contact's coordinates, we do this: |
1773 | 232 | break | 216 | |
1774 | 233 | 217 | # ABS_MT_SLOT 0 | |
1775 | 234 | dev = InputDevice(path) | 218 | # ABS_MT_POSITION_X 123 |
1776 | 235 | capabilities = dev.capabilities() | 219 | # ABS_MT_POSITION_Y 234 |
1777 | 236 | if e.EV_ABS in capabilities: | 220 | |
1778 | 237 | touch_devices.append(dev) | 221 | # Technically, the 'SLOT 0' part isn't needed, since we're already in slot 0, but |
1779 | 238 | i += 1 | 222 | # it doesn't hurt to have it there. |
1780 | 239 | touch_devices.sort(device_cmp) | 223 | |
1781 | 240 | return touch_devices | 224 | # To lift the contact, we simply specify a tracking Id of -1: |
1782 | 241 | 225 | ||
1783 | 242 | 226 | # ABS_MT_SLOT 0 | |
1784 | 243 | """ | 227 | # ABS_MT_TRACKING_ID -1 |
1785 | 244 | Multiouch notes: | 228 | |
1786 | 245 | ---------------- | 229 | # The initial association between slot and tracking Id is made when the 'finger' |
1787 | 246 | 230 | # first makes contact with the device (well, not technically true, but close | |
1788 | 247 | We're simulating a class of device that can track multiple touches, and keep | 231 | # enough). Multiple touches can be active simultaniously, as long as they all have |
1789 | 248 | them separate. This is how most modern track devices work anyway. The device | 232 | # unique slots, and tracking Ids. The simplest way to think about this is that the |
1790 | 249 | is created with a capability to track a certain number of distinct touches at | 233 | # SLOT refers to a finger number, and the TRACKING_ID identifies a unique touch |
1791 | 250 | once. This is the ABS_MT_SLOT capability. Since our target device can track 9 | 234 | # for the duration of it's existance. |
1792 | 251 | separate touches, we'll do the same. | 235 | |
1793 | 252 | 236 | _touch_fingers_in_use = [] | |
1794 | 253 | Each finger contact starts by registering a slot number (0-8) with a tracking | 237 | def _get_touch_finger(): |
1795 | 254 | Id. The Id should be unique for this touch - this can be an auto-inctrementing | 238 | """Claim a touch finger id for use. |
1796 | 255 | integer. The very first packets to tell the kernel that we have a touch happening | 239 | |
1797 | 256 | should look like this: | 240 | :raises: RuntimeError if no more fingers are available. |
1798 | 257 | 241 | ||
1799 | 258 | ABS_MT_SLOT 0 | 242 | """ |
1800 | 259 | ABS_MT_TRACKING_ID 45 | 243 | global _touch_fingers_in_use |
1801 | 260 | ABS_MT_POSITION_X x[0] | 244 | |
1802 | 261 | ABS_MT_POSITION_Y y[0] | 245 | for i in range(9): |
1803 | 262 | 246 | if i not in _touch_fingers_in_use: | |
1804 | 263 | This associates Tracking id 45 (could be any number) with slot 0. Slot 0 can now | 247 | _touch_fingers_in_use.append(i) |
1805 | 264 | not be use by any other touch until it is released. | 248 | return i |
1806 | 265 | 249 | raise RuntimeError("All available fingers have been used already.") | |
1807 | 266 | If we want to move this contact's coordinates, we do this: | 250 | |
1808 | 267 | 251 | def _release_touch_finger(finger_num): | |
1809 | 268 | ABS_MT_SLOT 0 | 252 | """Relase a previously-claimed finger id. |
1810 | 269 | ABS_MT_POSITION_X 123 | 253 | |
1811 | 270 | ABS_MT_POSITION_Y 234 | 254 | :raises: RuntimeError if the finger given was never claimed, or was already |
1812 | 271 | 255 | released. | |
1813 | 272 | Technically, the 'SLOT 0' part isn't needed, since we're already in slot 0, but | 256 | |
1814 | 273 | it doesn't hurt to have it there. | 257 | """ |
1815 | 274 | 258 | global _touch_fingers_in_use | |
1816 | 275 | To lift the contact, we simply specify a tracking Id of -1: | 259 | |
1817 | 276 | 260 | if finger_num not in _touch_fingers_in_use: | |
1818 | 277 | ABS_MT_SLOT 0 | 261 | raise RuntimeError("Finger %d was never claimed, or has already been released." % (finger_num)) |
1819 | 278 | ABS_MT_TRACKING_ID -1 | 262 | _touch_fingers_in_use.remove(finger_num) |
1820 | 279 | 263 | assert(finger_num not in _touch_fingers_in_use) | |
1821 | 280 | The initial association between slot and tracking Id is made when the 'finger' | 264 | |
1822 | 281 | first makes contact with the device (well, not technically true, but close | 265 | |
1823 | 282 | enough). Multiple touches can be active simultaniously, as long as they all have | 266 | class Touch(TouchBase): |
1739 | 283 | unique slots, and tracking Ids. The simplest way to think about this is that the | ||
1740 | 284 | SLOT refers to a finger number, and the TRACKING_ID identifies a unique touch | ||
1741 | 285 | for the duration of it's existance. | ||
1742 | 286 | |||
1743 | 287 | """ | ||
1744 | 288 | |||
1745 | 289 | class Finger(object): | ||
1824 | 290 | """Low level interface to generate single finger touch events.""" | 267 | """Low level interface to generate single finger touch events.""" |
1825 | 291 | 268 | ||
1826 | 292 | def __init__(self): | 269 | def __init__(self): |
1845 | 293 | self.device = create_touch_device() | 270 | super(TouchBase, self).__init__() |
1846 | 294 | if self.device == None: | 271 | self._touch_finger = None |
1847 | 295 | raise UInputError | 272 | |
1848 | 296 | self.current_x = 0 | 273 | @property |
1849 | 297 | self.current_y = 0 | 274 | def pressed(self): |
1850 | 298 | 275 | return self._touch_finger is not None | |
1833 | 299 | def move(self, x, y): | ||
1834 | 300 | """This is a convenience function to keep API compatibility with other pointer input methods""" | ||
1835 | 301 | self.current_x = x | ||
1836 | 302 | self.current_y = y | ||
1837 | 303 | |||
1838 | 304 | def move_to_object(self, object): | ||
1839 | 305 | """This is a convenience function to keep API compatibility with other pointer input methods""" | ||
1840 | 306 | self.current_x = object.globalRect[0] + object.globalRect[2] / 2 | ||
1841 | 307 | self.current_y = object.globalRect[1] + object.globalRect[3] / 2 | ||
1842 | 308 | |||
1843 | 309 | def click(self): | ||
1844 | 310 | self.tap(self.current_x, self.current_y) | ||
1851 | 311 | 276 | ||
1852 | 312 | def tap(self, x, y): | 277 | def tap(self, x, y): |
1853 | 313 | """Click (or 'tap') at given x and y coordinates.""" | 278 | """Click (or 'tap') at given x and y coordinates.""" |
1855 | 314 | self._finger_down(0, x, y) | 279 | self._finger_down(x, y) |
1856 | 315 | sleep(0.1) | 280 | sleep(0.1) |
1858 | 316 | self._finger_up(0) | 281 | self._finger_up() |
1859 | 317 | 282 | ||
1860 | 318 | def tap_object(self, object): | 283 | def tap_object(self, object): |
1861 | 319 | """Click (or 'tap') a given object""" | 284 | """Click (or 'tap') a given object""" |
1863 | 320 | self.tap(object.globalRect[0] + object.globalRect[2] / 2, object.globalRect[1] + object.globalRect[3] / 2) | 285 | x,y = get_center_point(object) |
1864 | 286 | self.tap(x,y) | ||
1865 | 321 | 287 | ||
1867 | 322 | def press(self, *args): | 288 | def press(self, x, y): |
1868 | 323 | """Press and hold a given object or at the given coordinates | 289 | """Press and hold a given object or at the given coordinates |
1869 | 324 | Call release() when the object has been pressed long enough""" | 290 | Call release() when the object has been pressed long enough""" |
1878 | 325 | if len(args) == 2: | 291 | self._finger_down(x, y) |
1871 | 326 | self.current_x = args[0] | ||
1872 | 327 | self.current_y = args[1] | ||
1873 | 328 | elif len(args) == 0: | ||
1874 | 329 | pass | ||
1875 | 330 | else: | ||
1876 | 331 | raise InvalidArgCount | ||
1877 | 332 | self._finger_down(0, self.current_x, self.current_y) | ||
1879 | 333 | 292 | ||
1880 | 334 | def release(self): | 293 | def release(self): |
1881 | 335 | """Release a previously pressed finger""" | 294 | """Release a previously pressed finger""" |
1883 | 336 | self._finger_up(0) | 295 | self._finger_up() |
1884 | 337 | 296 | ||
1885 | 338 | 297 | ||
1886 | 339 | def drag(self, x1, y1, x2, y2): | 298 | def drag(self, x1, y1, x2, y2): |
1887 | 340 | """Perform a drag gesture from (x1,y1) to (x2,y2)""" | 299 | """Perform a drag gesture from (x1,y1) to (x2,y2)""" |
1889 | 341 | self._finger_down(0, x1, y1) | 300 | self._finger_down(x1, y1) |
1890 | 342 | 301 | ||
1891 | 343 | # Let's drag in 100 steps for now... | 302 | # Let's drag in 100 steps for now... |
1892 | 344 | dx = 1.0 * (x2 - x1) / 100 | 303 | dx = 1.0 * (x2 - x1) / 100 |
1893 | @@ -346,92 +305,49 @@ | |||
1894 | 346 | cur_x = x1 + dx | 305 | cur_x = x1 + dx |
1895 | 347 | cur_y = y1 + dy | 306 | cur_y = y1 + dy |
1896 | 348 | for i in range(0, 100): | 307 | for i in range(0, 100): |
1898 | 349 | self._finger_move(0, int(cur_x), int(cur_y)) | 308 | self._finger_move(int(cur_x), int(cur_y)) |
1899 | 350 | sleep(0.002) | 309 | sleep(0.002) |
1900 | 351 | cur_x += dx | 310 | cur_x += dx |
1901 | 352 | cur_y += dy | 311 | cur_y += dy |
1902 | 353 | # Make sure we actually end up at target | 312 | # Make sure we actually end up at target |
1943 | 354 | self._finger_move(0, x2, y2) | 313 | self._finger_move(x2, y2) |
1944 | 355 | self._finger_up(0) | 314 | self._finger_up() |
1945 | 356 | 315 | ||
1946 | 357 | def pinch(self, center, distance_start, distance_end): | 316 | |
1947 | 358 | """Perform a two finger pinch (zoom) gesture | 317 | |
1948 | 359 | "center" gives the coordinates [x,y] of the center between the two fingers | 318 | def _finger_down(self, x, y): |
1909 | 360 | "distance_start" [x,y] values to move away from the center for the start | ||
1910 | 361 | "distance_end" [x,y] values to move away from the center for the end | ||
1911 | 362 | The fingers will move in 100 steps between the start and the end points. | ||
1912 | 363 | If start is smaller than end, the gesture will zoom in, otherwise it | ||
1913 | 364 | will zoom out.""" | ||
1914 | 365 | |||
1915 | 366 | finger_1_start = [center[0] - distance_start[0], center[1] - distance_start[1]] | ||
1916 | 367 | finger_2_start = [center[0] + distance_start[0], center[1] + distance_start[1]] | ||
1917 | 368 | finger_1_end = [center[0] - distance_end[0], center[1] - distance_end[1]] | ||
1918 | 369 | finger_2_end = [center[0] + distance_end[0], center[1] + distance_end[1]] | ||
1919 | 370 | |||
1920 | 371 | dx = 1.0 * (finger_1_end[0] - finger_1_start[0]) / 100 | ||
1921 | 372 | dy = 1.0 * (finger_1_end[1] - finger_1_start[1]) / 100 | ||
1922 | 373 | |||
1923 | 374 | self._finger_down(0, finger_1_start[0], finger_1_start[1]) | ||
1924 | 375 | self._finger_down(1, finger_2_start[0], finger_2_start[1]) | ||
1925 | 376 | |||
1926 | 377 | finger_1_cur = [finger_1_start[0] + dx, finger_1_start[1] + dy] | ||
1927 | 378 | finger_2_cur = [finger_2_start[0] - dx, finger_2_start[1] - dy] | ||
1928 | 379 | |||
1929 | 380 | for i in range(0, 100): | ||
1930 | 381 | self._finger_move(0, finger_1_cur[0], finger_1_cur[1]) | ||
1931 | 382 | self._finger_move(1, finger_2_cur[0], finger_2_cur[1]) | ||
1932 | 383 | sleep(0.005) | ||
1933 | 384 | |||
1934 | 385 | finger_1_cur = [finger_1_cur[0] + dx, finger_1_cur[1] + dy] | ||
1935 | 386 | finger_2_cur = [finger_2_cur[0] - dx, finger_2_cur[1] - dy] | ||
1936 | 387 | |||
1937 | 388 | self._finger_move(0, finger_1_end[0], finger_1_end[1]) | ||
1938 | 389 | self._finger_move(1, finger_2_end[0], finger_2_end[1]) | ||
1939 | 390 | self._finger_up(0) | ||
1940 | 391 | self._finger_up(1) | ||
1941 | 392 | |||
1942 | 393 | def _finger_down(self, finger, x, y): | ||
1949 | 394 | """Internal: moves finger "finger" down to the touchscreen at pos (x,y)""" | 319 | """Internal: moves finger "finger" down to the touchscreen at pos (x,y)""" |
1960 | 395 | self.device.write(e.EV_ABS, e.ABS_MT_SLOT, finger) | 320 | if self._touch_finger is not None: |
1961 | 396 | self.device.write(e.EV_ABS, e.ABS_MT_TRACKING_ID, get_next_tracking_id()) | 321 | raise RuntimeError("Cannot press finger: it's already pressed.") |
1962 | 397 | self.device.write(e.EV_KEY, e.BTN_TOOL_FINGER, 1) | 322 | self._touch_finger = _get_touch_finger() |
1963 | 398 | self.device.write(e.EV_ABS, e.ABS_MT_POSITION_X, x) | 323 | |
1964 | 399 | self.device.write(e.EV_ABS, e.ABS_MT_POSITION_Y, y) | 324 | _touch_device.write(e.EV_ABS, e.ABS_MT_SLOT, self._touch_finger) |
1965 | 400 | self.device.write(e.EV_ABS, e.ABS_MT_PRESSURE, 400) | 325 | _touch_device.write(e.EV_ABS, e.ABS_MT_TRACKING_ID, get_next_tracking_id()) |
1966 | 401 | self.device.syn() | 326 | _touch_device.write(e.EV_KEY, e.BTN_TOOL_FINGER, 1) |
1967 | 402 | 327 | _touch_device.write(e.EV_ABS, e.ABS_MT_POSITION_X, int(x)) | |
1968 | 403 | 328 | _touch_device.write(e.EV_ABS, e.ABS_MT_POSITION_Y, int(y)) | |
1969 | 404 | def _finger_move(self, finger, x, y): | 329 | _touch_device.write(e.EV_ABS, e.ABS_MT_PRESSURE, 400) |
1970 | 330 | _touch_device.syn() | ||
1971 | 331 | |||
1972 | 332 | |||
1973 | 333 | def _finger_move(self, x, y): | ||
1974 | 405 | """Internal: moves finger "finger" on the touchscreen to pos (x,y) | 334 | """Internal: moves finger "finger" on the touchscreen to pos (x,y) |
1975 | 406 | NOTE: The finger has to be down for this to have any effect.""" | 335 | NOTE: The finger has to be down for this to have any effect.""" |
1983 | 407 | self.device.write(e.EV_ABS, e.ABS_MT_SLOT, finger) | 336 | if self._touch_finger is not None: |
1984 | 408 | self.device.write(e.EV_ABS, e.ABS_MT_POSITION_X, int(x)) | 337 | _touch_device.write(e.EV_ABS, e.ABS_MT_SLOT, self._touch_finger) |
1985 | 409 | self.device.write(e.EV_ABS, e.ABS_MT_POSITION_Y, int(y)) | 338 | _touch_device.write(e.EV_ABS, e.ABS_MT_POSITION_X, int(x)) |
1986 | 410 | self.device.syn() | 339 | _touch_device.write(e.EV_ABS, e.ABS_MT_POSITION_Y, int(y)) |
1987 | 411 | 340 | _touch_device.syn() | |
1988 | 412 | 341 | ||
1989 | 413 | def _finger_up(self, finger): | 342 | |
1990 | 343 | def _finger_up(self): | ||
1991 | 414 | """Internal: moves finger "finger" up from the touchscreen""" | 344 | """Internal: moves finger "finger" up from the touchscreen""" |
2012 | 415 | self.device.write(e.EV_ABS, e.ABS_MT_SLOT, finger) | 345 | if self._touch_finger is None: |
2013 | 416 | self.device.write(e.EV_ABS, e.ABS_MT_TRACKING_ID, -1) | 346 | raise RuntimeError("Cannot release finger: it's not pressed.") |
2014 | 417 | self.device.write(e.EV_KEY, e.BTN_TOOL_FINGER, 0) | 347 | _touch_device.write(e.EV_ABS, e.ABS_MT_SLOT, self._touch_finger) |
2015 | 418 | self.device.syn() | 348 | _touch_device.write(e.EV_ABS, e.ABS_MT_TRACKING_ID, -1) |
2016 | 419 | 349 | _touch_device.write(e.EV_KEY, e.BTN_TOOL_FINGER, 0) | |
2017 | 420 | 350 | _touch_device.syn() | |
1998 | 421 | class MultiTouch(object): | ||
1999 | 422 | """High level interface to generate multi-touch events.""" | ||
2000 | 423 | |||
2001 | 424 | # Need to work out a good interface for generating multitouch events... | ||
2002 | 425 | # Possibly get users to specify each individual finger tracking path, or | ||
2003 | 426 | # possibly specify a gesture by name, with parameters or so? | ||
2004 | 427 | # | ||
2005 | 428 | # Probably need to specify X & Y resolution as well. Think we can ignore | ||
2006 | 429 | # pressure right now. | ||
2007 | 430 | # | ||
2008 | 431 | # Multi-touch protocol documentation is here: | ||
2009 | 432 | # | ||
2010 | 433 | # http://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt | ||
2011 | 434 | |||
2018 | 435 | 351 | ||
2019 | 436 | 352 | ||
2020 | 437 | _UINPUT_CODE_TRANSLATIONS = { | 353 | _UINPUT_CODE_TRANSLATIONS = { |
2021 | @@ -441,23 +357,3 @@ | |||
2022 | 441 | 'ALT': 'LEFTALT', | 357 | 'ALT': 'LEFTALT', |
2023 | 442 | 'SHIFT': 'LEFTSHIFT', | 358 | 'SHIFT': 'LEFTSHIFT', |
2024 | 443 | } | 359 | } |
2025 | 444 | |||
2026 | 445 | |||
2027 | 446 | def _get_events_for_key(key): | ||
2028 | 447 | """Return a list of events required to generate 'key' as an input. | ||
2029 | 448 | |||
2030 | 449 | Multiple keys will be returned when the key specified requires more than one | ||
2031 | 450 | keypress to generate (for example, upper-case letters). | ||
2032 | 451 | |||
2033 | 452 | """ | ||
2034 | 453 | events = [] | ||
2035 | 454 | if key.isupper(): | ||
2036 | 455 | events.append(e.KEY_LEFTSHIFT) | ||
2037 | 456 | keyname = _UINPUT_CODE_TRANSLATIONS.get(key.upper(), key) | ||
2038 | 457 | evt = getattr(e, 'KEY_' + keyname.upper(), None) | ||
2039 | 458 | if evt is None: | ||
2040 | 459 | raise ValueError("Unknown key name: '%s'" % key) | ||
2041 | 460 | events.append(evt) | ||
2042 | 461 | return events | ||
2043 | 462 | |||
2044 | 463 | |||
2045 | 464 | 360 | ||
2046 | === modified file 'autopilot/introspection/__init__.py' | |||
2047 | --- autopilot/introspection/__init__.py 2013-02-22 03:31:40 +0000 | |||
2048 | +++ autopilot/introspection/__init__.py 2013-04-15 21:43:32 +0000 | |||
2049 | @@ -7,16 +7,18 @@ | |||
2050 | 7 | # by the Free Software Foundation. | 7 | # by the Free Software Foundation. |
2051 | 8 | # | 8 | # |
2052 | 9 | 9 | ||
2054 | 10 | """Package for introspection support.""" | 10 | """Package for introspection support. |
2055 | 11 | |||
2056 | 12 | This package contains the internal implementation of the autopilot introspection | ||
2057 | 13 | mechanism, and probably isn't useful to most test authors. | ||
2058 | 14 | |||
2059 | 15 | """ | ||
2060 | 11 | 16 | ||
2061 | 12 | import dbus | 17 | import dbus |
2062 | 13 | from gi.repository import Gio | ||
2063 | 14 | import logging | 18 | import logging |
2064 | 15 | import subprocess | 19 | import subprocess |
2065 | 16 | from testtools.content import text_content | ||
2066 | 17 | from time import sleep | 20 | from time import sleep |
2067 | 18 | import os | 21 | import os |
2068 | 19 | import signal | ||
2069 | 20 | 22 | ||
2070 | 21 | 23 | ||
2071 | 22 | from autopilot.introspection.constants import ( | 24 | from autopilot.introspection.constants import ( |
2072 | @@ -31,62 +33,65 @@ | |||
2073 | 31 | object_passes_filters, | 33 | object_passes_filters, |
2074 | 32 | get_session_bus, | 34 | get_session_bus, |
2075 | 33 | ) | 35 | ) |
2077 | 34 | from autopilot.utilities import get_debug_logger | 36 | from autopilot.utilities import get_debug_logger, addCleanup |
2078 | 35 | 37 | ||
2079 | 36 | 38 | ||
2080 | 37 | logger = logging.getLogger(__name__) | 39 | logger = logging.getLogger(__name__) |
2081 | 38 | 40 | ||
2082 | 39 | 41 | ||
2133 | 40 | class ApplicationIntrospectionTestMixin(object): | 42 | def get_application_launcher(app_path): |
2134 | 41 | """A mix-in class to make launching applications for introsection easier. | 43 | """Return an instance of :class:`ApplicationLauncher` that knows how to launch |
2135 | 42 | 44 | the application at 'app_path'. | |
2136 | 43 | .. important:: You should not instantiate this class directly. Instead, use | 45 | """ |
2137 | 44 | one of the derived classes. | 46 | # TODO: this is a teeny bit hacky - we call ldd to check whether this application |
2138 | 45 | 47 | # links to certain library. We're assuming that linking to libQt* or libGtk* | |
2139 | 46 | """ | 48 | # means the application is introspectable. This excludes any non-dynamically |
2140 | 47 | 49 | # linked executables, which we may need to fix further down the line. | |
2141 | 48 | def launch_test_application(self, application, *arguments, **kwargs): | 50 | try: |
2142 | 49 | """Launch *application* and retrieve a proxy object for the application. | 51 | ldd_output = subprocess.check_output(["ldd", app_path]).strip().lower() |
2143 | 50 | 52 | except subprocess.CalledProcessError: | |
2144 | 51 | Use this method to launch a supported application and start testing it. | 53 | print "Error: Cannot auto-detect introspection plugin to load." |
2145 | 52 | The application can be specified as: | 54 | print "Use the '-i' argument to specify an interface." |
2146 | 53 | 55 | exit(1) # TODO - don't exit, raise an exception, and handle it appropriately in parent code. | |
2147 | 54 | * A Desktop file, either with or without a path component. | 56 | if 'libqtcore' in ldd_output: |
2148 | 55 | * An executable file, either with a path, or one that is in the $PATH. | 57 | from autopilot.introspection.qt import QtApplicationLauncher |
2149 | 56 | 58 | return QtApplicationLauncher() | |
2150 | 57 | This method supports the following keyword arguments: | 59 | elif 'libgtk' in ldd_output: |
2151 | 58 | 60 | from autopilot.introspection.gtk import GtkApplicationLauncher | |
2152 | 59 | * *launch_dir*. If set to a directory that exists the process will be | 61 | return GtkApplicationLauncher() |
2153 | 60 | launched from that directory. | 62 | return None |
2154 | 61 | 63 | ||
2155 | 62 | * *capture_output*. If set to True (the default), the process output | 64 | |
2156 | 63 | will be captured and attached to the test as test detail. | 65 | def launch_application(launcher, application, *arguments, **kwargs): |
2157 | 64 | 66 | """Launch an application, and return a process object. | |
2158 | 65 | :raises: **ValueError** if unknown keyword arguments are passed. | 67 | |
2159 | 66 | :return: A proxy object that represents the application. Introspection | 68 | :param launcher: An instance of the :class:`ApplicationLauncher` class to |
2160 | 67 | data is retrievable via this object. | 69 | prepare the environment before launching the application itself. |
2161 | 68 | 70 | """ | |
2162 | 69 | """ | 71 | |
2163 | 70 | if not isinstance(application, basestring): | 72 | if not isinstance(application, basestring): |
2164 | 71 | raise TypeError("'application' parameter must be a string.") | 73 | raise TypeError("'application' parameter must be a string.") |
2165 | 72 | cwd = kwargs.pop('launch_dir', None) | 74 | cwd = kwargs.pop('launch_dir', None) |
2166 | 73 | capture_output = kwargs.pop('capture_output', True) | 75 | capture_output = kwargs.pop('capture_output', True) |
2167 | 74 | if kwargs: | 76 | if kwargs: |
2168 | 75 | raise ValueError("Unknown keyword arguments: %s." % | 77 | raise ValueError("Unknown keyword arguments: %s." % |
2169 | 76 | (', '.join( repr(k) for k in kwargs.keys()))) | 78 | (', '.join( repr(k) for k in kwargs.keys()))) |
2170 | 77 | 79 | ||
2171 | 78 | if application.endswith('.desktop'): | 80 | path, args = launcher.prepare_environment(application, list(arguments)) |
2172 | 79 | proc = Gio.DesktopAppInfo.new(application) | 81 | |
2173 | 80 | application = proc.get_executable() | 82 | process = launch_process(path, |
2174 | 81 | 83 | args, | |
2175 | 82 | path, args = self.prepare_environment(application, list(arguments)) | 84 | capture_output, |
2176 | 83 | 85 | cwd=cwd | |
2177 | 84 | process = launch_autopilot_enabled_process(path, | 86 | ) |
2178 | 85 | args, | 87 | return process |
2179 | 86 | capture_output, | 88 | |
2180 | 87 | cwd=cwd) | 89 | |
2181 | 88 | self.addCleanup(self._kill_process_and_attach_logs, process) | 90 | class ApplicationLauncher(object): |
2182 | 89 | return get_autopilot_proxy_object_for_process(process) | 91 | """A class that knows how to launch an application with a certain type of |
2183 | 92 | introspection enabled. | ||
2184 | 93 | |||
2185 | 94 | """ | ||
2186 | 90 | 95 | ||
2187 | 91 | def prepare_environment(self, app_path, arguments): | 96 | def prepare_environment(self, app_path, arguments): |
2188 | 92 | """Prepare the application, or environment to launch with autopilot-support. | 97 | """Prepare the application, or environment to launch with autopilot-support. |
2189 | @@ -99,22 +104,9 @@ | |||
2190 | 99 | """ | 104 | """ |
2191 | 100 | raise NotImplementedError("Sub-classes must implement this method.") | 105 | raise NotImplementedError("Sub-classes must implement this method.") |
2192 | 101 | 106 | ||
2209 | 102 | def _kill_process_and_attach_logs(self, process): | 107 | |
2210 | 103 | process.kill() | 108 | |
2211 | 104 | logger.info("waiting for process to exit.") | 109 | def launch_process(application, args, capture_output, **kwargs): |
2196 | 105 | for i in range(10): | ||
2197 | 106 | if process.returncode is not None: | ||
2198 | 107 | break | ||
2199 | 108 | if i == 9: | ||
2200 | 109 | logger.info("Terminating process group, since it hasn't exited after 10 seconds.") | ||
2201 | 110 | os.killpg(process.pid, signal.SIGTERM) | ||
2202 | 111 | sleep(1) | ||
2203 | 112 | stdout, stderr = process.communicate() | ||
2204 | 113 | self.addDetail('process-stdout', text_content(stdout)) | ||
2205 | 114 | self.addDetail('process-stderr', text_content(stderr)) | ||
2206 | 115 | |||
2207 | 116 | |||
2208 | 117 | def launch_autopilot_enabled_process(application, args, capture_output, **kwargs): | ||
2212 | 118 | """Launch an autopilot-enabled process and return the proxy object.""" | 110 | """Launch an autopilot-enabled process and return the proxy object.""" |
2213 | 119 | commandline = [application] | 111 | commandline = [application] |
2214 | 120 | commandline.extend(args) | 112 | commandline.extend(args) |
2215 | @@ -132,28 +124,6 @@ | |||
2216 | 132 | return process | 124 | return process |
2217 | 133 | 125 | ||
2218 | 134 | 126 | ||
2219 | 135 | def get_child_pids(pid): | ||
2220 | 136 | """Get a list of all child process Ids, for the given parent. | ||
2221 | 137 | |||
2222 | 138 | """ | ||
2223 | 139 | def get_children(pid): | ||
2224 | 140 | command = ['ps', '-o', 'pid', '--ppid', str(pid), '--noheaders'] | ||
2225 | 141 | try: | ||
2226 | 142 | raw_output = subprocess.check_output(command) | ||
2227 | 143 | except subprocess.CalledProcessError: | ||
2228 | 144 | return [] | ||
2229 | 145 | return [int(p) for p in raw_output.split()] | ||
2230 | 146 | |||
2231 | 147 | result = [pid] | ||
2232 | 148 | data = get_children(pid) | ||
2233 | 149 | while data: | ||
2234 | 150 | pid = data.pop(0) | ||
2235 | 151 | result.append(pid) | ||
2236 | 152 | data.extend(get_children(pid)) | ||
2237 | 153 | |||
2238 | 154 | return result | ||
2239 | 155 | |||
2240 | 156 | |||
2241 | 157 | def get_autopilot_proxy_object_for_process(process): | 127 | def get_autopilot_proxy_object_for_process(process): |
2242 | 158 | """Return the autopilot proxy object for the given *process*. | 128 | """Return the autopilot proxy object for the given *process*. |
2243 | 159 | 129 | ||
2244 | @@ -199,6 +169,28 @@ | |||
2245 | 199 | raise RuntimeError("Unable to find Autopilot interface.") | 169 | raise RuntimeError("Unable to find Autopilot interface.") |
2246 | 200 | 170 | ||
2247 | 201 | 171 | ||
2248 | 172 | def get_child_pids(pid): | ||
2249 | 173 | """Get a list of all child process Ids, for the given parent. | ||
2250 | 174 | |||
2251 | 175 | """ | ||
2252 | 176 | def get_children(pid): | ||
2253 | 177 | command = ['ps', '-o', 'pid', '--ppid', str(pid), '--noheaders'] | ||
2254 | 178 | try: | ||
2255 | 179 | raw_output = subprocess.check_output(command) | ||
2256 | 180 | except subprocess.CalledProcessError: | ||
2257 | 181 | return [] | ||
2258 | 182 | return [int(p) for p in raw_output.split()] | ||
2259 | 183 | |||
2260 | 184 | result = [pid] | ||
2261 | 185 | data = get_children(pid) | ||
2262 | 186 | while data: | ||
2263 | 187 | pid = data.pop(0) | ||
2264 | 188 | result.append(pid) | ||
2265 | 189 | data.extend(get_children(pid)) | ||
2266 | 190 | |||
2267 | 191 | return result | ||
2268 | 192 | |||
2269 | 193 | |||
2270 | 202 | def make_proxy_object_from_service_name(service_name, obj_path): | 194 | def make_proxy_object_from_service_name(service_name, obj_path): |
2271 | 203 | """Returns a root proxy object given a DBus service name.""" | 195 | """Returns a root proxy object given a DBus service name.""" |
2272 | 204 | # parameters can sometimes be dbus.String instances, sometimes QString instances. | 196 | # parameters can sometimes be dbus.String instances, sometimes QString instances. |
2273 | 205 | 197 | ||
2274 | === modified file 'autopilot/introspection/dbus.py' | |||
2275 | --- autopilot/introspection/dbus.py 2013-02-20 04:00:40 +0000 | |||
2276 | +++ autopilot/introspection/dbus.py 2013-04-15 21:43:32 +0000 | |||
2277 | @@ -23,7 +23,7 @@ | |||
2278 | 23 | from time import sleep | 23 | from time import sleep |
2279 | 24 | from textwrap import dedent | 24 | from textwrap import dedent |
2280 | 25 | 25 | ||
2282 | 26 | from autopilot.emulators.dbus_handler import get_session_bus | 26 | from autopilot.dbus_handler import get_session_bus |
2283 | 27 | from autopilot.introspection.constants import AP_INTROSPECTION_IFACE | 27 | from autopilot.introspection.constants import AP_INTROSPECTION_IFACE |
2284 | 28 | from autopilot.utilities import Timer | 28 | from autopilot.utilities import Timer |
2285 | 29 | 29 | ||
2286 | 30 | 30 | ||
2287 | === modified file 'autopilot/introspection/gtk.py' | |||
2288 | --- autopilot/introspection/gtk.py 2013-01-25 01:47:48 +0000 | |||
2289 | +++ autopilot/introspection/gtk.py 2013-04-15 21:43:32 +0000 | |||
2290 | @@ -8,10 +8,10 @@ | |||
2291 | 8 | 8 | ||
2292 | 9 | import os | 9 | import os |
2293 | 10 | 10 | ||
2298 | 11 | from autopilot.introspection import ApplicationIntrospectionTestMixin | 11 | from autopilot.introspection import ApplicationLauncher |
2299 | 12 | 12 | ||
2300 | 13 | 13 | ||
2301 | 14 | class GtkIntrospectionTestMixin(ApplicationIntrospectionTestMixin): | 14 | class GtkApplicationLauncher(ApplicationLauncher): |
2302 | 15 | """A mix-in class to make Gtk application introspection easier.""" | 15 | """A mix-in class to make Gtk application introspection easier.""" |
2303 | 16 | 16 | ||
2304 | 17 | def prepare_environment(self, app_path, arguments): | 17 | def prepare_environment(self, app_path, arguments): |
2305 | 18 | 18 | ||
2306 | === modified file 'autopilot/introspection/qt.py' | |||
2307 | --- autopilot/introspection/qt.py 2013-03-14 21:37:17 +0000 | |||
2308 | +++ autopilot/introspection/qt.py 2013-04-15 21:43:32 +0000 | |||
2309 | @@ -10,14 +10,14 @@ | |||
2310 | 10 | """Classes and tools to support Qt introspection.""" | 10 | """Classes and tools to support Qt introspection.""" |
2311 | 11 | 11 | ||
2312 | 12 | 12 | ||
2314 | 13 | __all__ = ['QtIntrospectionTestMixin'] | 13 | __all__ = ['QtApplicationLauncher'] |
2315 | 14 | 14 | ||
2316 | 15 | import dbus | 15 | import dbus |
2317 | 16 | import functools | 16 | import functools |
2318 | 17 | 17 | ||
2319 | 18 | import logging | 18 | import logging |
2320 | 19 | 19 | ||
2322 | 20 | from autopilot.introspection import ApplicationIntrospectionTestMixin | 20 | from autopilot.introspection import ApplicationLauncher |
2323 | 21 | from autopilot.introspection.constants import QT_AUTOPILOT_IFACE | 21 | from autopilot.introspection.constants import QT_AUTOPILOT_IFACE |
2324 | 22 | from autopilot.introspection.dbus import get_session_bus | 22 | from autopilot.introspection.dbus import get_session_bus |
2325 | 23 | 23 | ||
2326 | @@ -25,7 +25,7 @@ | |||
2327 | 25 | logger = logging.getLogger(__name__) | 25 | logger = logging.getLogger(__name__) |
2328 | 26 | 26 | ||
2329 | 27 | 27 | ||
2331 | 28 | class QtIntrospectionTestMixin(ApplicationIntrospectionTestMixin): | 28 | class QtApplicationLauncher(ApplicationLauncher): |
2332 | 29 | """A mix-in class to make Qt application introspection easier. | 29 | """A mix-in class to make Qt application introspection easier. |
2333 | 30 | 30 | ||
2334 | 31 | Inherit from this class if you want to launch and test Qt application with | 31 | Inherit from this class if you want to launch and test Qt application with |
2335 | 32 | 32 | ||
2336 | === modified file 'autopilot/keybindings.py' | |||
2337 | --- autopilot/keybindings.py 2013-02-28 00:26:07 +0000 | |||
2338 | +++ autopilot/keybindings.py 2013-04-15 21:43:32 +0000 | |||
2339 | @@ -27,8 +27,8 @@ | |||
2340 | 27 | from types import NoneType | 27 | from types import NoneType |
2341 | 28 | import re | 28 | import re |
2342 | 29 | 29 | ||
2345 | 30 | from autopilot.emulators.input import get_keyboard | 30 | from autopilot.input import Keyboard |
2346 | 31 | from autopilot.compizconfig import get_plugin, get_setting | 31 | from autopilot.utilities import Silence |
2347 | 32 | 32 | ||
2348 | 33 | logger = logging.getLogger(__name__) | 33 | logger = logging.getLogger(__name__) |
2349 | 34 | 34 | ||
2350 | @@ -184,8 +184,8 @@ | |||
2351 | 184 | 184 | ||
2352 | 185 | """ | 185 | """ |
2353 | 186 | plugin_name, setting_name = compiz_tuple | 186 | plugin_name, setting_name = compiz_tuple |
2356 | 187 | plugin = get_plugin(plugin_name) | 187 | plugin = _get_compiz_plugin(plugin_name) |
2357 | 188 | setting = get_setting(plugin_name, setting_name) | 188 | setting = _get_compiz_setting(plugin_name, setting_name) |
2358 | 189 | if setting.Type != 'Key': | 189 | if setting.Type != 'Key': |
2359 | 190 | raise ValueError("Key binding maps to a compiz option that does not hold a keybinding.") | 190 | raise ValueError("Key binding maps to a compiz option that does not hold a keybinding.") |
2360 | 191 | if not plugin.Enabled: | 191 | if not plugin.Enabled: |
2361 | @@ -232,7 +232,7 @@ | |||
2362 | 232 | 232 | ||
2363 | 233 | @property | 233 | @property |
2364 | 234 | def _keyboard(self): | 234 | def _keyboard(self): |
2366 | 235 | return get_keyboard() | 235 | return Keyboard.create() |
2367 | 236 | 236 | ||
2368 | 237 | def keybinding(self, binding_name, delay=None): | 237 | def keybinding(self, binding_name, delay=None): |
2369 | 238 | """Press and release the keybinding with the given name. | 238 | """Press and release the keybinding with the given name. |
2370 | @@ -263,3 +263,48 @@ | |||
2371 | 263 | def keybinding_hold_part_then_tap(self, binding_name): | 263 | def keybinding_hold_part_then_tap(self, binding_name): |
2372 | 264 | self.keybinding_hold(binding_name) | 264 | self.keybinding_hold(binding_name) |
2373 | 265 | self.keybinding_tap(binding_name) | 265 | self.keybinding_tap(binding_name) |
2374 | 266 | |||
2375 | 267 | |||
2376 | 268 | # Functions that wrap compizconfig to avoid some unpleasantness in that module. | ||
2377 | 269 | # Local to the this keybindings for now until their removal in the very near | ||
2378 | 270 | # future. | ||
2379 | 271 | _global_compiz_context = None | ||
2380 | 272 | |||
2381 | 273 | def _get_global_compiz_context(): | ||
2382 | 274 | """Get the compizconfig global context object.""" | ||
2383 | 275 | global _global_compiz_context | ||
2384 | 276 | if _global_compiz_context is None: | ||
2385 | 277 | with Silence(): | ||
2386 | 278 | from compizconfig import Context | ||
2387 | 279 | _global_compiz_context = Context() | ||
2388 | 280 | return _global_compiz_context | ||
2389 | 281 | |||
2390 | 282 | |||
2391 | 283 | def _get_compiz_plugin(plugin_name): | ||
2392 | 284 | """Get a compizconfig plugin with the specified name. | ||
2393 | 285 | |||
2394 | 286 | Raises KeyError of the plugin named does not exist. | ||
2395 | 287 | |||
2396 | 288 | """ | ||
2397 | 289 | ctx = _get_global_compiz_context() | ||
2398 | 290 | with Silence(): | ||
2399 | 291 | try: | ||
2400 | 292 | return ctx.Plugins[plugin_name] | ||
2401 | 293 | except KeyError: | ||
2402 | 294 | raise KeyError("Compiz plugin '%s' does not exist." % (plugin_name)) | ||
2403 | 295 | |||
2404 | 296 | |||
2405 | 297 | def _get_compiz_setting(plugin_name, setting_name): | ||
2406 | 298 | """Get a compizconfig setting object, given a plugin name and setting name. | ||
2407 | 299 | |||
2408 | 300 | Raises KeyError if the plugin or setting is not found. | ||
2409 | 301 | |||
2410 | 302 | """ | ||
2411 | 303 | plugin = _get_compiz_plugin(plugin_name) | ||
2412 | 304 | with Silence(): | ||
2413 | 305 | try: | ||
2414 | 306 | return plugin.Screen[setting_name] | ||
2415 | 307 | except KeyError: | ||
2416 | 308 | raise KeyError("Compiz setting '%s' does not exist in plugin '%s'." % (setting_name, plugin_name)) | ||
2417 | 309 | |||
2418 | 310 | |||
2419 | 266 | 311 | ||
2420 | === modified file 'autopilot/matchers/__init__.py' | |||
2421 | --- autopilot/matchers/__init__.py 2012-12-05 02:15:45 +0000 | |||
2422 | +++ autopilot/matchers/__init__.py 2013-04-15 21:43:32 +0000 | |||
2423 | @@ -18,9 +18,54 @@ | |||
2424 | 18 | class Eventually(Matcher): | 18 | class Eventually(Matcher): |
2425 | 19 | """Asserts that a value will eventually equal a given Matcher object. | 19 | """Asserts that a value will eventually equal a given Matcher object. |
2426 | 20 | 20 | ||
2430 | 21 | This works on objects that *either* have a :meth:`wait_for(expected)` | 21 | This matcher wraps another testtools matcher object. It makes that other |
2431 | 22 | function, *or* objects that are callable and return the most current value | 22 | matcher work with a timeout. This is necessary for several reasons: |
2432 | 23 | (i.e.- they refresh the objects value). | 23 | |
2433 | 24 | 1. Since most actions in a GUI applicaton take some time to complete, the | ||
2434 | 25 | test may need to wait for the application to enter the expected state. | ||
2435 | 26 | |||
2436 | 27 | 2. Since the test is running in a separate process to the application under | ||
2437 | 28 | test, test authors cannot make any assumptions about when the application | ||
2438 | 29 | under test will recieve CPU time to update to the expected state. | ||
2439 | 30 | |||
2440 | 31 | There are two main ways of using the Eventually matcher: | ||
2441 | 32 | |||
2442 | 33 | **Attributes from the application**:: | ||
2443 | 34 | |||
2444 | 35 | self.assertThat(window.maximized, Eventually(Equals(True))) | ||
2445 | 36 | |||
2446 | 37 | Here, ``window`` is an object generated by autopilot from the applications | ||
2447 | 38 | state. This pattern of usage will cover 90% (or more) of the assertions in | ||
2448 | 39 | an autopilot test. Note that any matcher can be used - either from testtools | ||
2449 | 40 | or any custom matcher that implements the matcher API:: | ||
2450 | 41 | |||
2451 | 42 | self.assertThat(window.height, Eventually(GreaterThan(200))) | ||
2452 | 43 | |||
2453 | 44 | **Callable Objects**:: | ||
2454 | 45 | |||
2455 | 46 | self.assertThat(autopilot.platform.model, Eventually(Equals("Galaxy Nexus"))) | ||
2456 | 47 | |||
2457 | 48 | In this example we're using the :func:`autopilot.platform.model` function as | ||
2458 | 49 | a callable. In this form, Eventually matches against the return value of the | ||
2459 | 50 | callable. | ||
2460 | 51 | |||
2461 | 52 | This can also be used to use a regular python property inside an Eventually | ||
2462 | 53 | matcher:: | ||
2463 | 54 | |||
2464 | 55 | self.assertThat(lambda: self.mouse.x, Eventually(LessThan(10))) | ||
2465 | 56 | |||
2466 | 57 | .. note:: Using this form generally makes your tests less readabvle, and | ||
2467 | 58 | should be used with great care. It also relies the test author to have | ||
2468 | 59 | knowledge about the implementation of the object being matched against. | ||
2469 | 60 | In this example, if ``self.mouse.x`` were ever to change to be a regular | ||
2470 | 61 | python attribute, this test would likely break. | ||
2471 | 62 | |||
2472 | 63 | **Timeout** | ||
2473 | 64 | |||
2474 | 65 | By default timeout period is ten seconds. This can be altered by passing the | ||
2475 | 66 | timeout keyword:: | ||
2476 | 67 | |||
2477 | 68 | self.assertThat(foo.bar, Eventually(Equals(123), timeout=30)) | ||
2478 | 24 | 69 | ||
2479 | 25 | """ | 70 | """ |
2480 | 26 | 71 | ||
2481 | 27 | 72 | ||
2482 | === added file 'autopilot/platform.py' | |||
2483 | --- autopilot/platform.py 1970-01-01 00:00:00 +0000 | |||
2484 | +++ autopilot/platform.py 2013-04-15 21:43:32 +0000 | |||
2485 | @@ -0,0 +1,105 @@ | |||
2486 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
2487 | 2 | # Copyright 2013 Canonical | ||
2488 | 3 | # Author: Thomi Richards | ||
2489 | 4 | # | ||
2490 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
2491 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
2492 | 7 | # by the Free Software Foundation. | ||
2493 | 8 | |||
2494 | 9 | """ | ||
2495 | 10 | Platform identification utilities for Autopilot. | ||
2496 | 11 | ================================================ | ||
2497 | 12 | |||
2498 | 13 | This module provides functions that give test authors hints as to which platform | ||
2499 | 14 | their tests are currently running on. This is useful when tests should only run | ||
2500 | 15 | on certain platforms. | ||
2501 | 16 | |||
2502 | 17 | """ | ||
2503 | 18 | |||
2504 | 19 | from os.path import exists | ||
2505 | 20 | |||
2506 | 21 | |||
2507 | 22 | def model(): | ||
2508 | 23 | """Get the model name of the current platform. | ||
2509 | 24 | |||
2510 | 25 | For desktop / laptop installations, this will return "Desktop". | ||
2511 | 26 | Otherwise, the current hardware model will be returned. For example: | ||
2512 | 27 | |||
2513 | 28 | >>> autopilot.platform.model() | ||
2514 | 29 | ... "Galaxy Nexus" | ||
2515 | 30 | |||
2516 | 31 | """ | ||
2517 | 32 | return _PlatformDetector.create().model | ||
2518 | 33 | |||
2519 | 34 | |||
2520 | 35 | def image_codename(): | ||
2521 | 36 | """Get the image codename. | ||
2522 | 37 | |||
2523 | 38 | For desktop / laptop installations this will return "Desktop". | ||
2524 | 39 | Otherwise, the codename of the image that was installed will be | ||
2525 | 40 | returned. For example: | ||
2526 | 41 | |||
2527 | 42 | >>> autopilot.platform.image_codename() | ||
2528 | 43 | ... "maguro" | ||
2529 | 44 | |||
2530 | 45 | """ | ||
2531 | 46 | return _PlatformDetector.create().image_codename | ||
2532 | 47 | |||
2533 | 48 | |||
2534 | 49 | class _PlatformDetector(object): | ||
2535 | 50 | |||
2536 | 51 | _cached_detector = None | ||
2537 | 52 | |||
2538 | 53 | @staticmethod | ||
2539 | 54 | def create(): | ||
2540 | 55 | """Create a platform detector object, or return one we baked earlier.""" | ||
2541 | 56 | if _PlatformDetector._cached_detector is None: | ||
2542 | 57 | _PlatformDetector._cached_detector = _PlatformDetector() | ||
2543 | 58 | return _PlatformDetector._cached_detector | ||
2544 | 59 | |||
2545 | 60 | def __init__(self): | ||
2546 | 61 | self.model = "Desktop" | ||
2547 | 62 | self.image_codename = "Desktop" | ||
2548 | 63 | |||
2549 | 64 | property_file = _get_property_file() | ||
2550 | 65 | if property_file is not None: | ||
2551 | 66 | self.update_values_from_build_file(property_file) | ||
2552 | 67 | |||
2553 | 68 | def update_values_from_build_file(self, property_file): | ||
2554 | 69 | """Read build.prop file and parse it.""" | ||
2555 | 70 | properties = _parse_build_properties_file(property_file) | ||
2556 | 71 | self.model = properties.get('ro.product.model', "Desktop") | ||
2557 | 72 | self.image_codename = properties.get('ro.product.name', "Desktop") | ||
2558 | 73 | |||
2559 | 74 | |||
2560 | 75 | def _get_property_file(): | ||
2561 | 76 | """Return a file-like object that contains the contents of the build properties | ||
2562 | 77 | file, if it exists, or None. | ||
2563 | 78 | |||
2564 | 79 | """ | ||
2565 | 80 | if exists('/system/build.prop'): | ||
2566 | 81 | return open('/system/build.prop') | ||
2567 | 82 | return None | ||
2568 | 83 | |||
2569 | 84 | |||
2570 | 85 | def _parse_build_properties_file(property_file): | ||
2571 | 86 | """Parse 'property_file', which must be a file-like object containing the | ||
2572 | 87 | system build properties. | ||
2573 | 88 | |||
2574 | 89 | Returns a dictionary of key,value pairs. | ||
2575 | 90 | |||
2576 | 91 | """ | ||
2577 | 92 | properties = {} | ||
2578 | 93 | for line in property_file: | ||
2579 | 94 | line = line.strip() | ||
2580 | 95 | if not line or line.startswith('#') or line.isspace(): | ||
2581 | 96 | continue | ||
2582 | 97 | split_location = line.find('=') | ||
2583 | 98 | if split_location == -1: | ||
2584 | 99 | continue | ||
2585 | 100 | key = line[:split_location] | ||
2586 | 101 | value = line[split_location + 1:] | ||
2587 | 102 | |||
2588 | 103 | properties[key] = value | ||
2589 | 104 | return properties | ||
2590 | 105 | |||
2591 | 0 | 106 | ||
2592 | === added directory 'autopilot/process' | |||
2593 | === added file 'autopilot/process/__init__.py' | |||
2594 | --- autopilot/process/__init__.py 1970-01-01 00:00:00 +0000 | |||
2595 | +++ autopilot/process/__init__.py 2013-04-15 21:43:32 +0000 | |||
2596 | @@ -0,0 +1,403 @@ | |||
2597 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
2598 | 2 | # Copyright 2013 Canonical | ||
2599 | 3 | # Author: Christopher Lee | ||
2600 | 4 | # | ||
2601 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
2602 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
2603 | 7 | # by the Free Software Foundation. | ||
2604 | 8 | |||
2605 | 9 | from collections import OrderedDict | ||
2606 | 10 | |||
2607 | 11 | from autopilot.utilities import _pick_variant | ||
2608 | 12 | |||
2609 | 13 | |||
2610 | 14 | class ProcessManager(object): | ||
2611 | 15 | |||
2612 | 16 | """A simple process manager class. | ||
2613 | 17 | |||
2614 | 18 | The process manager is used to handle processes, windows and applications. | ||
2615 | 19 | This class should not be instantiated directly however. To get an instance | ||
2616 | 20 | of the keyboard class, call :py:meth:`create` instead. | ||
2617 | 21 | |||
2618 | 22 | """ | ||
2619 | 23 | |||
2620 | 24 | KNOWN_APPS = { | ||
2621 | 25 | 'Character Map' : { | ||
2622 | 26 | 'desktop-file': 'gucharmap.desktop', | ||
2623 | 27 | 'process-name': 'gucharmap', | ||
2624 | 28 | }, | ||
2625 | 29 | 'Calculator' : { | ||
2626 | 30 | 'desktop-file': 'gcalctool.desktop', | ||
2627 | 31 | 'process-name': 'gnome-calculator', | ||
2628 | 32 | }, | ||
2629 | 33 | 'Mahjongg' : { | ||
2630 | 34 | 'desktop-file': 'mahjongg.desktop', | ||
2631 | 35 | 'process-name': 'gnome-mahjongg', | ||
2632 | 36 | }, | ||
2633 | 37 | 'Remmina' : { | ||
2634 | 38 | 'desktop-file': 'remmina.desktop', | ||
2635 | 39 | 'process-name': 'remmina', | ||
2636 | 40 | }, | ||
2637 | 41 | 'System Settings' : { | ||
2638 | 42 | 'desktop-file': 'gnome-control-center.desktop', | ||
2639 | 43 | 'process-name': 'gnome-control-center', | ||
2640 | 44 | }, | ||
2641 | 45 | 'Text Editor' : { | ||
2642 | 46 | 'desktop-file': 'gedit.desktop', | ||
2643 | 47 | 'process-name': 'gedit', | ||
2644 | 48 | }, | ||
2645 | 49 | 'Terminal' : { | ||
2646 | 50 | 'desktop-file': 'gnome-terminal.desktop', | ||
2647 | 51 | 'process-name': 'gnome-terminal', | ||
2648 | 52 | }, | ||
2649 | 53 | } | ||
2650 | 54 | |||
2651 | 55 | |||
2652 | 56 | @staticmethod | ||
2653 | 57 | def create(preferred_variant=""): | ||
2654 | 58 | """Get an instance of the :py:class:`ProcessManager` class. | ||
2655 | 59 | |||
2656 | 60 | :param preferred_variant: A string containing a hint as to which variant you | ||
2657 | 61 | would like. However, this hint can be ignored - autopilot will prefer to | ||
2658 | 62 | return a keyboard variant other than the one requested, rather than fail | ||
2659 | 63 | to return anything at all. | ||
2660 | 64 | :raises: a RuntimeError will be raised if autopilot cannot instantate any of | ||
2661 | 65 | the possible backends. | ||
2662 | 66 | """ | ||
2663 | 67 | def get_bamf_pm(): | ||
2664 | 68 | from autopilot.process._bamf import ProcessManager | ||
2665 | 69 | return ProcessManager() | ||
2666 | 70 | |||
2667 | 71 | def get_upa_pm(): | ||
2668 | 72 | from autopilot.process._upa import ProcessManager | ||
2669 | 73 | return ProcessManager() | ||
2670 | 74 | |||
2671 | 75 | variants = OrderedDict() | ||
2672 | 76 | variants['BAMF'] = get_bamf_pm | ||
2673 | 77 | return _pick_variant(variants, preferred_variant) | ||
2674 | 78 | |||
2675 | 79 | @classmethod | ||
2676 | 80 | def register_known_application(cls, name, desktop_file, process_name): | ||
2677 | 81 | """Register an application with autopilot. | ||
2678 | 82 | |||
2679 | 83 | After calling this method, you may call :meth:`start_app` or | ||
2680 | 84 | :meth:`start_app_window` with the `name` parameter to start this | ||
2681 | 85 | application. | ||
2682 | 86 | You need only call this once within a test run - the application will | ||
2683 | 87 | remain registerred until the test run ends. | ||
2684 | 88 | |||
2685 | 89 | :param name: The name to be used when launching the application. | ||
2686 | 90 | :param desktop_file: The filename (without path component) of the desktop file used to launch the application. | ||
2687 | 91 | :param process_name: The name of the executable process that gets run. | ||
2688 | 92 | :raises: **KeyError** if application has been registered already | ||
2689 | 93 | |||
2690 | 94 | """ | ||
2691 | 95 | if name in cls.KNOWN_APPS: | ||
2692 | 96 | raise KeyError("Application has been registered already") | ||
2693 | 97 | else: | ||
2694 | 98 | cls.KNOWN_APPS[name] = { | ||
2695 | 99 | "desktop-file" : desktop_file, | ||
2696 | 100 | "process-name" : process_name | ||
2697 | 101 | } | ||
2698 | 102 | |||
2699 | 103 | @classmethod | ||
2700 | 104 | def unregister_known_application(cls, name): | ||
2701 | 105 | """Unregister an application with the known_apps dictionary. | ||
2702 | 106 | |||
2703 | 107 | :param name: The name to be used when launching the application. | ||
2704 | 108 | :raises: **KeyError** if the application has not been registered. | ||
2705 | 109 | |||
2706 | 110 | """ | ||
2707 | 111 | if name in cls.KNOWN_APPS: | ||
2708 | 112 | del cls.KNOWN_APPS[name] | ||
2709 | 113 | else: | ||
2710 | 114 | raise KeyError("Application has not been registered") | ||
2711 | 115 | |||
2712 | 116 | def start_app(self, app_name, files=[], locale=None): | ||
2713 | 117 | """Start one of the known applications, and kill it on tear down. | ||
2714 | 118 | |||
2715 | 119 | .. warning:: This method will clear all instances of this application on | ||
2716 | 120 | tearDown, not just the one opened by this method! We recommend that | ||
2717 | 121 | you use the :meth:`start_app_window` method instead, as it is generally | ||
2718 | 122 | safer. | ||
2719 | 123 | |||
2720 | 124 | :param app_name: The application name. *This name must either already | ||
2721 | 125 | be registered as one of the built-in applications that are supported | ||
2722 | 126 | by autopilot, or must have been registered using* | ||
2723 | 127 | :meth:`register_known_application` *beforehand.* | ||
2724 | 128 | :param files: (Optional) A list of paths to open with the | ||
2725 | 129 | given application. *Not all applications support opening files in this | ||
2726 | 130 | way.* | ||
2727 | 131 | :param locale: (Optional) The locale will to set when the application | ||
2728 | 132 | is launched. *If you want to launch an application without any | ||
2729 | 133 | localisation being applied, set this parameter to 'C'.* | ||
2730 | 134 | :returns: A :class:`~autopilot.process.Application` instance. | ||
2731 | 135 | |||
2732 | 136 | """ | ||
2733 | 137 | raise NotImplementedError("You cannot use this class directly.") | ||
2734 | 138 | |||
2735 | 139 | def start_app_window(self, app_name, files=[], locale=None): | ||
2736 | 140 | """Open a single window for one of the known applications, and close it | ||
2737 | 141 | at the end of the test. | ||
2738 | 142 | |||
2739 | 143 | :param app_name: The application name. *This name must either already | ||
2740 | 144 | be registered as one of the built-in applications that are supported | ||
2741 | 145 | by autopilot, or must have been registered with* | ||
2742 | 146 | :meth:`register_known_application` *beforehand.* | ||
2743 | 147 | :param files: (Optional) Should be a list of paths to open with the | ||
2744 | 148 | given application. *Not all applications support opening files in this | ||
2745 | 149 | way.* | ||
2746 | 150 | :param locale: (Optional) The locale will to set when the application | ||
2747 | 151 | is launched. *If you want to launch an application without any | ||
2748 | 152 | localisation being applied, set this parameter to 'C'.* | ||
2749 | 153 | :raises: **AssertionError** if no window was opened, or more than one | ||
2750 | 154 | window was opened. | ||
2751 | 155 | :returns: A :class:`~autopilot.process.Window` instance. | ||
2752 | 156 | |||
2753 | 157 | """ | ||
2754 | 158 | raise NotImplementedError("You cannot use this class directly.") | ||
2755 | 159 | |||
2756 | 160 | def get_open_windows_by_application(self, app_name): | ||
2757 | 161 | """Get a list of ~autopilot.process.Window` instances | ||
2758 | 162 | for the given application name. | ||
2759 | 163 | |||
2760 | 164 | :param app_name: The name of one of the well-known applications. | ||
2761 | 165 | :returns: A list of :class:`~autopilot.process.Window` | ||
2762 | 166 | instances. | ||
2763 | 167 | |||
2764 | 168 | """ | ||
2765 | 169 | raise NotImplementedError("You cannot use this class directly.") | ||
2766 | 170 | |||
2767 | 171 | def close_all_app(self, app_name): | ||
2768 | 172 | raise NotImplementedError("You cannot use this class directly.") | ||
2769 | 173 | |||
2770 | 174 | def get_app_instances(self, app_name): | ||
2771 | 175 | raise NotImplementedError("You cannot use this class directly.") | ||
2772 | 176 | |||
2773 | 177 | def app_is_running(self, app_name): | ||
2774 | 178 | raise NotImplementedError("You cannot use this class directly.") | ||
2775 | 179 | |||
2776 | 180 | def get_running_applications(self, user_visible_only=True): | ||
2777 | 181 | """Get a list of the currently running applications. | ||
2778 | 182 | |||
2779 | 183 | If user_visible_only is True (the default), only applications | ||
2780 | 184 | visible to the user in the switcher will be returned. | ||
2781 | 185 | |||
2782 | 186 | """ | ||
2783 | 187 | raise NotImplementedError("You cannot use this class directly.") | ||
2784 | 188 | |||
2785 | 189 | def get_running_applications_by_desktop_file(self, desktop_file): | ||
2786 | 190 | """Return a list of applications that have the desktop file *desktop_file*. | ||
2787 | 191 | |||
2788 | 192 | This method will return an empty list if no applications | ||
2789 | 193 | are found with the specified desktop file. | ||
2790 | 194 | |||
2791 | 195 | """ | ||
2792 | 196 | raise NotImplementedError("You cannot use this class directly.") | ||
2793 | 197 | |||
2794 | 198 | def get_open_windows(self, user_visible_only=True): | ||
2795 | 199 | """Get a list of currently open windows. | ||
2796 | 200 | |||
2797 | 201 | If *user_visible_only* is True (the default), only applications visible | ||
2798 | 202 | to the user in the switcher will be returned. | ||
2799 | 203 | |||
2800 | 204 | The result is sorted to be in stacking order. | ||
2801 | 205 | |||
2802 | 206 | """ | ||
2803 | 207 | raise NotImplementedError("You cannot use this class directly.") | ||
2804 | 208 | |||
2805 | 209 | def wait_until_application_is_running(self, desktop_file, timeout): | ||
2806 | 210 | """Wait until a given application is running. | ||
2807 | 211 | |||
2808 | 212 | :param string desktop_file: The name of the application desktop file. | ||
2809 | 213 | :param integer timeout: The maximum time to wait, in seconds. *If set to | ||
2810 | 214 | something less than 0, this method will wait forever.* | ||
2811 | 215 | |||
2812 | 216 | :return: true once the application is found, or false if the application | ||
2813 | 217 | was not found until the timeout was reached. | ||
2814 | 218 | """ | ||
2815 | 219 | raise NotImplementedError("You cannot use this class directly.") | ||
2816 | 220 | |||
2817 | 221 | def launch_application(self, desktop_file, files=[], wait=True): | ||
2818 | 222 | """Launch an application by specifying a desktop file. | ||
2819 | 223 | |||
2820 | 224 | :param files: List of files to pass to the application. *Not all | ||
2821 | 225 | apps support this.* | ||
2822 | 226 | :type files: List of strings | ||
2823 | 227 | |||
2824 | 228 | .. note:: If `wait` is True, this method will wait up to 10 seconds for | ||
2825 | 229 | the application to appear. | ||
2826 | 230 | |||
2827 | 231 | :raises: **TypeError** on invalid *files* parameter. | ||
2828 | 232 | :return: The Gobject process object. | ||
2829 | 233 | """ | ||
2830 | 234 | raise NotImplementedError("You cannot use this class directly.") | ||
2831 | 235 | |||
2832 | 236 | |||
2833 | 237 | class Application(object): | ||
2834 | 238 | @property | ||
2835 | 239 | def desktop_file(self): | ||
2836 | 240 | """Get the application desktop file. | ||
2837 | 241 | |||
2838 | 242 | This returns just the filename, not the full path. | ||
2839 | 243 | If the application no longer exists, this returns an empty string. | ||
2840 | 244 | """ | ||
2841 | 245 | raise NotImplementedError("You cannot use this class directly.") | ||
2842 | 246 | |||
2843 | 247 | @property | ||
2844 | 248 | def name(self): | ||
2845 | 249 | """Get the application name. | ||
2846 | 250 | |||
2847 | 251 | .. note:: This may change according to the current locale. If you want a | ||
2848 | 252 | unique string to match applications against, use desktop_file instead. | ||
2849 | 253 | |||
2850 | 254 | """ | ||
2851 | 255 | raise NotImplementedError("You cannot use this class directly.") | ||
2852 | 256 | |||
2853 | 257 | @property | ||
2854 | 258 | def icon(self): | ||
2855 | 259 | """Get the application icon. | ||
2856 | 260 | |||
2857 | 261 | :return: The name of the icon. | ||
2858 | 262 | |||
2859 | 263 | """ | ||
2860 | 264 | raise NotImplementedError("You cannot use this class directly.") | ||
2861 | 265 | |||
2862 | 266 | @property | ||
2863 | 267 | def is_active(self): | ||
2864 | 268 | """Is the application active (i.e. has keyboard focus)?""" | ||
2865 | 269 | raise NotImplementedError("You cannot use this class directly.") | ||
2866 | 270 | |||
2867 | 271 | @property | ||
2868 | 272 | def is_urgent(self): | ||
2869 | 273 | """Is the application currently signalling urgency?""" | ||
2870 | 274 | raise NotImplementedError("You cannot use this class directly.") | ||
2871 | 275 | |||
2872 | 276 | @property | ||
2873 | 277 | def user_visible(self): | ||
2874 | 278 | """Is this application visible to the user? | ||
2875 | 279 | |||
2876 | 280 | .. note:: Some applications (such as the panel) are hidden to the user | ||
2877 | 281 | but may still be returned. | ||
2878 | 282 | |||
2879 | 283 | """ | ||
2880 | 284 | raise NotImplementedError("You cannot use this class directly.") | ||
2881 | 285 | |||
2882 | 286 | def get_windows(self): | ||
2883 | 287 | """Get a list of the application windows.""" | ||
2884 | 288 | raise NotImplementedError("You cannot use this class directly.") | ||
2885 | 289 | |||
2886 | 290 | |||
2887 | 291 | |||
2888 | 292 | class Window(object): | ||
2889 | 293 | @property | ||
2890 | 294 | def x_id(self): | ||
2891 | 295 | """Get the X11 Window Id.""" | ||
2892 | 296 | raise NotImplementedError("You cannot use this class directly.") | ||
2893 | 297 | |||
2894 | 298 | @property | ||
2895 | 299 | def x_win(self): | ||
2896 | 300 | """Get the X11 window object of the underlying window.""" | ||
2897 | 301 | raise NotImplementedError("You cannot use this class directly.") | ||
2898 | 302 | |||
2899 | 303 | @property | ||
2900 | 304 | def get_wm_state(self): | ||
2901 | 305 | """Get the state of the underlying window.""" | ||
2902 | 306 | raise NotImplementedError("You cannot use this class directly.") | ||
2903 | 307 | |||
2904 | 308 | @property | ||
2905 | 309 | def name(self): | ||
2906 | 310 | """Get the window name. | ||
2907 | 311 | |||
2908 | 312 | .. note:: This may change according to the current locale. If you want a | ||
2909 | 313 | unique string to match windows against, use the x_id instead. | ||
2910 | 314 | |||
2911 | 315 | """ | ||
2912 | 316 | raise NotImplementedError("You cannot use this class directly.") | ||
2913 | 317 | |||
2914 | 318 | @property | ||
2915 | 319 | def title(self): | ||
2916 | 320 | """Get the window title. | ||
2917 | 321 | |||
2918 | 322 | This may be different from the application name. | ||
2919 | 323 | |||
2920 | 324 | .. note:: This may change depending on the current locale. | ||
2921 | 325 | |||
2922 | 326 | """ | ||
2923 | 327 | raise NotImplementedError("You cannot use this class directly.") | ||
2924 | 328 | |||
2925 | 329 | @property | ||
2926 | 330 | def geometry(self): | ||
2927 | 331 | """Get the geometry for this window. | ||
2928 | 332 | |||
2929 | 333 | :return: Tuple containing (x, y, width, height). | ||
2930 | 334 | |||
2931 | 335 | """ | ||
2932 | 336 | raise NotImplementedError("You cannot use this class directly.") | ||
2933 | 337 | |||
2934 | 338 | @property | ||
2935 | 339 | def is_maximized(self): | ||
2936 | 340 | """Is the window maximized? | ||
2937 | 341 | |||
2938 | 342 | Maximized in this case means both maximized vertically and | ||
2939 | 343 | horizontally. If a window is only maximized in one direction it is not | ||
2940 | 344 | considered maximized. | ||
2941 | 345 | |||
2942 | 346 | """ | ||
2943 | 347 | raise NotImplementedError("You cannot use this class directly.") | ||
2944 | 348 | |||
2945 | 349 | @property | ||
2946 | 350 | def application(self): | ||
2947 | 351 | """Get the application that owns this window. | ||
2948 | 352 | |||
2949 | 353 | This method may return None if the window does not have an associated | ||
2950 | 354 | application. The 'desktop' window is one such example. | ||
2951 | 355 | |||
2952 | 356 | """ | ||
2953 | 357 | raise NotImplementedError("You cannot use this class directly.") | ||
2954 | 358 | |||
2955 | 359 | @property | ||
2956 | 360 | def user_visible(self): | ||
2957 | 361 | """Is this window visible to the user in the switcher?""" | ||
2958 | 362 | raise NotImplementedError("You cannot use this class directly.") | ||
2959 | 363 | |||
2960 | 364 | @property | ||
2961 | 365 | def is_hidden(self): | ||
2962 | 366 | """Is this window hidden? | ||
2963 | 367 | |||
2964 | 368 | Windows are hidden when the 'Show Desktop' mode is activated. | ||
2965 | 369 | |||
2966 | 370 | """ | ||
2967 | 371 | raise NotImplementedError("You cannot use this class directly.") | ||
2968 | 372 | |||
2969 | 373 | @property | ||
2970 | 374 | def is_focused(self): | ||
2971 | 375 | """Is this window focused?""" | ||
2972 | 376 | raise NotImplementedError("You cannot use this class directly.") | ||
2973 | 377 | |||
2974 | 378 | @property | ||
2975 | 379 | def is_valid(self): | ||
2976 | 380 | """Is this window object valid? | ||
2977 | 381 | |||
2978 | 382 | Invalid windows are caused by windows closing during the construction of | ||
2979 | 383 | this object instance. | ||
2980 | 384 | |||
2981 | 385 | """ | ||
2982 | 386 | raise NotImplementedError("You cannot use this class directly.") | ||
2983 | 387 | |||
2984 | 388 | @property | ||
2985 | 389 | def monitor(self): | ||
2986 | 390 | """Returns the monitor to which the windows belongs to""" | ||
2987 | 391 | raise NotImplementedError("You cannot use this class directly.") | ||
2988 | 392 | |||
2989 | 393 | @property | ||
2990 | 394 | def closed(self): | ||
2991 | 395 | """Returns True if the window has been closed""" | ||
2992 | 396 | raise NotImplementedError("You cannot use this class directly.") | ||
2993 | 397 | |||
2994 | 398 | def close(self): | ||
2995 | 399 | """Close the window.""" | ||
2996 | 400 | raise NotImplementedError("You cannot use this class directly.") | ||
2997 | 401 | |||
2998 | 402 | def set_focus(self): | ||
2999 | 403 | raise NotImplementedError("You cannot use this class directly.") | ||
3000 | 0 | 404 | ||
3001 | === renamed file 'autopilot/emulators/bamf.py' => 'autopilot/process/_bamf.py' | |||
3002 | --- autopilot/emulators/bamf.py 2013-01-06 21:51:56 +0000 | |||
3003 | +++ autopilot/process/_bamf.py 2013-04-15 21:43:32 +0000 | |||
3004 | @@ -5,7 +5,7 @@ | |||
3005 | 5 | # under the terms of the GNU General Public License version 3, as published | 5 | # under the terms of the GNU General Public License version 3, as published |
3006 | 6 | # by the Free Software Foundation. | 6 | # by the Free Software Foundation. |
3007 | 7 | 7 | ||
3009 | 8 | """Various classes for interacting with BAMF.""" | 8 | """BAMF implementation of the Process Management""" |
3010 | 9 | 9 | ||
3011 | 10 | from __future__ import absolute_import | 10 | from __future__ import absolute_import |
3012 | 11 | 11 | ||
3013 | @@ -13,21 +13,25 @@ | |||
3014 | 13 | import dbus.glib | 13 | import dbus.glib |
3015 | 14 | from gi.repository import Gio | 14 | from gi.repository import Gio |
3016 | 15 | from gi.repository import GLib | 15 | from gi.repository import GLib |
3017 | 16 | import logging | ||
3018 | 16 | import os | 17 | import os |
3019 | 18 | from time import sleep | ||
3020 | 17 | from Xlib import display, X, protocol | 19 | from Xlib import display, X, protocol |
3021 | 18 | 20 | ||
3030 | 19 | from autopilot.emulators.dbus_handler import get_session_bus | 21 | from autopilot.dbus_handler import get_session_bus |
3031 | 20 | from autopilot.utilities import Silence | 22 | from autopilot.utilities import addCleanup, Silence |
3032 | 21 | 23 | ||
3033 | 22 | __all__ = [ | 24 | from autopilot.process import ( |
3034 | 23 | "Bamf", | 25 | ProcessManager as ProcessManagerBase, |
3035 | 24 | "BamfApplication", | 26 | Application as ApplicationBase, |
3036 | 25 | "BamfWindow", | 27 | Window as WindowBase |
3037 | 26 | ] | 28 | ) |
3038 | 29 | |||
3039 | 27 | 30 | ||
3040 | 28 | _BAMF_BUS_NAME = 'org.ayatana.bamf' | 31 | _BAMF_BUS_NAME = 'org.ayatana.bamf' |
3041 | 29 | _X_DISPLAY = None | 32 | _X_DISPLAY = None |
3042 | 30 | 33 | ||
3043 | 34 | logger = logging.getLogger(__name__) | ||
3044 | 31 | 35 | ||
3045 | 32 | def get_display(): | 36 | def get_display(): |
3046 | 33 | """Create an Xlib display object (silently) and return it.""" | 37 | """Create an Xlib display object (silently) and return it.""" |
3047 | @@ -51,7 +55,7 @@ | |||
3048 | 51 | return False | 55 | return False |
3049 | 52 | 56 | ||
3050 | 53 | 57 | ||
3052 | 54 | class Bamf(object): | 58 | class ProcessManager(ProcessManagerBase): |
3053 | 55 | """High-level class for interacting with Bamf from within a test. | 59 | """High-level class for interacting with Bamf from within a test. |
3054 | 56 | 60 | ||
3055 | 57 | Use this class to inspect the state of running applications and open | 61 | Use this class to inspect the state of running applications and open |
3056 | @@ -65,6 +69,126 @@ | |||
3057 | 65 | self.matcher_proxy = get_session_bus().get_object(_BAMF_BUS_NAME, matcher_path) | 69 | self.matcher_proxy = get_session_bus().get_object(_BAMF_BUS_NAME, matcher_path) |
3058 | 66 | self.matcher_interface = dbus.Interface(self.matcher_proxy, self.matcher_interface_name) | 70 | self.matcher_interface = dbus.Interface(self.matcher_proxy, self.matcher_interface_name) |
3059 | 67 | 71 | ||
3060 | 72 | def start_app(self, app_name, files=[], locale=None): | ||
3061 | 73 | """Start one of the known applications, and kill it on tear down. | ||
3062 | 74 | |||
3063 | 75 | .. warning:: This method will clear all instances of this application on | ||
3064 | 76 | tearDown, not just the one opened by this method! We recommend that | ||
3065 | 77 | you use the :meth:`start_app_window` method instead, as it is generally | ||
3066 | 78 | safer. | ||
3067 | 79 | |||
3068 | 80 | :param app_name: The application name. *This name must either already | ||
3069 | 81 | be registered as one of the built-in applications that are supported | ||
3070 | 82 | by autopilot, or must have been registered using* | ||
3071 | 83 | :meth:`register_known_application` *beforehand.* | ||
3072 | 84 | :param files: (Optional) A list of paths to open with the | ||
3073 | 85 | given application. *Not all applications support opening files in this | ||
3074 | 86 | way.* | ||
3075 | 87 | :param locale: (Optional) The locale will to set when the application | ||
3076 | 88 | is launched. *If you want to launch an application without any | ||
3077 | 89 | localisation being applied, set this parameter to 'C'.* | ||
3078 | 90 | :returns: A :class:`~autopilot.process.Application` instance. | ||
3079 | 91 | |||
3080 | 92 | """ | ||
3081 | 93 | window = self._open_window(app_name, files, locale) | ||
3082 | 94 | if window: | ||
3083 | 95 | addCleanup(self.close_all_app, app_name) | ||
3084 | 96 | return window.application | ||
3085 | 97 | |||
3086 | 98 | raise AssertionError("No new application window was opened.") | ||
3087 | 99 | |||
3088 | 100 | def start_app_window(self, app_name, files=[], locale=None): | ||
3089 | 101 | """Open a single window for one of the known applications, and close it | ||
3090 | 102 | at the end of the test. | ||
3091 | 103 | |||
3092 | 104 | :param app_name: The application name. *This name must either already | ||
3093 | 105 | be registered as one of the built-in applications that are supported | ||
3094 | 106 | by autopilot, or must have been registered with* | ||
3095 | 107 | :meth:`register_known_application` *beforehand.* | ||
3096 | 108 | :param files: (Optional) Should be a list of paths to open with the | ||
3097 | 109 | given application. *Not all applications support opening files in this | ||
3098 | 110 | way.* | ||
3099 | 111 | :param locale: (Optional) The locale will to set when the application | ||
3100 | 112 | is launched. *If you want to launch an application without any | ||
3101 | 113 | localisation being applied, set this parameter to 'C'.* | ||
3102 | 114 | :raises: **AssertionError** if no window was opened, or more than one | ||
3103 | 115 | window was opened. | ||
3104 | 116 | :returns: A :class:`~autopilot.process.Window` instance. | ||
3105 | 117 | |||
3106 | 118 | """ | ||
3107 | 119 | window = self._open_window(app_name, files, locale) | ||
3108 | 120 | if window: | ||
3109 | 121 | addCleanup(window.close) | ||
3110 | 122 | return window | ||
3111 | 123 | raise AssertionError("No window was opened.") | ||
3112 | 124 | |||
3113 | 125 | def _open_window(self, app_name, files, locale): | ||
3114 | 126 | """Open a new 'app_name' window, returning the window instance or None. | ||
3115 | 127 | |||
3116 | 128 | Raises an AssertionError if this creates more than one window. | ||
3117 | 129 | |||
3118 | 130 | """ | ||
3119 | 131 | existing_windows = self.get_open_windows_by_application(app_name) | ||
3120 | 132 | |||
3121 | 133 | if locale: | ||
3122 | 134 | os.putenv("LC_ALL", locale) | ||
3123 | 135 | addCleanup(os.unsetenv, "LC_ALL") | ||
3124 | 136 | logger.info("Starting application '%s' with files %r in locale %s", app_name, files, locale) | ||
3125 | 137 | else: | ||
3126 | 138 | logger.info("Starting application '%s' with files %r", app_name, files) | ||
3127 | 139 | |||
3128 | 140 | |||
3129 | 141 | app = self.KNOWN_APPS[app_name] | ||
3130 | 142 | self.launch_application(app['desktop-file'], files) | ||
3131 | 143 | apps = self.get_running_applications_by_desktop_file(app['desktop-file']) | ||
3132 | 144 | |||
3133 | 145 | for i in range(10): | ||
3134 | 146 | try: | ||
3135 | 147 | new_windows = [] | ||
3136 | 148 | [new_windows.extend(a.get_windows()) for a in apps] | ||
3137 | 149 | filter_fn = lambda w: w.x_id not in [c.x_id for c in existing_windows] | ||
3138 | 150 | new_wins = filter(filter_fn, new_windows) | ||
3139 | 151 | if new_wins: | ||
3140 | 152 | assert len(new_wins) == 1 | ||
3141 | 153 | return new_wins[0] | ||
3142 | 154 | except DBusException: | ||
3143 | 155 | pass | ||
3144 | 156 | sleep(1) | ||
3145 | 157 | return None | ||
3146 | 158 | |||
3147 | 159 | def get_open_windows_by_application(self, app_name): | ||
3148 | 160 | """Get a list of ~autopilot.process.Window` instances | ||
3149 | 161 | for the given application name. | ||
3150 | 162 | |||
3151 | 163 | :param app_name: The name of one of the well-known applications. | ||
3152 | 164 | :returns: A list of :class:`~autopilot.process.Window` | ||
3153 | 165 | instances. | ||
3154 | 166 | |||
3155 | 167 | """ | ||
3156 | 168 | existing_windows = [] | ||
3157 | 169 | [existing_windows.extend(a.get_windows()) for a in self.get_app_instances(app_name)] | ||
3158 | 170 | return existing_windows | ||
3159 | 171 | |||
3160 | 172 | def close_all_app(self, app_name): | ||
3161 | 173 | """Close all instances of the application 'app_name'.""" | ||
3162 | 174 | app = self.KNOWN_APPS[app_name] | ||
3163 | 175 | try: | ||
3164 | 176 | pids = check_output(["pidof", app['process-name']]).split() | ||
3165 | 177 | if len(pids): | ||
3166 | 178 | call(["kill"] + pids) | ||
3167 | 179 | except CalledProcessError: | ||
3168 | 180 | logger.warning("Tried to close applicaton '%s' but it wasn't running.", app_name) | ||
3169 | 181 | |||
3170 | 182 | def get_app_instances(self, app_name): | ||
3171 | 183 | """Get `~autopilot.process.Application` instances for app_name.""" | ||
3172 | 184 | desktop_file = self.KNOWN_APPS[app_name]['desktop-file'] | ||
3173 | 185 | return self.get_running_applications_by_desktop_file(desktop_file) | ||
3174 | 186 | |||
3175 | 187 | def app_is_running(self, app_name): | ||
3176 | 188 | """Return true if an instance of the application is running.""" | ||
3177 | 189 | apps = self.get_app_instances(app_name) | ||
3178 | 190 | return len(apps) > 0 | ||
3179 | 191 | |||
3180 | 68 | def get_running_applications(self, user_visible_only=True): | 192 | def get_running_applications(self, user_visible_only=True): |
3181 | 69 | """Get a list of the currently running applications. | 193 | """Get a list of the currently running applications. |
3182 | 70 | 194 | ||
3183 | @@ -72,7 +196,7 @@ | |||
3184 | 72 | visible to the user in the switcher will be returned. | 196 | visible to the user in the switcher will be returned. |
3185 | 73 | 197 | ||
3186 | 74 | """ | 198 | """ |
3188 | 75 | apps = [BamfApplication(p) for p in self.matcher_interface.RunningApplications()] | 199 | apps = [Application(p) for p in self.matcher_interface.RunningApplications()] |
3189 | 76 | if user_visible_only: | 200 | if user_visible_only: |
3190 | 77 | return filter(_filter_user_visible, apps) | 201 | return filter(_filter_user_visible, apps) |
3191 | 78 | return apps | 202 | return apps |
3192 | @@ -80,7 +204,7 @@ | |||
3193 | 80 | def get_running_applications_by_desktop_file(self, desktop_file): | 204 | def get_running_applications_by_desktop_file(self, desktop_file): |
3194 | 81 | """Return a list of applications that have the desktop file *desktop_file*. | 205 | """Return a list of applications that have the desktop file *desktop_file*. |
3195 | 82 | 206 | ||
3197 | 83 | This method may return an empty list, if no applications | 207 | This method will return an empty list if no applications |
3198 | 84 | are found with the specified desktop file. | 208 | are found with the specified desktop file. |
3199 | 85 | 209 | ||
3200 | 86 | """ | 210 | """ |
3201 | @@ -93,14 +217,6 @@ | |||
3202 | 93 | pass | 217 | pass |
3203 | 94 | return apps | 218 | return apps |
3204 | 95 | 219 | ||
3205 | 96 | def get_application_by_xid(self, xid): | ||
3206 | 97 | """Return the application that has a child with the requested xid or None.""" | ||
3207 | 98 | |||
3208 | 99 | app_path = self.matcher_interface.ApplicationForXid(xid) | ||
3209 | 100 | if len(app_path): | ||
3210 | 101 | return BamfApplication(app_path) | ||
3211 | 102 | return None | ||
3212 | 103 | |||
3213 | 104 | def get_open_windows(self, user_visible_only=True): | 220 | def get_open_windows(self, user_visible_only=True): |
3214 | 105 | """Get a list of currently open windows. | 221 | """Get a list of currently open windows. |
3215 | 106 | 222 | ||
3216 | @@ -111,7 +227,7 @@ | |||
3217 | 111 | 227 | ||
3218 | 112 | """ | 228 | """ |
3219 | 113 | 229 | ||
3221 | 114 | windows = [BamfWindow(w) for w in self.matcher_interface.WindowStackForMonitor(-1)] | 230 | windows = [Window(w) for w in self.matcher_interface.WindowStackForMonitor(-1)] |
3222 | 115 | if user_visible_only: | 231 | if user_visible_only: |
3223 | 116 | windows = filter(_filter_user_visible, windows) | 232 | windows = filter(_filter_user_visible, windows) |
3224 | 117 | # Now sort on stacking order. | 233 | # Now sort on stacking order. |
3225 | @@ -119,11 +235,6 @@ | |||
3226 | 119 | # try and use len() on return values from these methods. | 235 | # try and use len() on return values from these methods. |
3227 | 120 | return list(reversed(windows)) | 236 | return list(reversed(windows)) |
3228 | 121 | 237 | ||
3229 | 122 | def get_window_by_xid(self, xid): | ||
3230 | 123 | """Get the BamfWindow that matches the provided *xid*.""" | ||
3231 | 124 | windows = [BamfWindow(w) for w in self.matcher_interface.WindowPaths() if BamfWindow(w).x_id == xid] | ||
3232 | 125 | return windows[0] if windows else None | ||
3233 | 126 | |||
3234 | 127 | def wait_until_application_is_running(self, desktop_file, timeout): | 238 | def wait_until_application_is_running(self, desktop_file, timeout): |
3235 | 128 | """Wait until a given application is running. | 239 | """Wait until a given application is running. |
3236 | 129 | 240 | ||
3237 | @@ -147,7 +258,7 @@ | |||
3238 | 147 | # No, so define a callback to watch the ViewOpened signal: | 258 | # No, so define a callback to watch the ViewOpened signal: |
3239 | 148 | def on_view_added(bamf_path, name): | 259 | def on_view_added(bamf_path, name): |
3240 | 149 | if bamf_path.split('/')[-1].startswith('application'): | 260 | if bamf_path.split('/')[-1].startswith('application'): |
3242 | 150 | app = BamfApplication(bamf_path) | 261 | app = Application(bamf_path) |
3243 | 151 | if desktop_file == os.path.split(app.desktop_file)[1]: | 262 | if desktop_file == os.path.split(app.desktop_file)[1]: |
3244 | 152 | gobject_loop.quit() | 263 | gobject_loop.quit() |
3245 | 153 | 264 | ||
3246 | @@ -192,7 +303,7 @@ | |||
3247 | 192 | return proc | 303 | return proc |
3248 | 193 | 304 | ||
3249 | 194 | 305 | ||
3251 | 195 | class BamfApplication(object): | 306 | class Application(ApplicationBase): |
3252 | 196 | """Represents an application, with information as returned by Bamf. | 307 | """Represents an application, with information as returned by Bamf. |
3253 | 197 | 308 | ||
3254 | 198 | .. important:: Don't instantiate this class yourself. instead, use the | 309 | .. important:: Don't instantiate this class yourself. instead, use the |
3255 | @@ -265,20 +376,20 @@ | |||
3256 | 265 | 376 | ||
3257 | 266 | def get_windows(self): | 377 | def get_windows(self): |
3258 | 267 | """Get a list of the application windows.""" | 378 | """Get a list of the application windows.""" |
3260 | 268 | return [BamfWindow(w) for w in self._view_iface.Children()] | 379 | return [Window(w) for w in self._view_iface.Children()] |
3261 | 269 | 380 | ||
3262 | 270 | def __repr__(self): | 381 | def __repr__(self): |
3264 | 271 | return "<BamfApplication '%s'>" % (self.name) | 382 | return "<Application '%s'>" % (self.name) |
3265 | 272 | 383 | ||
3266 | 273 | def __eq__(self, other): | 384 | def __eq__(self, other): |
3267 | 274 | return self.desktop_file == other.desktop_file | 385 | return self.desktop_file == other.desktop_file |
3268 | 275 | 386 | ||
3269 | 276 | 387 | ||
3271 | 277 | class BamfWindow(object): | 388 | class Window(WindowBase): |
3272 | 278 | """Represents an application window, as returned by Bamf. | 389 | """Represents an application window, as returned by Bamf. |
3273 | 279 | 390 | ||
3274 | 280 | .. important:: Don't instantiate this class yourself. Instead, use the | 391 | .. important:: Don't instantiate this class yourself. Instead, use the |
3276 | 281 | appropriate methods in BamfApplication. | 392 | appropriate methods in Application. |
3277 | 282 | 393 | ||
3278 | 283 | """ | 394 | """ |
3279 | 284 | def __init__(self, window_path): | 395 | def __init__(self, window_path): |
3280 | @@ -364,7 +475,7 @@ | |||
3281 | 364 | # associated application. For these windows we return none. | 475 | # associated application. For these windows we return none. |
3282 | 365 | parents = self._view_iface.Parents() | 476 | parents = self._view_iface.Parents() |
3283 | 366 | if parents: | 477 | if parents: |
3285 | 367 | return BamfApplication(parents[0]) | 478 | return Application(parents[0]) |
3286 | 368 | else: | 479 | else: |
3287 | 369 | return None | 480 | return None |
3288 | 370 | 481 | ||
3289 | @@ -423,7 +534,7 @@ | |||
3290 | 423 | self._x_win.configure(stack_mode=X.Above) | 534 | self._x_win.configure(stack_mode=X.Above) |
3291 | 424 | 535 | ||
3292 | 425 | def __repr__(self): | 536 | def __repr__(self): |
3294 | 426 | return "<BamfWindow '%s' Xid: %d>" % (self.title if self._x_win else '', self.x_id) | 537 | return "<Window '%s' Xid: %d>" % (self.title if self._x_win else '', self.x_id) |
3295 | 427 | 538 | ||
3296 | 428 | def _getProperty(self, _type): | 539 | def _getProperty(self, _type): |
3297 | 429 | """Get an X11 property. | 540 | """Get an X11 property. |
3298 | 430 | 541 | ||
3299 | === modified file 'autopilot/testcase.py' | |||
3300 | --- autopilot/testcase.py 2013-04-05 14:02:59 +0000 | |||
3301 | +++ autopilot/testcase.py 2013-04-15 21:43:32 +0000 | |||
3302 | @@ -11,40 +11,35 @@ | |||
3303 | 11 | from __future__ import absolute_import | 11 | from __future__ import absolute_import |
3304 | 12 | 12 | ||
3305 | 13 | from dbus import DBusException | 13 | from dbus import DBusException |
3306 | 14 | from gi.repository import Gio | ||
3307 | 14 | import logging | 15 | import logging |
3308 | 15 | import os | 16 | import os |
3310 | 16 | from StringIO import StringIO | 17 | import signal |
3311 | 17 | from subprocess import ( | 18 | from subprocess import ( |
3312 | 18 | call, | 19 | call, |
3313 | 19 | CalledProcessError, | 20 | CalledProcessError, |
3314 | 20 | check_output, | 21 | check_output, |
3315 | 21 | Popen, | ||
3316 | 22 | PIPE, | ||
3317 | 23 | STDOUT, | ||
3318 | 24 | ) | 22 | ) |
3319 | 25 | 23 | ||
3320 | 26 | from testscenarios import TestWithScenarios | 24 | from testscenarios import TestWithScenarios |
3321 | 27 | from testtools import TestCase | 25 | from testtools import TestCase |
3322 | 28 | from testtools.content import text_content | 26 | from testtools.content import text_content |
3323 | 29 | from testtools.matchers import Equals | 27 | from testtools.matchers import Equals |
3325 | 30 | import time | 28 | from time import sleep |
3326 | 31 | 29 | ||
3337 | 32 | from autopilot.compizconfig import get_global_context | 30 | from autopilot.process import ProcessManager |
3338 | 33 | from autopilot.emulators.bamf import Bamf | 31 | from autopilot.input import Keyboard, Mouse |
3339 | 34 | from autopilot.emulators.zeitgeist import Zeitgeist | 32 | from autopilot.introspection import ( |
3340 | 35 | from autopilot.emulators.processmanager import ProcessManager | 33 | get_application_launcher, |
3341 | 36 | from autopilot.emulators.X11 import ScreenGeometry, reset_display | 34 | get_autopilot_proxy_object_for_process, |
3342 | 37 | from autopilot.emulators.input import get_keyboard, get_mouse | 35 | launch_application, |
3343 | 38 | from autopilot.glibrunner import AutopilotTestRunner | 36 | launch_process, |
3334 | 39 | from autopilot.globals import (get_log_verbose, | ||
3335 | 40 | get_video_recording_enabled, | ||
3336 | 41 | get_video_record_directory, | ||
3344 | 42 | ) | 37 | ) |
3345 | 38 | from autopilot.display import Display | ||
3346 | 39 | from autopilot.globals import on_test_started | ||
3347 | 43 | from autopilot.keybindings import KeybindingsHelper | 40 | from autopilot.keybindings import KeybindingsHelper |
3348 | 44 | from autopilot.matchers import Eventually | 41 | from autopilot.matchers import Eventually |
3352 | 45 | from autopilot.utilities import (get_compiz_setting, | 42 | |
3350 | 46 | LogFormatter, | ||
3351 | 47 | ) | ||
3353 | 48 | 43 | ||
3354 | 49 | logger = logging.getLogger(__name__) | 44 | logger = logging.getLogger(__name__) |
3355 | 50 | 45 | ||
3356 | @@ -74,108 +69,7 @@ | |||
3357 | 74 | return result | 69 | return result |
3358 | 75 | 70 | ||
3359 | 76 | 71 | ||
3462 | 77 | class LoggedTestCase(TestWithScenarios, TestCase): | 72 | class AutopilotTestCase(TestWithScenarios, TestCase, KeybindingsHelper): |
3361 | 78 | """Initialize the logging for the test case.""" | ||
3362 | 79 | |||
3363 | 80 | def setUp(self): | ||
3364 | 81 | self._setUpTestLogging() | ||
3365 | 82 | # The reason that the super setup is done here is due to making sure | ||
3366 | 83 | # that the logging is properly set up prior to calling it. | ||
3367 | 84 | super(LoggedTestCase, self).setUp() | ||
3368 | 85 | if get_log_verbose(): | ||
3369 | 86 | logger.info("*" * 60) | ||
3370 | 87 | logger.info("Starting test %s", self.shortDescription()) | ||
3371 | 88 | |||
3372 | 89 | def _setUpTestLogging(self): | ||
3373 | 90 | self._log_buffer = StringIO() | ||
3374 | 91 | root_logger = logging.getLogger() | ||
3375 | 92 | root_logger.setLevel(logging.DEBUG) | ||
3376 | 93 | formatter = LogFormatter() | ||
3377 | 94 | self._log_handler = logging.StreamHandler(stream=self._log_buffer) | ||
3378 | 95 | self._log_handler.setFormatter(formatter) | ||
3379 | 96 | root_logger.addHandler(self._log_handler) | ||
3380 | 97 | |||
3381 | 98 | #Tear down logging in a cleanUp handler, so it's done after all other | ||
3382 | 99 | # tearDown() calls and cleanup handlers. | ||
3383 | 100 | self.addCleanup(self._tearDownLogging) | ||
3384 | 101 | |||
3385 | 102 | def _tearDownLogging(self): | ||
3386 | 103 | root_logger = logging.getLogger() | ||
3387 | 104 | self._log_handler.flush() | ||
3388 | 105 | self._log_buffer.seek(0) | ||
3389 | 106 | self.addDetail('test-log', text_content(self._log_buffer.getvalue())) | ||
3390 | 107 | root_logger.removeHandler(self._log_handler) | ||
3391 | 108 | # Calling del to remove the handler and flush the buffer. We are | ||
3392 | 109 | # abusing the log handlers here a little. | ||
3393 | 110 | del self._log_buffer | ||
3394 | 111 | |||
3395 | 112 | |||
3396 | 113 | |||
3397 | 114 | class VideoCapturedTestCase(LoggedTestCase): | ||
3398 | 115 | """Video capture autopilot tests, saving the results if the test failed.""" | ||
3399 | 116 | |||
3400 | 117 | _recording_app = '/usr/bin/recordmydesktop' | ||
3401 | 118 | _recording_opts = ['--no-sound', '--no-frame', '-o',] | ||
3402 | 119 | |||
3403 | 120 | def setUp(self): | ||
3404 | 121 | super(VideoCapturedTestCase, self).setUp() | ||
3405 | 122 | global video_recording_enabled | ||
3406 | 123 | if get_video_recording_enabled() and not self._have_recording_app(): | ||
3407 | 124 | video_recording_enabled = False | ||
3408 | 125 | logger.warning("Disabling video capture since '%s' is not present", self._recording_app) | ||
3409 | 126 | |||
3410 | 127 | if get_video_recording_enabled(): | ||
3411 | 128 | self._test_passed = True | ||
3412 | 129 | self.addOnException(self._on_test_failed) | ||
3413 | 130 | self.addCleanup(self._stop_video_capture) | ||
3414 | 131 | self._start_video_capture() | ||
3415 | 132 | |||
3416 | 133 | def _have_recording_app(self): | ||
3417 | 134 | return os.path.exists(self._recording_app) | ||
3418 | 135 | |||
3419 | 136 | def _start_video_capture(self): | ||
3420 | 137 | args = self._get_capture_command_line() | ||
3421 | 138 | self._capture_file = self._get_capture_output_file() | ||
3422 | 139 | self._ensure_directory_exists_but_not_file(self._capture_file) | ||
3423 | 140 | args.append(self._capture_file) | ||
3424 | 141 | logger.debug("Starting: %r", args) | ||
3425 | 142 | self._capture_process = Popen(args, stdout=PIPE, stderr=STDOUT) | ||
3426 | 143 | |||
3427 | 144 | def _stop_video_capture(self): | ||
3428 | 145 | """Stop the video capture. If the test failed, save the resulting file.""" | ||
3429 | 146 | |||
3430 | 147 | if self._test_passed: | ||
3431 | 148 | # We use kill here because we don't want the recording app to start | ||
3432 | 149 | # encoding the video file (since we're removing it anyway.) | ||
3433 | 150 | self._capture_process.kill() | ||
3434 | 151 | self._capture_process.wait() | ||
3435 | 152 | else: | ||
3436 | 153 | self._capture_process.terminate() | ||
3437 | 154 | self._capture_process.wait() | ||
3438 | 155 | if self._capture_process.returncode != 0: | ||
3439 | 156 | self.addDetail('video capture log', text_content(self._capture_process.stdout.read())) | ||
3440 | 157 | self._capture_process = None | ||
3441 | 158 | |||
3442 | 159 | def _get_capture_command_line(self): | ||
3443 | 160 | return [self._recording_app] + self._recording_opts | ||
3444 | 161 | |||
3445 | 162 | def _get_capture_output_file(self): | ||
3446 | 163 | return os.path.join(get_video_record_directory(), '%s.ogv' % (self.shortDescription())) | ||
3447 | 164 | |||
3448 | 165 | def _ensure_directory_exists_but_not_file(self, file_path): | ||
3449 | 166 | dirpath = os.path.dirname(file_path) | ||
3450 | 167 | if not os.path.exists(dirpath): | ||
3451 | 168 | os.makedirs(dirpath) | ||
3452 | 169 | elif os.path.exists(file_path): | ||
3453 | 170 | logger.warning("Video capture file '%s' already exists, deleting.", file_path) | ||
3454 | 171 | os.remove(file_path) | ||
3455 | 172 | |||
3456 | 173 | def _on_test_failed(self, ex_info): | ||
3457 | 174 | """Called when a test fails.""" | ||
3458 | 175 | self._test_passed = False | ||
3459 | 176 | |||
3460 | 177 | |||
3461 | 178 | class AutopilotTestCase(VideoCapturedTestCase, KeybindingsHelper): | ||
3463 | 179 | """Wrapper around testtools.TestCase that adds significant functionality. | 73 | """Wrapper around testtools.TestCase that adds significant functionality. |
3464 | 180 | 74 | ||
3465 | 181 | This class should be the base class for all autopilot test case classes. Not | 75 | This class should be the base class for all autopilot test case classes. Not |
3466 | @@ -190,19 +84,11 @@ | |||
3467 | 190 | :meth:`~autopilot.testcase.AutopilotTestCase.start_app` and | 84 | :meth:`~autopilot.testcase.AutopilotTestCase.start_app` and |
3468 | 191 | :meth:`~autopilot.testcase.AutopilotTestCase.start_app_window` which will | 85 | :meth:`~autopilot.testcase.AutopilotTestCase.start_app_window` which will |
3469 | 192 | launch one of the well-known applications and return a | 86 | launch one of the well-known applications and return a |
3472 | 193 | :class:`~autopilot.emulators.bamf.BamfApplication` or | 87 | :class:`~autopilot.process.Application` or |
3473 | 194 | :class:`~autopilot.emulators.bamf.BamfWindow` instance to the launched | 88 | :class:`~autopilot.process.Window` instance to the launched |
3474 | 195 | process respectively. All applications launched in this way will be closed | 89 | process respectively. All applications launched in this way will be closed |
3475 | 196 | when the test ends. | 90 | when the test ends. |
3476 | 197 | 91 | ||
3477 | 198 | **Set Unity & Compiz Options** | ||
3478 | 199 | |||
3479 | 200 | The :meth:`~autopilot.testcase.AutopilotTestCase.set_unity_option` and | ||
3480 | 201 | :meth:`~autopilot.testcase.AutopilotTestCase.set_compiz_option` methods set a | ||
3481 | 202 | unity or compiz setting to a particular value for the duration of the | ||
3482 | 203 | current test only. This is useful if you want the window manager to behave | ||
3483 | 204 | in a particular fashion for a particular test, while being assured that any | ||
3484 | 205 | chances are non-destructive. | ||
3485 | 206 | 92 | ||
3486 | 207 | **Patch Process Environment** | 93 | **Patch Process Environment** |
3487 | 208 | 94 | ||
3488 | @@ -213,269 +99,40 @@ | |||
3489 | 213 | 99 | ||
3490 | 214 | """ | 100 | """ |
3491 | 215 | 101 | ||
3492 | 216 | run_tests_with = AutopilotTestRunner | ||
3493 | 217 | |||
3494 | 218 | KNOWN_APPS = { | ||
3495 | 219 | 'Character Map' : { | ||
3496 | 220 | 'desktop-file': 'gucharmap.desktop', | ||
3497 | 221 | 'process-name': 'gucharmap', | ||
3498 | 222 | }, | ||
3499 | 223 | 'Calculator' : { | ||
3500 | 224 | 'desktop-file': 'gcalctool.desktop', | ||
3501 | 225 | 'process-name': 'gnome-calculator', | ||
3502 | 226 | }, | ||
3503 | 227 | 'Mahjongg' : { | ||
3504 | 228 | 'desktop-file': 'mahjongg.desktop', | ||
3505 | 229 | 'process-name': 'gnome-mahjongg', | ||
3506 | 230 | }, | ||
3507 | 231 | 'Remmina' : { | ||
3508 | 232 | 'desktop-file': 'remmina.desktop', | ||
3509 | 233 | 'process-name': 'remmina', | ||
3510 | 234 | }, | ||
3511 | 235 | 'System Settings' : { | ||
3512 | 236 | 'desktop-file': 'gnome-control-center.desktop', | ||
3513 | 237 | 'process-name': 'gnome-control-center', | ||
3514 | 238 | }, | ||
3515 | 239 | 'Text Editor' : { | ||
3516 | 240 | 'desktop-file': 'gedit.desktop', | ||
3517 | 241 | 'process-name': 'gedit', | ||
3518 | 242 | }, | ||
3519 | 243 | 'Terminal' : { | ||
3520 | 244 | 'desktop-file': 'gnome-terminal.desktop', | ||
3521 | 245 | 'process-name': 'gnome-terminal', | ||
3522 | 246 | }, | ||
3523 | 247 | } | ||
3524 | 248 | |||
3525 | 249 | |||
3526 | 250 | def setUp(self): | 102 | def setUp(self): |
3527 | 251 | super(AutopilotTestCase, self).setUp() | 103 | super(AutopilotTestCase, self).setUp() |
3539 | 252 | 104 | on_test_started(self) | |
3540 | 253 | self._process_manager = ProcessManager() | 105 | |
3541 | 254 | self._process_manager.snapshot_running_apps() | 106 | self.process_manager = ProcessManager.create() |
3542 | 255 | self.addCleanup(self._process_manager.compare_system_with_snapshot) | 107 | self._app_snapshot = self.process_manager.get_running_applications() |
3543 | 256 | 108 | self.addCleanup(self._compare_system_with_app_snapshot) | |
3544 | 257 | self.bamf = Bamf() | 109 | |
3545 | 258 | self.keyboard = get_keyboard() | 110 | self.keyboard = Keyboard.create() |
3546 | 259 | self.mouse = get_mouse() | 111 | self.mouse = Mouse.create() |
3547 | 260 | self.zeitgeist = Zeitgeist() | 112 | |
3548 | 261 | 113 | self.screen_geo = Display.create() | |
3538 | 262 | self.screen_geo = ScreenGeometry() | ||
3549 | 263 | self.addCleanup(self.keyboard.cleanup) | 114 | self.addCleanup(self.keyboard.cleanup) |
3550 | 264 | self.addCleanup(self.mouse.cleanup) | 115 | self.addCleanup(self.mouse.cleanup) |
3551 | 265 | 116 | ||
3720 | 266 | def call_gsettings_cmd(self, command, schema, *args): | 117 | def _compare_system_with_app_snapshot(self): |
3721 | 267 | """Set a desktop wide gsettings option | 118 | """Compare the currently running application with the last snapshot. |
3722 | 268 | 119 | ||
3723 | 269 | Using the gsettings command because there is a bug with importing | 120 | This method will raise an AssertionError if there are any new applications |
3724 | 270 | from gobject introspection and pygtk2 simultaneously, and the Xlib | 121 | currently running that were not running when the snapshot was taken. |
3725 | 271 | keyboard layout bits are very unwieldy. This seems like the best | 122 | """ |
3726 | 272 | solution, even a little bit brutish. | 123 | if self._app_snapshot is None: |
3727 | 273 | """ | 124 | raise RuntimeError("No snapshot to match against.") |
3728 | 274 | cmd = ['gsettings', command, schema] + list(args) | 125 | |
3729 | 275 | # strip to remove the trailing \n. | 126 | new_apps = [] |
3562 | 276 | ret = check_output(cmd).strip() | ||
3563 | 277 | time.sleep(5) | ||
3564 | 278 | reset_display() | ||
3565 | 279 | return ret | ||
3566 | 280 | |||
3567 | 281 | def set_unity_option(self, option_name, option_value): | ||
3568 | 282 | """Set an option in the unity compiz plugin options. | ||
3569 | 283 | |||
3570 | 284 | .. note:: The value will be set for the current test only, and | ||
3571 | 285 | automatically undone when the test ends. | ||
3572 | 286 | |||
3573 | 287 | :param option_name: The name of the unity option. | ||
3574 | 288 | :param option_value: The value you want to set. | ||
3575 | 289 | :raises: **KeyError** if the option named does not exist. | ||
3576 | 290 | |||
3577 | 291 | """ | ||
3578 | 292 | self.set_compiz_option("unityshell", option_name, option_value) | ||
3579 | 293 | |||
3580 | 294 | def set_compiz_option(self, plugin_name, option_name, option_value): | ||
3581 | 295 | """Set a compiz option for the duration of this test only. | ||
3582 | 296 | |||
3583 | 297 | .. note:: The value will be set for the current test only, and | ||
3584 | 298 | automatically undone when the test ends. | ||
3585 | 299 | |||
3586 | 300 | :param plugin_name: The name of the compiz plugin where the option is | ||
3587 | 301 | registered. If the option is not in a plugin, the string "core" should | ||
3588 | 302 | be used as the plugin name. | ||
3589 | 303 | :param option_name: The name of the unity option. | ||
3590 | 304 | :param option_value: The value you want to set. | ||
3591 | 305 | :raises: **KeyError** if the option named does not exist. | ||
3592 | 306 | |||
3593 | 307 | """ | ||
3594 | 308 | old_value = self._set_compiz_option(plugin_name, option_name, option_value) | ||
3595 | 309 | # Cleanup is LIFO, during clean-up also allow unity to respond | ||
3596 | 310 | self.addCleanup(time.sleep, 0.5) | ||
3597 | 311 | self.addCleanup(self._set_compiz_option, plugin_name, option_name, old_value) | ||
3598 | 312 | # Allow unity time to respond to the new setting. | ||
3599 | 313 | time.sleep(0.5) | ||
3600 | 314 | |||
3601 | 315 | def _set_compiz_option(self, plugin_name, option_name, option_value): | ||
3602 | 316 | logger.info("Setting compiz option '%s' in plugin '%s' to %r", | ||
3603 | 317 | option_name, plugin_name, option_value) | ||
3604 | 318 | setting = get_compiz_setting(plugin_name, option_name) | ||
3605 | 319 | old_value = setting.Value | ||
3606 | 320 | setting.Value = option_value | ||
3607 | 321 | get_global_context().Write() | ||
3608 | 322 | return old_value | ||
3609 | 323 | |||
3610 | 324 | @classmethod | ||
3611 | 325 | def register_known_application(cls, name, desktop_file, process_name): | ||
3612 | 326 | """Register an application with autopilot. | ||
3613 | 327 | |||
3614 | 328 | After calling this method, you may call :meth:`start_app` or | ||
3615 | 329 | :meth:`start_app_window` with the `name` parameter to start this | ||
3616 | 330 | application. | ||
3617 | 331 | You need only call this once within a test run - the application will | ||
3618 | 332 | remain registerred until the test run ends. | ||
3619 | 333 | |||
3620 | 334 | :param name: The name to be used when launching the application. | ||
3621 | 335 | :param desktop_file: The filename (without path component) of the desktop file used to launch the application. | ||
3622 | 336 | :param process_name: The name of the executable process that gets run. | ||
3623 | 337 | :raises: **KeyError** if application has been registered already | ||
3624 | 338 | |||
3625 | 339 | """ | ||
3626 | 340 | if name in cls.KNOWN_APPS: | ||
3627 | 341 | raise KeyError("Application has been registered already") | ||
3628 | 342 | else: | ||
3629 | 343 | cls.KNOWN_APPS[name] = { | ||
3630 | 344 | "desktop-file" : desktop_file, | ||
3631 | 345 | "process-name" : process_name | ||
3632 | 346 | } | ||
3633 | 347 | |||
3634 | 348 | @classmethod | ||
3635 | 349 | def unregister_known_application(cls, name): | ||
3636 | 350 | """Unregister an application with the known_apps dictionary. | ||
3637 | 351 | |||
3638 | 352 | :param name: The name to be used when launching the application. | ||
3639 | 353 | :raises: **KeyError** if the application has not been registered. | ||
3640 | 354 | |||
3641 | 355 | """ | ||
3642 | 356 | if name in cls.KNOWN_APPS: | ||
3643 | 357 | del cls.KNOWN_APPS[name] | ||
3644 | 358 | else: | ||
3645 | 359 | raise KeyError("Application has not been registered") | ||
3646 | 360 | |||
3647 | 361 | def start_app(self, app_name, files=[], locale=None): | ||
3648 | 362 | """Start one of the known applications, and kill it on tear down. | ||
3649 | 363 | |||
3650 | 364 | .. warning:: This method will clear all instances of this application on | ||
3651 | 365 | tearDown, not just the one opened by this method! We recommend that | ||
3652 | 366 | you use the :meth:`start_app_window` method instead, as it is generally | ||
3653 | 367 | safer. | ||
3654 | 368 | |||
3655 | 369 | :param app_name: The application name. *This name must either already | ||
3656 | 370 | be registered as one of the built-in applications that are supported | ||
3657 | 371 | by autopilot, or must have been registered using* | ||
3658 | 372 | :meth:`register_known_application` *beforehand.* | ||
3659 | 373 | :param files: (Optional) A list of paths to open with the | ||
3660 | 374 | given application. *Not all applications support opening files in this | ||
3661 | 375 | way.* | ||
3662 | 376 | :param locale: (Optional) The locale will to set when the application | ||
3663 | 377 | is launched. *If you want to launch an application without any | ||
3664 | 378 | localisation being applied, set this parameter to 'C'.* | ||
3665 | 379 | :returns: A :class:`~autopilot.emulators.bamf.BamfApplication` instance. | ||
3666 | 380 | |||
3667 | 381 | """ | ||
3668 | 382 | window = self._open_window(app_name, files, locale) | ||
3669 | 383 | if window: | ||
3670 | 384 | self.addCleanup(self.close_all_app, app_name) | ||
3671 | 385 | return window.application | ||
3672 | 386 | |||
3673 | 387 | raise AssertionError("No new application window was opened.") | ||
3674 | 388 | |||
3675 | 389 | def start_app_window(self, app_name, files=[], locale=None): | ||
3676 | 390 | """Open a single window for one of the known applications, and close it | ||
3677 | 391 | at the end of the test. | ||
3678 | 392 | |||
3679 | 393 | :param app_name: The application name. *This name must either already | ||
3680 | 394 | be registered as one of the built-in applications that are supported | ||
3681 | 395 | by autopilot, or must have been registered with* | ||
3682 | 396 | :meth:`register_known_application` *beforehand.* | ||
3683 | 397 | :param files: (Optional) Should be a list of paths to open with the | ||
3684 | 398 | given application. *Not all applications support opening files in this | ||
3685 | 399 | way.* | ||
3686 | 400 | :param locale: (Optional) The locale will to set when the application | ||
3687 | 401 | is launched. *If you want to launch an application without any | ||
3688 | 402 | localisation being applied, set this parameter to 'C'.* | ||
3689 | 403 | :raises: **AssertionError** if no window was opened, or more than one | ||
3690 | 404 | window was opened. | ||
3691 | 405 | :returns: A :class:`~autopilot.emulators.bamf.BamfWindow` instance. | ||
3692 | 406 | |||
3693 | 407 | """ | ||
3694 | 408 | window = self._open_window(app_name, files, locale) | ||
3695 | 409 | if window: | ||
3696 | 410 | self.addCleanup(window.close) | ||
3697 | 411 | return window | ||
3698 | 412 | raise AssertionError("No window was opened.") | ||
3699 | 413 | |||
3700 | 414 | def _open_window(self, app_name, files, locale): | ||
3701 | 415 | """Open a new 'app_name' window, returning the window instance or None. | ||
3702 | 416 | |||
3703 | 417 | Raises an AssertionError if this creates more than one window. | ||
3704 | 418 | |||
3705 | 419 | """ | ||
3706 | 420 | existing_windows = self.get_open_windows_by_application(app_name) | ||
3707 | 421 | |||
3708 | 422 | if locale: | ||
3709 | 423 | os.putenv("LC_ALL", locale) | ||
3710 | 424 | self.addCleanup(os.unsetenv, "LC_ALL") | ||
3711 | 425 | logger.info("Starting application '%s' with files %r in locale %s", app_name, files, locale) | ||
3712 | 426 | else: | ||
3713 | 427 | logger.info("Starting application '%s' with files %r", app_name, files) | ||
3714 | 428 | |||
3715 | 429 | |||
3716 | 430 | app = self.KNOWN_APPS[app_name] | ||
3717 | 431 | self.bamf.launch_application(app['desktop-file'], files) | ||
3718 | 432 | apps = self.bamf.get_running_applications_by_desktop_file(app['desktop-file']) | ||
3719 | 433 | |||
3730 | 434 | for i in range(10): | 127 | for i in range(10): |
3775 | 435 | try: | 128 | current_apps = self.process_manager.get_running_applications() |
3776 | 436 | new_windows = [] | 129 | new_apps = filter(lambda i: i not in self._app_snapshot, current_apps) |
3777 | 437 | [new_windows.extend(a.get_windows()) for a in apps] | 130 | if not new_apps: |
3778 | 438 | filter_fn = lambda w: w.x_id not in [c.x_id for c in existing_windows] | 131 | self._app_snapshot = None |
3779 | 439 | new_wins = filter(filter_fn, new_windows) | 132 | return |
3780 | 440 | if new_wins: | 133 | sleep(1) |
3781 | 441 | assert len(new_wins) == 1 | 134 | self._app_snapshot = None |
3782 | 442 | return new_wins[0] | 135 | raise AssertionError("The following apps were started during the test and not closed: %r", new_apps) |
3739 | 443 | except DBusException: | ||
3740 | 444 | pass | ||
3741 | 445 | time.sleep(1) | ||
3742 | 446 | return None | ||
3743 | 447 | |||
3744 | 448 | def get_open_windows_by_application(self, app_name): | ||
3745 | 449 | """Get a list of BamfWindow instances for the given application name. | ||
3746 | 450 | |||
3747 | 451 | :param app_name: The name of one of the well-known applications. | ||
3748 | 452 | :returns: A list of :class:`~autopilot.emulators.bamf.BamfWindow` | ||
3749 | 453 | instances. | ||
3750 | 454 | |||
3751 | 455 | """ | ||
3752 | 456 | existing_windows = [] | ||
3753 | 457 | [existing_windows.extend(a.get_windows()) for a in self.get_app_instances(app_name)] | ||
3754 | 458 | return existing_windows | ||
3755 | 459 | |||
3756 | 460 | def close_all_app(self, app_name): | ||
3757 | 461 | """Close all instances of the application 'app_name'.""" | ||
3758 | 462 | app = self.KNOWN_APPS[app_name] | ||
3759 | 463 | try: | ||
3760 | 464 | pids = check_output(["pidof", app['process-name']]).split() | ||
3761 | 465 | if len(pids): | ||
3762 | 466 | call(["kill"] + pids) | ||
3763 | 467 | except CalledProcessError: | ||
3764 | 468 | logger.warning("Tried to close applicaton '%s' but it wasn't running.", app_name) | ||
3765 | 469 | |||
3766 | 470 | def get_app_instances(self, app_name): | ||
3767 | 471 | """Get BamfApplication instances for app_name.""" | ||
3768 | 472 | desktop_file = self.KNOWN_APPS[app_name]['desktop-file'] | ||
3769 | 473 | return self.bamf.get_running_applications_by_desktop_file(desktop_file) | ||
3770 | 474 | |||
3771 | 475 | def app_is_running(self, app_name): | ||
3772 | 476 | """Return true if an instance of the application is running.""" | ||
3773 | 477 | apps = self.get_app_instances(app_name) | ||
3774 | 478 | return len(apps) > 0 | ||
3783 | 479 | 136 | ||
3784 | 480 | def patch_environment(self, key, value): | 137 | def patch_environment(self, key, value): |
3785 | 481 | """Patch the process environment, setting *key* with value *value*. | 138 | """Patch the process environment, setting *key* with value *value*. |
3786 | @@ -513,12 +170,13 @@ | |||
3787 | 513 | 170 | ||
3788 | 514 | .. note:: Minimised windows are skipped. | 171 | .. note:: Minimised windows are skipped. |
3789 | 515 | 172 | ||
3791 | 516 | :param stack_start: An iterable of BamfWindow instances. | 173 | :param stack_start: An iterable of |
3792 | 174 | `~autopilot.process.Window` instances. | ||
3793 | 517 | :raises: **AssertionError** if the top of the window stack does not | 175 | :raises: **AssertionError** if the top of the window stack does not |
3794 | 518 | match the contents of the stack_start parameter. | 176 | match the contents of the stack_start parameter. |
3795 | 519 | 177 | ||
3796 | 520 | """ | 178 | """ |
3798 | 521 | stack = [win for win in self.bamf.get_open_windows() if not win.is_hidden] | 179 | stack = [win for win in self.process_manager.get_open_windows() if not win.is_hidden] |
3799 | 522 | for pos, win in enumerate(stack_start): | 180 | for pos, win in enumerate(stack_start): |
3800 | 523 | self.assertThat(stack[pos].x_id, Equals(win.x_id), | 181 | self.assertThat(stack[pos].x_id, Equals(win.x_id), |
3801 | 524 | "%r at %d does not equal %r" % (stack[pos], pos, win)) | 182 | "%r at %d does not equal %r" % (stack[pos], pos, win)) |
3802 | @@ -531,7 +189,7 @@ | |||
3803 | 531 | the autopilot DBus interface). | 189 | the autopilot DBus interface). |
3804 | 532 | 190 | ||
3805 | 533 | For example, from within a test, to assert certain properties on a | 191 | For example, from within a test, to assert certain properties on a |
3807 | 534 | BamfWindow instance:: | 192 | `~autopilot.process.Window` instance:: |
3808 | 535 | 193 | ||
3809 | 536 | self.assertProperty(my_window, is_maximized=True) | 194 | self.assertProperty(my_window, is_maximized=True) |
3810 | 537 | 195 | ||
3811 | @@ -561,3 +219,83 @@ | |||
3812 | 561 | self.assertThat(lambda: getattr(obj, prop_name), Eventually(Equals(desired_value))) | 219 | self.assertThat(lambda: getattr(obj, prop_name), Eventually(Equals(desired_value))) |
3813 | 562 | 220 | ||
3814 | 563 | assertProperties = assertProperty | 221 | assertProperties = assertProperty |
3815 | 222 | |||
3816 | 223 | def launch_test_application(self, application, *arguments, **kwargs): | ||
3817 | 224 | """Launch ``application`` and return a proxy object for the application. | ||
3818 | 225 | |||
3819 | 226 | Use this method to launch an application and start testing it. The | ||
3820 | 227 | positional arguments are used as arguments to the application to lanch. | ||
3821 | 228 | Keyword arguments are used to control the manner in which the application | ||
3822 | 229 | is launched. | ||
3823 | 230 | |||
3824 | 231 | This method is designed to be flexible enough to launch all supported | ||
3825 | 232 | types of applications. For example, to launch a traditional Gtk application, | ||
3826 | 233 | a test might start with:: | ||
3827 | 234 | |||
3828 | 235 | app_proxy = self.launch_test_application('gedit') | ||
3829 | 236 | |||
3830 | 237 | ... a Qt4 Qml application might be launched like this:: | ||
3831 | 238 | |||
3832 | 239 | app_proxy = self.launch_test_application('qmlviewer', 'my_scene.qml') | ||
3833 | 240 | |||
3834 | 241 | ... a Qt5 Qml application is launched in a similar fashion:: | ||
3835 | 242 | |||
3836 | 243 | app_proxy = self.launch_test_application('qmlscene', 'my_scene.qml') | ||
3837 | 244 | |||
3838 | 245 | :param application: The application to launch. The application can be | ||
3839 | 246 | specified as: | ||
3840 | 247 | |||
3841 | 248 | * A full, absolute path to an executable file. (``/usr/bin/gedit``) | ||
3842 | 249 | * A relative path to an executable file. (``./build/my_app``) | ||
3843 | 250 | * An app name, which will be searched for in $PATH (``my_app``) | ||
3844 | 251 | |||
3845 | 252 | :keyword launch_dir: If set to a directory that exists the process will be | ||
3846 | 253 | launched from that directory. | ||
3847 | 254 | |||
3848 | 255 | :keyword capture_output: If set to True (the default), the process output | ||
3849 | 256 | will be captured and attached to the test as test detail. | ||
3850 | 257 | |||
3851 | 258 | :raises: **ValueError** if unknown keyword arguments are passed. | ||
3852 | 259 | :return: A proxy object that represents the application. Introspection | ||
3853 | 260 | data is retrievable via this object. | ||
3854 | 261 | |||
3855 | 262 | """ | ||
3856 | 263 | # first, we get a launcher. Tests can override this if they need: | ||
3857 | 264 | launcher = self.pick_app_launcher(application) | ||
3858 | 265 | if launcher is None: | ||
3859 | 266 | raise RuntimeError("Autopilot could not determine the correct \ | ||
3860 | 267 | introspection type to use. You can specify one by overriding \ | ||
3861 | 268 | the AutopilotTestCase.pick_app_launcher method.") | ||
3862 | 269 | process = launch_application(launcher, application, *arguments, **kwargs) | ||
3863 | 270 | self.addCleanup(self._kill_process_and_attach_logs, process) | ||
3864 | 271 | return get_autopilot_proxy_object_for_process(process) | ||
3865 | 272 | |||
3866 | 273 | def pick_app_launcher(self, app_path): | ||
3867 | 274 | """Given an application path, return an object suitable for launching | ||
3868 | 275 | the application. | ||
3869 | 276 | |||
3870 | 277 | This function attempts to guess what kind of application you are | ||
3871 | 278 | launching. If, for some reason the default implementation returns the | ||
3872 | 279 | wrong launcher, test authors may override this method to provide their | ||
3873 | 280 | own implemetnation. | ||
3874 | 281 | |||
3875 | 282 | The default implementation calls | ||
3876 | 283 | :py:func:`autopilot.introspection.get_application_launcher` | ||
3877 | 284 | |||
3878 | 285 | """ | ||
3879 | 286 | # default implementation is in autopilot.introspection: | ||
3880 | 287 | return get_application_launcher(app_path) | ||
3881 | 288 | |||
3882 | 289 | def _kill_process_and_attach_logs(self, process): | ||
3883 | 290 | process.kill() | ||
3884 | 291 | logger.info("waiting for process to exit.") | ||
3885 | 292 | for i in range(10): | ||
3886 | 293 | if process.returncode is not None: | ||
3887 | 294 | break | ||
3888 | 295 | if i == 9: | ||
3889 | 296 | logger.info("Terminating process group, since it hasn't exited after 10 seconds.") | ||
3890 | 297 | os.killpg(process.pid, signal.SIGTERM) | ||
3891 | 298 | sleep(1) | ||
3892 | 299 | stdout, stderr = process.communicate() | ||
3893 | 300 | self.addDetail('process-stdout', text_content(stdout)) | ||
3894 | 301 | self.addDetail('process-stderr', text_content(stderr)) | ||
3895 | 564 | 302 | ||
3896 | === modified file 'autopilot/tests/test_ap_apps.py' | |||
3897 | --- autopilot/tests/test_ap_apps.py 2013-02-22 03:59:51 +0000 | |||
3898 | +++ autopilot/tests/test_ap_apps.py 2013-04-15 21:43:32 +0000 | |||
3899 | @@ -13,8 +13,7 @@ | |||
3900 | 13 | from textwrap import dedent | 13 | from textwrap import dedent |
3901 | 14 | 14 | ||
3902 | 15 | from autopilot.testcase import AutopilotTestCase | 15 | from autopilot.testcase import AutopilotTestCase |
3905 | 16 | from autopilot.introspection.gtk import GtkIntrospectionTestMixin | 16 | from autopilot.introspection.gtk import GtkApplicationLauncher |
3904 | 17 | from autopilot.introspection.qt import QtIntrospectionTestMixin | ||
3906 | 18 | 17 | ||
3907 | 19 | 18 | ||
3908 | 20 | class ApplicationTests(AutopilotTestCase): | 19 | class ApplicationTests(AutopilotTestCase): |
3909 | @@ -33,15 +32,20 @@ | |||
3910 | 33 | return path | 32 | return path |
3911 | 34 | 33 | ||
3912 | 35 | 34 | ||
3914 | 36 | class QtTests(ApplicationTests, QtIntrospectionTestMixin): | 35 | class QtTests(ApplicationTests): |
3915 | 37 | 36 | ||
3916 | 38 | def setUp(self): | 37 | def setUp(self): |
3917 | 39 | super(QtTests, self).setUp() | 38 | super(QtTests, self).setUp() |
3918 | 40 | 39 | ||
3919 | 41 | try: | 40 | try: |
3921 | 42 | self.app_path = subprocess.check_output(['which','qmlviewer']).strip() | 41 | self.app_path = subprocess.check_output(['which','qmlscene']).strip() |
3922 | 43 | except subprocess.CalledProcessError: | 42 | except subprocess.CalledProcessError: |
3924 | 44 | self.skip("qmlviewer not found.") | 43 | self.skip("qmlscene not found.") |
3925 | 44 | |||
3926 | 45 | def pick_app_launcher(self, app_path): | ||
3927 | 46 | # force Qt app introspection: | ||
3928 | 47 | from autopilot.introspection.qt import QtApplicationLauncher | ||
3929 | 48 | return QtApplicationLauncher() | ||
3930 | 45 | 49 | ||
3931 | 46 | def test_can_launch_qt_app(self): | 50 | def test_can_launch_qt_app(self): |
3932 | 47 | app_proxy = self.launch_test_application(self.app_path) | 51 | app_proxy = self.launch_test_application(self.app_path) |
3933 | @@ -83,7 +87,7 @@ | |||
3934 | 83 | self.assertTrue(app_proxy is not None) | 87 | self.assertTrue(app_proxy is not None) |
3935 | 84 | 88 | ||
3936 | 85 | 89 | ||
3938 | 86 | class GtkTests(ApplicationTests, GtkIntrospectionTestMixin): | 90 | class GtkTests(ApplicationTests): |
3939 | 87 | 91 | ||
3940 | 88 | def setUp(self): | 92 | def setUp(self): |
3941 | 89 | super(GtkTests, self).setUp() | 93 | super(GtkTests, self).setUp() |
3942 | 90 | 94 | ||
3943 | === modified file 'autopilot/tests/test_application_mixin.py' | |||
3944 | --- autopilot/tests/test_application_mixin.py 2012-09-13 02:28:04 +0000 | |||
3945 | +++ autopilot/tests/test_application_mixin.py 2013-04-15 21:43:32 +0000 | |||
3946 | @@ -8,45 +8,33 @@ | |||
3947 | 8 | 8 | ||
3948 | 9 | from __future__ import absolute_import | 9 | from __future__ import absolute_import |
3949 | 10 | 10 | ||
3956 | 11 | from testtools import TestCase | 11 | from autopilot.testcase import AutopilotTestCase |
3957 | 12 | from testtools.matchers import Equals, Is, Not, raises | 12 | from testtools.matchers import Is, Not, raises |
3952 | 13 | from mock import patch | ||
3953 | 14 | |||
3954 | 15 | from autopilot.introspection.qt import QtIntrospectionTestMixin | ||
3955 | 16 | |||
3958 | 17 | 13 | ||
3959 | 18 | def dummy_addCleanup(*args, **kwargs): | 14 | def dummy_addCleanup(*args, **kwargs): |
3960 | 19 | pass | 15 | pass |
3961 | 20 | 16 | ||
3962 | 21 | 17 | ||
3968 | 22 | class ApplicationSupportTests(TestCase): | 18 | class ApplicationSupportTests(AutopilotTestCase): |
3964 | 23 | |||
3965 | 24 | def test_can_create(self): | ||
3966 | 25 | mixin = QtIntrospectionTestMixin() | ||
3967 | 26 | self.assertThat(mixin, Not(Is(None))) | ||
3969 | 27 | 19 | ||
3970 | 28 | def test_launch_with_bad_types_raises_typeerror(self): | 20 | def test_launch_with_bad_types_raises_typeerror(self): |
3971 | 29 | """Calling launch_test_application with something other than a string must | 21 | """Calling launch_test_application with something other than a string must |
3972 | 30 | raise a TypeError""" | 22 | raise a TypeError""" |
3973 | 31 | 23 | ||
3984 | 32 | mixin = QtIntrospectionTestMixin() | 24 | self.assertThat(lambda: self.launch_test_application(1), raises(TypeError)) |
3985 | 33 | mixin.addCleanup = dummy_addCleanup | 25 | self.assertThat(lambda: self.launch_test_application(True), raises(TypeError)) |
3986 | 34 | 26 | self.assertThat(lambda: self.launch_test_application(1.0), raises(TypeError)) | |
3987 | 35 | self.assertThat(lambda: mixin.launch_test_application(1), raises(TypeError)) | 27 | self.assertThat(lambda: self.launch_test_application(object()), raises(TypeError)) |
3988 | 36 | self.assertThat(lambda: mixin.launch_test_application(True), raises(TypeError)) | 28 | self.assertThat(lambda: self.launch_test_application(None), raises(TypeError)) |
3989 | 37 | self.assertThat(lambda: mixin.launch_test_application(1.0), raises(TypeError)) | 29 | self.assertThat(lambda: self.launch_test_application([]), raises(TypeError)) |
3990 | 38 | self.assertThat(lambda: mixin.launch_test_application(object()), raises(TypeError)) | 30 | self.assertThat(lambda: self.launch_test_application((None,)), raises(TypeError)) |
3981 | 39 | self.assertThat(lambda: mixin.launch_test_application(None), raises(TypeError)) | ||
3982 | 40 | self.assertThat(lambda: mixin.launch_test_application([]), raises(TypeError)) | ||
3983 | 41 | self.assertThat(lambda: mixin.launch_test_application((None,)), raises(TypeError)) | ||
3991 | 42 | 31 | ||
3992 | 43 | def test_launch_raises_ValueError_on_unknown_kwargs(self): | 32 | def test_launch_raises_ValueError_on_unknown_kwargs(self): |
3993 | 44 | """launch_test_application must raise ValueError when given unknown | 33 | """launch_test_application must raise ValueError when given unknown |
3994 | 45 | keyword arguments. | 34 | keyword arguments. |
3995 | 46 | 35 | ||
3996 | 47 | """ | 36 | """ |
3999 | 48 | mixin = QtIntrospectionTestMixin() | 37 | fn = lambda: self.launch_test_application('gedit', arg1=123, arg2='asd') |
3998 | 49 | fn = lambda: mixin.launch_test_application('gedit', arg1=123, arg2='asd') | ||
4000 | 50 | self.assertThat(fn, raises(ValueError("Unknown keyword arguments: 'arg1', 'arg2'."))) | 38 | self.assertThat(fn, raises(ValueError("Unknown keyword arguments: 'arg1', 'arg2'."))) |
4001 | 51 | 39 | ||
4002 | 52 | def test_launch_raises_ValueError_on_unknown_kwargs_with_known(self): | 40 | def test_launch_raises_ValueError_on_unknown_kwargs_with_known(self): |
4003 | @@ -54,6 +42,5 @@ | |||
4004 | 54 | keyword arguments. | 42 | keyword arguments. |
4005 | 55 | 43 | ||
4006 | 56 | """ | 44 | """ |
4009 | 57 | mixin = QtIntrospectionTestMixin() | 45 | fn = lambda: self.launch_test_application('gedit', arg1=123, arg2='asd', launch_dir='/') |
4008 | 58 | fn = lambda: mixin.launch_test_application('gedit', arg1=123, arg2='asd', launch_dir='/') | ||
4010 | 59 | self.assertThat(fn, raises(ValueError("Unknown keyword arguments: 'arg1', 'arg2'."))) | 46 | self.assertThat(fn, raises(ValueError("Unknown keyword arguments: 'arg1', 'arg2'."))) |
4011 | 60 | 47 | ||
4012 | === removed file 'autopilot/tests/test_application_registration.py' | |||
4013 | --- autopilot/tests/test_application_registration.py 2012-09-30 22:39:30 +0000 | |||
4014 | +++ autopilot/tests/test_application_registration.py 1970-01-01 00:00:00 +0000 | |||
4015 | @@ -1,94 +0,0 @@ | |||
4016 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
4017 | 2 | # Copyright 2012 Canonical | ||
4018 | 3 | # Author: Thomi Richards | ||
4019 | 4 | # | ||
4020 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
4021 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
4022 | 7 | # by the Free Software Foundation. | ||
4023 | 8 | |||
4024 | 9 | from __future__ import absolute_import | ||
4025 | 10 | |||
4026 | 11 | from testtools import TestCase | ||
4027 | 12 | from testtools.matchers import Equals, Is, Not, raises, Contains | ||
4028 | 13 | from mock import patch | ||
4029 | 14 | |||
4030 | 15 | from autopilot.testcase import AutopilotTestCase | ||
4031 | 16 | |||
4032 | 17 | |||
4033 | 18 | def safe_unregister_application(test_case_class, app_name): | ||
4034 | 19 | if app_name in test_case_class.KNOWN_APPS: | ||
4035 | 20 | test_case_class.unregister_known_application(app_name) | ||
4036 | 21 | |||
4037 | 22 | class ApplicationRegistrationTests(TestCase): | ||
4038 | 23 | |||
4039 | 24 | def test_can_register_new_application(self): | ||
4040 | 25 | AutopilotTestCase.register_known_application( | ||
4041 | 26 | "NewApplicationName", | ||
4042 | 27 | "newapp.desktop", | ||
4043 | 28 | "newapp") | ||
4044 | 29 | self.addCleanup(safe_unregister_application, | ||
4045 | 30 | AutopilotTestCase, | ||
4046 | 31 | "NewApplicationName") | ||
4047 | 32 | |||
4048 | 33 | app_details = AutopilotTestCase.KNOWN_APPS['NewApplicationName'] | ||
4049 | 34 | |||
4050 | 35 | self.assertThat(AutopilotTestCase.KNOWN_APPS, Contains("NewApplicationName")) | ||
4051 | 36 | self.assertTrue(type(app_details) is dict) | ||
4052 | 37 | self.assertThat(app_details, Contains('desktop-file')) | ||
4053 | 38 | self.assertThat(app_details, Contains('process-name')) | ||
4054 | 39 | self.assertThat(app_details['desktop-file'], Equals('newapp.desktop')) | ||
4055 | 40 | self.assertThat(app_details['process-name'], Equals('newapp')) | ||
4056 | 41 | |||
4057 | 42 | def test_registering_app_twice_raises_KeyError(self): | ||
4058 | 43 | """Registering an application with the same app name as one that's | ||
4059 | 44 | already in the dictionary must raise KeyError and not change the | ||
4060 | 45 | dictionary. | ||
4061 | 46 | |||
4062 | 47 | """ | ||
4063 | 48 | AutopilotTestCase.register_known_application( | ||
4064 | 49 | "NewApplicationName", | ||
4065 | 50 | "newapp.desktop", | ||
4066 | 51 | "newapp") | ||
4067 | 52 | self.addCleanup(safe_unregister_application, | ||
4068 | 53 | AutopilotTestCase, | ||
4069 | 54 | "NewApplicationName") | ||
4070 | 55 | |||
4071 | 56 | app_details = AutopilotTestCase.KNOWN_APPS['NewApplicationName'] | ||
4072 | 57 | register_fn = lambda: AutopilotTestCase.register_known_application( | ||
4073 | 58 | "NewApplicationName", | ||
4074 | 59 | "newapp2.desktop", | ||
4075 | 60 | "newapp2") | ||
4076 | 61 | |||
4077 | 62 | self.assertThat(register_fn, raises( | ||
4078 | 63 | KeyError("Application has been registered already"))) | ||
4079 | 64 | self.assertThat(AutopilotTestCase.KNOWN_APPS, Contains("NewApplicationName")) | ||
4080 | 65 | self.assertTrue(type(app_details) is dict) | ||
4081 | 66 | self.assertThat(app_details, Contains('desktop-file')) | ||
4082 | 67 | self.assertThat(app_details, Contains('process-name')) | ||
4083 | 68 | self.assertThat(app_details['desktop-file'], Equals('newapp.desktop')) | ||
4084 | 69 | self.assertThat(app_details['process-name'], Equals('newapp')) | ||
4085 | 70 | |||
4086 | 71 | def test_can_unregister_application(self): | ||
4087 | 72 | AutopilotTestCase.register_known_application( | ||
4088 | 73 | "NewApplicationName", | ||
4089 | 74 | "newapp.desktop", | ||
4090 | 75 | "newapp") | ||
4091 | 76 | self.addCleanup(safe_unregister_application, | ||
4092 | 77 | AutopilotTestCase, | ||
4093 | 78 | "NewApplicationName") | ||
4094 | 79 | |||
4095 | 80 | AutopilotTestCase.unregister_known_application("NewApplicationName") | ||
4096 | 81 | |||
4097 | 82 | self.assertThat(AutopilotTestCase.KNOWN_APPS, | ||
4098 | 83 | Not(Contains("NewApplicationName"))) | ||
4099 | 84 | |||
4100 | 85 | def test_unregistering_unknown_application_raises_KeyError(self): | ||
4101 | 86 | """Trying to unregister an application that is not already registered | ||
4102 | 87 | must raise a KeyError. | ||
4103 | 88 | |||
4104 | 89 | """ | ||
4105 | 90 | |||
4106 | 91 | unregister_fn = lambda: AutopilotTestCase.unregister_known_application("FooBarBaz") | ||
4107 | 92 | |||
4108 | 93 | self.assertThat(unregister_fn, raises(KeyError("Application has not been registered"))) | ||
4109 | 94 | |||
4110 | 95 | 0 | ||
4111 | === removed file 'autopilot/tests/test_compiz_key_translate.py' | |||
4112 | --- autopilot/tests/test_compiz_key_translate.py 2012-05-08 16:14:53 +0000 | |||
4113 | +++ autopilot/tests/test_compiz_key_translate.py 1970-01-01 00:00:00 +0000 | |||
4114 | @@ -1,69 +0,0 @@ | |||
4115 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
4116 | 2 | # Copyright 2012 Canonical | ||
4117 | 3 | # Author: Thomi Richards | ||
4118 | 4 | # | ||
4119 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
4120 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
4121 | 7 | # by the Free Software Foundation. | ||
4122 | 8 | |||
4123 | 9 | from __future__ import absolute_import | ||
4124 | 10 | |||
4125 | 11 | from testscenarios import TestWithScenarios | ||
4126 | 12 | from testtools import TestCase | ||
4127 | 13 | from testtools.matchers import raises, Equals | ||
4128 | 14 | |||
4129 | 15 | from autopilot.keybindings import _translate_compiz_keystroke_string as translate_func | ||
4130 | 16 | |||
4131 | 17 | class KeyTranslateArgumentTests(TestWithScenarios, TestCase): | ||
4132 | 18 | """Tests that the compizconfig keycode translation routes work as advertised.""" | ||
4133 | 19 | |||
4134 | 20 | scenarios = [ | ||
4135 | 21 | ('bool', {'input': True}), | ||
4136 | 22 | ('int', {'input': 42}), | ||
4137 | 23 | ('float', {'input': 0.321}), | ||
4138 | 24 | ('none', {'input': None}), | ||
4139 | 25 | ] | ||
4140 | 26 | |||
4141 | 27 | def test_requires_string_instance(self): | ||
4142 | 28 | """Function must raise TypeError unless given an instance of basestring.""" | ||
4143 | 29 | self.assertThat(lambda: translate_func(self.input), raises(TypeError)) | ||
4144 | 30 | |||
4145 | 31 | |||
4146 | 32 | class TranslationTests(TestWithScenarios, TestCase): | ||
4147 | 33 | """Test that we get the result we expect, with the given input.""" | ||
4148 | 34 | |||
4149 | 35 | scenarios = [ | ||
4150 | 36 | ('empty string', dict(input='', expected='')), | ||
4151 | 37 | ('single simpe letter', dict(input='a', expected='a')), | ||
4152 | 38 | ('trailing space', dict(input='d ', expected='d')), | ||
4153 | 39 | ('only whitespace', dict(input='\t\n ', expected='')), | ||
4154 | 40 | ('special key: Ctrl', dict(input='<Control>', expected='Ctrl')), | ||
4155 | 41 | ('special key: Primary', dict(input='<Primary>', expected='Ctrl')), | ||
4156 | 42 | ('special key: Alt', dict(input='<Alt>', expected='Alt')), | ||
4157 | 43 | ('special key: Shift', dict(input='<Shift>', expected='Shift')), | ||
4158 | 44 | ('direction key up', dict(input='Up', expected='Up')), | ||
4159 | 45 | ('direction key down', dict(input='Down', expected='Down')), | ||
4160 | 46 | ('direction key left', dict(input='Left', expected='Left')), | ||
4161 | 47 | ('direction key right', dict(input='Right', expected='Right')), | ||
4162 | 48 | ('Ctrl+a', dict(input='<Control>a', expected='Ctrl+a')), | ||
4163 | 49 | ('Primary+a', dict(input='<Control>a', expected='Ctrl+a')), | ||
4164 | 50 | ('Shift+s', dict(input='<Shift>s', expected='Shift+s')), | ||
4165 | 51 | ('Alt+d', dict(input='<Alt>d', expected='Alt+d')), | ||
4166 | 52 | ('Super+w', dict(input='<Super>w', expected='Super+w')), | ||
4167 | 53 | ('Ctrl+Up', dict(input='<Control>Up', expected='Ctrl+Up')), | ||
4168 | 54 | ('Primary+Down', dict(input='<Control>Down', expected='Ctrl+Down')), | ||
4169 | 55 | ('Alt+Left', dict(input='<Alt>Left', expected='Alt+Left')), | ||
4170 | 56 | ('Shift+F3', dict(input='<Shift>F3', expected='Shift+F3')), | ||
4171 | 57 | ('duplicate keys Ctrl+Ctrl', dict(input='<Control><Control>', expected='Ctrl')), | ||
4172 | 58 | ('duplicate keys Ctrl+Primary', dict(input='<Control><Primary>', expected='Ctrl')), | ||
4173 | 59 | ('duplicate keys Ctrl+Primary', dict(input='<Primary><Control>', expected='Ctrl')), | ||
4174 | 60 | ('duplicate keys Alt+Alt', dict(input='<Alt><Alt>', expected='Alt')), | ||
4175 | 61 | ('duplicate keys Ctrl+Primary+left', dict(input='<Control><Primary>Left', expected='Ctrl+Left')), | ||
4176 | 62 | ('first key wins', dict(input='<Control><Alt>Down<Alt>', expected='Ctrl+Alt+Down')), | ||
4177 | 63 | ('Getting silly now', dict(input='<Control><Primary><Shift><Shift><Alt>Left', expected='Ctrl+Shift+Alt+Left')), | ||
4178 | 64 | ] | ||
4179 | 65 | |||
4180 | 66 | def test_translation(self): | ||
4181 | 67 | self.assertThat(translate_func(self.input), Equals(self.expected)) | ||
4182 | 68 | |||
4183 | 69 | |||
4184 | 70 | 0 | ||
4185 | === removed file 'autopilot/tests/test_compiz_option_support.py' | |||
4186 | --- autopilot/tests/test_compiz_option_support.py 2012-08-20 03:59:45 +0000 | |||
4187 | +++ autopilot/tests/test_compiz_option_support.py 1970-01-01 00:00:00 +0000 | |||
4188 | @@ -1,31 +0,0 @@ | |||
4189 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
4190 | 2 | # Copyright 2012 Canonical | ||
4191 | 3 | # Author: Thomi Richards | ||
4192 | 4 | # | ||
4193 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
4194 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
4195 | 7 | # by the Free Software Foundation. | ||
4196 | 8 | |||
4197 | 9 | from __future__ import absolute_import | ||
4198 | 10 | |||
4199 | 11 | from testtools.matchers import Equals, raises, Not | ||
4200 | 12 | |||
4201 | 13 | from autopilot.testcase import AutopilotTestCase | ||
4202 | 14 | import logging | ||
4203 | 15 | logger = logging.getLogger(__name__) | ||
4204 | 16 | |||
4205 | 17 | |||
4206 | 18 | |||
4207 | 19 | class CompizConfigOptionTests(AutopilotTestCase): | ||
4208 | 20 | |||
4209 | 21 | def test_set_option_raises_KeyError_on_bad_plugin_name(self): | ||
4210 | 22 | """set_compiz_option must raise KeyError when given a bad plugin name.""" | ||
4211 | 23 | fn = lambda: self.set_compiz_option('rubbishpluginname', 'rubbishsettingname', 'settingvalue') | ||
4212 | 24 | self.assertThat(fn, raises(KeyError("Compiz plugin 'rubbishpluginname' does not exist."))) | ||
4213 | 25 | |||
4214 | 26 | def test_set_option_raises_KeyError_on_bad_setting_name(self): | ||
4215 | 27 | """set_compiz_option must raise KeyError when called with a bad setting name.""" | ||
4216 | 28 | fn = lambda: self.set_compiz_option('core', 'rubbishsettingname', 'settingvalue') | ||
4217 | 29 | self.assertThat(fn, raises(KeyError("Compiz setting 'rubbishsettingname' does not exist in plugin 'core'."))) | ||
4218 | 30 | |||
4219 | 31 | |||
4220 | 32 | 0 | ||
4221 | === modified file 'autopilot/tests/test_keyboard.py' | |||
4222 | --- autopilot/tests/test_keyboard.py 2012-12-04 01:37:07 +0000 | |||
4223 | +++ autopilot/tests/test_keyboard.py 2013-04-15 21:43:32 +0000 | |||
4224 | @@ -30,7 +30,7 @@ | |||
4225 | 30 | 30 | ||
4226 | 31 | def test_keyboard_types_correct_characters(self): | 31 | def test_keyboard_types_correct_characters(self): |
4227 | 32 | """Verify that the keyboard.type method types what we expect.""" | 32 | """Verify that the keyboard.type method types what we expect.""" |
4229 | 33 | self.start_app_window('Terminal') | 33 | self.process_manager.start_app_window('Terminal') |
4230 | 34 | filename = mktemp() | 34 | filename = mktemp() |
4231 | 35 | self.keyboard.type('''python -c "open('%s','w').write(raw_input())"''' % filename) | 35 | self.keyboard.type('''python -c "open('%s','w').write(raw_input())"''' % filename) |
4232 | 36 | self.keyboard.press_and_release('Enter') | 36 | self.keyboard.press_and_release('Enter') |
4233 | @@ -46,7 +46,7 @@ | |||
4234 | 46 | expect. | 46 | expect. |
4235 | 47 | 47 | ||
4236 | 48 | """ | 48 | """ |
4238 | 49 | self.start_app_window('Terminal') | 49 | self.process_manager.start_app_window('Terminal') |
4239 | 50 | filename = mktemp() | 50 | filename = mktemp() |
4240 | 51 | self.keyboard.type('''python -c "open('%s','w').write(raw_input())"''' % filename) | 51 | self.keyboard.type('''python -c "open('%s','w').write(raw_input())"''' % filename) |
4241 | 52 | self.keyboard.press_and_release('Enter') | 52 | self.keyboard.press_and_release('Enter') |
4242 | 53 | 53 | ||
4243 | === modified file 'autopilot/tests/test_mouse_emulator.py' | |||
4244 | --- autopilot/tests/test_mouse_emulator.py 2013-02-28 04:16:14 +0000 | |||
4245 | +++ autopilot/tests/test_mouse_emulator.py 2013-04-15 21:43:32 +0000 | |||
4246 | @@ -10,7 +10,7 @@ | |||
4247 | 10 | from testtools.matchers import Equals, raises | 10 | from testtools.matchers import Equals, raises |
4248 | 11 | from mock import patch | 11 | from mock import patch |
4249 | 12 | 12 | ||
4251 | 13 | from autopilot.emulators.input import get_mouse | 13 | from autopilot.input import Mouse |
4252 | 14 | 14 | ||
4253 | 15 | class Empty(object): | 15 | class Empty(object): |
4254 | 16 | pass | 16 | pass |
4255 | @@ -31,7 +31,7 @@ | |||
4256 | 31 | 31 | ||
4257 | 32 | def setUp(self): | 32 | def setUp(self): |
4258 | 33 | super(MouseEmulatorTests, self).setUp() | 33 | super(MouseEmulatorTests, self).setUp() |
4260 | 34 | self.mouse = get_mouse() | 34 | self.mouse = Mouse.create() |
4261 | 35 | 35 | ||
4262 | 36 | def tearDown(self): | 36 | def tearDown(self): |
4263 | 37 | super(MouseEmulatorTests, self).tearDown() | 37 | super(MouseEmulatorTests, self).tearDown() |
4264 | 38 | 38 | ||
4265 | === modified file 'autopilot/tests/test_open_window.py' | |||
4266 | --- autopilot/tests/test_open_window.py 2012-07-08 23:29:30 +0000 | |||
4267 | +++ autopilot/tests/test_open_window.py 2013-04-15 21:43:32 +0000 | |||
4268 | @@ -11,23 +11,24 @@ | |||
4269 | 11 | from testtools.matchers import Equals | 11 | from testtools.matchers import Equals |
4270 | 12 | 12 | ||
4271 | 13 | from autopilot.testcase import AutopilotTestCase | 13 | from autopilot.testcase import AutopilotTestCase |
4272 | 14 | from autopilot.process import ProcessManager | ||
4273 | 14 | import logging | 15 | import logging |
4274 | 15 | logger = logging.getLogger(__name__) | 16 | logger = logging.getLogger(__name__) |
4275 | 16 | 17 | ||
4276 | 17 | 18 | ||
4277 | 18 | class OpenWindowTests(AutopilotTestCase): | 19 | class OpenWindowTests(AutopilotTestCase): |
4278 | 19 | 20 | ||
4280 | 20 | scenarios = [(k, {'app_name': k}) for k in AutopilotTestCase.KNOWN_APPS.iterkeys()] | 21 | scenarios = [(k, {'app_name': k}) for k in ProcessManager.KNOWN_APPS.iterkeys()] |
4281 | 21 | 22 | ||
4282 | 22 | def test_open_window(self): | 23 | def test_open_window(self): |
4283 | 23 | """self.start_app_window must open a new window of the given app.""" | 24 | """self.start_app_window must open a new window of the given app.""" |
4285 | 24 | existing_apps = self.get_app_instances(self.app_name) | 25 | existing_apps = self.process_manager.get_app_instances(self.app_name) |
4286 | 25 | old_wins = [] | 26 | old_wins = [] |
4287 | 26 | for app in existing_apps: | 27 | for app in existing_apps: |
4288 | 27 | old_wins.extend(app.get_windows()) | 28 | old_wins.extend(app.get_windows()) |
4289 | 28 | logger.debug("Old windows: %r", old_wins) | 29 | logger.debug("Old windows: %r", old_wins) |
4290 | 29 | 30 | ||
4292 | 30 | win = self.start_app_window(self.app_name) | 31 | win = self.process_manager.start_app_window(self.app_name) |
4293 | 31 | logger.debug("New window: %r", win) | 32 | logger.debug("New window: %r", win) |
4294 | 32 | is_new = win.x_id not in [w.x_id for w in old_wins] | 33 | is_new = win.x_id not in [w.x_id for w in old_wins] |
4295 | 33 | self.assertThat(is_new, Equals(True)) | 34 | self.assertThat(is_new, Equals(True)) |
4296 | 34 | 35 | ||
4297 | === added file 'autopilot/tests/test_out_of_test_addcleanup.py' | |||
4298 | --- autopilot/tests/test_out_of_test_addcleanup.py 1970-01-01 00:00:00 +0000 | |||
4299 | +++ autopilot/tests/test_out_of_test_addcleanup.py 2013-04-15 21:43:32 +0000 | |||
4300 | @@ -0,0 +1,34 @@ | |||
4301 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
4302 | 2 | # Copyright 2013 Canonical | ||
4303 | 3 | # Author: Thomi Richards | ||
4304 | 4 | # | ||
4305 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
4306 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
4307 | 7 | # by the Free Software Foundation. | ||
4308 | 8 | |||
4309 | 9 | from testtools import TestCase | ||
4310 | 10 | from testtools.matchers import Equals | ||
4311 | 11 | |||
4312 | 12 | from autopilot.testcase import AutopilotTestCase | ||
4313 | 13 | from autopilot.utilities import addCleanup | ||
4314 | 14 | |||
4315 | 15 | log = '' | ||
4316 | 16 | |||
4317 | 17 | class AddCleanupTests(TestCase): | ||
4318 | 18 | |||
4319 | 19 | def test_addCleanup_called_with_args_and_kwargs(self): | ||
4320 | 20 | """Test that out-of-test addClenaup works as expected, and is passed both | ||
4321 | 21 | args and kwargs. | ||
4322 | 22 | |||
4323 | 23 | """ | ||
4324 | 24 | class InnerTest(AutopilotTestCase): | ||
4325 | 25 | def write_to_log(self, *args, **kwargs): | ||
4326 | 26 | global log | ||
4327 | 27 | log = "Hello %r %r" % (args, kwargs) | ||
4328 | 28 | |||
4329 | 29 | def test_foo(self): | ||
4330 | 30 | addCleanup(self.write_to_log, "arg1", 2, foo='bar') | ||
4331 | 31 | |||
4332 | 32 | InnerTest('test_foo').run() | ||
4333 | 33 | self.assertThat(log, Equals("Hello ('arg1', 2) {'foo': 'bar'}")) | ||
4334 | 34 | |||
4335 | 0 | 35 | ||
4336 | === added file 'autopilot/tests/test_platform.py' | |||
4337 | --- autopilot/tests/test_platform.py 1970-01-01 00:00:00 +0000 | |||
4338 | +++ autopilot/tests/test_platform.py 2013-04-15 21:43:32 +0000 | |||
4339 | @@ -0,0 +1,134 @@ | |||
4340 | 1 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- | ||
4341 | 2 | # Copyright 2013 Canonical | ||
4342 | 3 | # Author: Thomi Richards | ||
4343 | 4 | # | ||
4344 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
4345 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
4346 | 7 | # by the Free Software Foundation. | ||
4347 | 8 | |||
4348 | 9 | "Tests for the autopilot platform code." | ||
4349 | 10 | |||
4350 | 11 | import autopilot.platform as platform | ||
4351 | 12 | |||
4352 | 13 | from StringIO import StringIO | ||
4353 | 14 | from testtools import TestCase | ||
4354 | 15 | from testtools.matchers import Equals | ||
4355 | 16 | |||
4356 | 17 | from mock import patch | ||
4357 | 18 | |||
4358 | 19 | class PlatformDetectorTests(TestCase): | ||
4359 | 20 | |||
4360 | 21 | def tearDown(self): | ||
4361 | 22 | super(PlatformDetectorTests, self).tearDown() | ||
4362 | 23 | # platform detector is cached, so destroy the cache at the end of each | ||
4363 | 24 | # test: | ||
4364 | 25 | platform._PlatformDetector._cached_detector = None | ||
4365 | 26 | |||
4366 | 27 | def test_platform_detector_is_cached(self): | ||
4367 | 28 | """Test that the platform detector is only created once.""" | ||
4368 | 29 | detector1 = platform._PlatformDetector.create() | ||
4369 | 30 | detector2 = platform._PlatformDetector.create() | ||
4370 | 31 | self.assertThat(id(detector1), Equals(id(detector2))) | ||
4371 | 32 | |||
4372 | 33 | @patch('autopilot.platform._get_property_file') | ||
4373 | 34 | def test_default_model(self, mock_get_property_file): | ||
4374 | 35 | """The default model name must be 'Desktop'.""" | ||
4375 | 36 | mock_get_property_file.return_value = None | ||
4376 | 37 | |||
4377 | 38 | detector = platform._PlatformDetector.create() | ||
4378 | 39 | self.assertThat(detector.model, Equals('Desktop')) | ||
4379 | 40 | |||
4380 | 41 | @patch('autopilot.platform._get_property_file') | ||
4381 | 42 | def test_default_image_codename(self, mock_get_property_file): | ||
4382 | 43 | """The default image codename must be 'Desktop'.""" | ||
4383 | 44 | mock_get_property_file.return_value = None | ||
4384 | 45 | |||
4385 | 46 | detector = platform._PlatformDetector.create() | ||
4386 | 47 | self.assertThat(detector.image_codename, Equals('Desktop')) | ||
4387 | 48 | |||
4388 | 49 | @patch('autopilot.platform._get_property_file') | ||
4389 | 50 | def test_model_is_set_from_property_file(self, mock_get_property_file): | ||
4390 | 51 | """Detector must read product model from android properties file.""" | ||
4391 | 52 | mock_get_property_file.return_value = StringIO("ro.product.model=test123") | ||
4392 | 53 | |||
4393 | 54 | detector = platform._PlatformDetector.create() | ||
4394 | 55 | self.assertThat(detector.model, Equals('test123')) | ||
4395 | 56 | |||
4396 | 57 | @patch('autopilot.platform._get_property_file', new=lambda: StringIO("")) | ||
4397 | 58 | def test_model_has_default_when_not_in_property_file(self): | ||
4398 | 59 | """Detector must use 'Desktop' as a default value for the model name | ||
4399 | 60 | when the property file exists, but does not contain a model description. | ||
4400 | 61 | |||
4401 | 62 | """ | ||
4402 | 63 | detector = platform._PlatformDetector.create() | ||
4403 | 64 | self.assertThat(detector.model, Equals('Desktop')) | ||
4404 | 65 | |||
4405 | 66 | @patch('autopilot.platform._get_property_file') | ||
4406 | 67 | def test_product_codename_is_set_from_property_file(self, mock_get_property_file): | ||
4407 | 68 | """Detector must read product model from android properties file.""" | ||
4408 | 69 | mock_get_property_file.return_value = StringIO("ro.product.name=test123") | ||
4409 | 70 | |||
4410 | 71 | detector = platform._PlatformDetector.create() | ||
4411 | 72 | self.assertThat(detector.image_codename, Equals('test123')) | ||
4412 | 73 | |||
4413 | 74 | @patch('autopilot.platform._get_property_file', new=lambda: StringIO("")) | ||
4414 | 75 | def test_product_codename_has_default_when_not_in_property_file(self): | ||
4415 | 76 | """Detector must use 'Desktop' as a default value for the product codename | ||
4416 | 77 | when the property file exists, but does not contain a model description. | ||
4417 | 78 | |||
4418 | 79 | """ | ||
4419 | 80 | detector = platform._PlatformDetector.create() | ||
4420 | 81 | self.assertThat(detector.image_codename, Equals('Desktop')) | ||
4421 | 82 | |||
4422 | 83 | |||
4423 | 84 | class BuildPropertyParserTests(TestCase): | ||
4424 | 85 | |||
4425 | 86 | """Tests for the android build properties file parser.""" | ||
4426 | 87 | |||
4427 | 88 | def test_empty_file_returns_empty_dictionary(self): | ||
4428 | 89 | """An empty file must result in an empty dictionary.""" | ||
4429 | 90 | prop_file = StringIO("") | ||
4430 | 91 | properties = platform._parse_build_properties_file(prop_file) | ||
4431 | 92 | self.assertThat(len(properties), Equals(0)) | ||
4432 | 93 | |||
4433 | 94 | def test_whitespace_is_ignored(self): | ||
4434 | 95 | """Whitespace in build file must be ignored.""" | ||
4435 | 96 | prop_file = StringIO("\n\n\n\n\n") | ||
4436 | 97 | properties = platform._parse_build_properties_file(prop_file) | ||
4437 | 98 | self.assertThat(len(properties), Equals(0)) | ||
4438 | 99 | |||
4439 | 100 | def test_comments_are_ignored(self): | ||
4440 | 101 | """Comments in build file must be ignored.""" | ||
4441 | 102 | prop_file = StringIO("# Hello World\n #Hello Again\n#####") | ||
4442 | 103 | properties = platform._parse_build_properties_file(prop_file) | ||
4443 | 104 | self.assertThat(len(properties), Equals(0)) | ||
4444 | 105 | |||
4445 | 106 | def test_invalid_lines_are_ignored(self): | ||
4446 | 107 | """lines without ana ssignment must be ignored.""" | ||
4447 | 108 | prop_file = StringIO("Hello") | ||
4448 | 109 | properties = platform._parse_build_properties_file(prop_file) | ||
4449 | 110 | self.assertThat(len(properties), Equals(0)) | ||
4450 | 111 | |||
4451 | 112 | def test_simple_value(self): | ||
4452 | 113 | """Test a simple a=b expression.""" | ||
4453 | 114 | prop_file = StringIO("a=b") | ||
4454 | 115 | properties = platform._parse_build_properties_file(prop_file) | ||
4455 | 116 | self.assertThat(properties, Equals(dict(a='b'))) | ||
4456 | 117 | |||
4457 | 118 | def test_multiple_values(self): | ||
4458 | 119 | """Test several expressions over multiple lines.""" | ||
4459 | 120 | prop_file = StringIO("a=b\nb=23") | ||
4460 | 121 | properties = platform._parse_build_properties_file(prop_file) | ||
4461 | 122 | self.assertThat(properties, Equals(dict(a='b',b='23'))) | ||
4462 | 123 | |||
4463 | 124 | def test_values_with_equals_in_them(self): | ||
4464 | 125 | """Test that we can parse values with a '=' in them.""" | ||
4465 | 126 | prop_file = StringIO("a=b=c") | ||
4466 | 127 | properties = platform._parse_build_properties_file(prop_file) | ||
4467 | 128 | self.assertThat(properties, Equals(dict(a='b=c'))) | ||
4468 | 129 | |||
4469 | 130 | def test_dotted_values_work(self): | ||
4470 | 131 | """Test that we can use dotted values as the keys.""" | ||
4471 | 132 | prop_file = StringIO("ro.product.model=maguro") | ||
4472 | 133 | properties = platform._parse_build_properties_file(prop_file) | ||
4473 | 134 | self.assertThat(properties, Equals({'ro.product.model':'maguro'})) | ||
4474 | 0 | 135 | ||
4475 | === renamed file 'autopilot/tests/test_bamf_emulator.py' => 'autopilot/tests/test_process_emulator.py' | |||
4476 | --- autopilot/tests/test_bamf_emulator.py 2013-01-06 21:39:32 +0000 | |||
4477 | +++ autopilot/tests/test_process_emulator.py 2013-04-15 21:43:32 +0000 | |||
4478 | @@ -15,11 +15,11 @@ | |||
4479 | 15 | from time import sleep, time | 15 | from time import sleep, time |
4480 | 16 | 16 | ||
4481 | 17 | 17 | ||
4483 | 18 | class BamfEmulatorTests(AutopilotTestCase): | 18 | class ProcessEmulatorTests(AutopilotTestCase): |
4484 | 19 | 19 | ||
4485 | 20 | def ensure_gedit_not_running(self): | 20 | def ensure_gedit_not_running(self): |
4486 | 21 | """Close any open gedit applications.""" | 21 | """Close any open gedit applications.""" |
4488 | 22 | apps = self.bamf.get_running_applications_by_desktop_file('gedit.desktop') | 22 | apps = self.process_manager.get_running_applications_by_desktop_file('gedit.desktop') |
4489 | 23 | if apps: | 23 | if apps: |
4490 | 24 | # this is a bit brutal, but easier in this context than the alternative. | 24 | # this is a bit brutal, but easier in this context than the alternative. |
4491 | 25 | call(['killall', 'gedit']) | 25 | call(['killall', 'gedit']) |
4492 | @@ -34,7 +34,7 @@ | |||
4493 | 34 | start = time() | 34 | start = time() |
4494 | 35 | t = Thread(target=start_gedit()) | 35 | t = Thread(target=start_gedit()) |
4495 | 36 | t.start() | 36 | t.start() |
4497 | 37 | ret = self.bamf.wait_until_application_is_running('gedit.desktop', 10) | 37 | ret = self.process_manager.wait_until_application_is_running('gedit.desktop', 10) |
4498 | 38 | end = time() | 38 | end = time() |
4499 | 39 | t.join() | 39 | t.join() |
4500 | 40 | 40 | ||
4501 | @@ -46,7 +46,7 @@ | |||
4502 | 46 | self.ensure_gedit_not_running() | 46 | self.ensure_gedit_not_running() |
4503 | 47 | 47 | ||
4504 | 48 | start = time() | 48 | start = time() |
4506 | 49 | ret = self.bamf.wait_until_application_is_running('gedit.desktop', 5) | 49 | ret = self.process_manager.wait_until_application_is_running('gedit.desktop', 5) |
4507 | 50 | end = time() | 50 | end = time() |
4508 | 51 | 51 | ||
4509 | 52 | self.assertThat(abs(end - start - 5.0), LessThan(1)) | 52 | self.assertThat(abs(end - start - 5.0), LessThan(1)) |
4510 | 53 | 53 | ||
4511 | === modified file 'autopilot/utilities.py' | |||
4512 | --- autopilot/utilities.py 2013-03-03 21:21:08 +0000 | |||
4513 | +++ autopilot/utilities.py 2013-04-15 21:43:32 +0000 | |||
4514 | @@ -14,103 +14,26 @@ | |||
4515 | 14 | 14 | ||
4516 | 15 | from __future__ import absolute_import | 15 | from __future__ import absolute_import |
4517 | 16 | 16 | ||
4518 | 17 | import inspect | ||
4519 | 17 | import logging | 18 | import logging |
4520 | 18 | import os | 19 | import os |
4521 | 19 | import sys | ||
4522 | 20 | import time | 20 | import time |
4523 | 21 | from functools import wraps | 21 | from functools import wraps |
4616 | 22 | from Xlib import X, display, protocol | 22 | |
4617 | 23 | 23 | ||
4618 | 24 | _display = None | 24 | def _pick_variant(variants, preferred_variant): |
4619 | 25 | 25 | possible_backends = variants.keys() | |
4620 | 26 | def get_display(): | 26 | get_debug_logger().debug("Possible variants: %s", ','.join(possible_backends)) |
4621 | 27 | """Get a Xlib display object. Creating the display prints garbage to stdout.""" | 27 | if preferred_variant in possible_backends: |
4622 | 28 | global _display | 28 | possible_backends.sort(lambda a,b: -1 if a == preferred_variant else 0) |
4623 | 29 | if _display is None: | 29 | failure_reasons = [] |
4624 | 30 | with Silence(): | 30 | for be in possible_backends: |
4625 | 31 | _display = display.Display() | 31 | try: |
4626 | 32 | return _display | 32 | return variants[be]() |
4627 | 33 | 33 | except Exception as e: | |
4628 | 34 | 34 | get_debug_logger().warning("Can't create variant %s: %r", be, e) | |
4629 | 35 | 35 | failure_reasons.append('%s: %r' % (be, e)) | |
4630 | 36 | def make_window_skip_taskbar(window, set_flag=True): | 36 | raise RuntimeError("Unable to instantiate any backends\n%s" % '\n'.join(failure_reasons)) |
4539 | 37 | """Set the skip-taskbar kint on an X11 window. | ||
4540 | 38 | |||
4541 | 39 | 'window' should be an Xlib window object. | ||
4542 | 40 | set_flag should be 'True' to set the flag, 'False' to clear it. | ||
4543 | 41 | |||
4544 | 42 | """ | ||
4545 | 43 | state = get_display().get_atom('_NET_WM_STATE_SKIP_TASKBAR', 1) | ||
4546 | 44 | action = int(set_flag) | ||
4547 | 45 | if action == 0: | ||
4548 | 46 | print "Clearing flag" | ||
4549 | 47 | elif action == 1: | ||
4550 | 48 | print "Setting flag" | ||
4551 | 49 | _setProperty('_NET_WM_STATE', [action, state, 0, 1], window) | ||
4552 | 50 | get_display().sync() | ||
4553 | 51 | |||
4554 | 52 | |||
4555 | 53 | def get_desktop_viewport(): | ||
4556 | 54 | """Get the x,y coordinates for the current desktop viewport top-left corner.""" | ||
4557 | 55 | return _getProperty('_NET_DESKTOP_VIEWPORT') | ||
4558 | 56 | |||
4559 | 57 | |||
4560 | 58 | def get_desktop_geometry(): | ||
4561 | 59 | """Get the full width and height of the desktop, including all the viewports.""" | ||
4562 | 60 | return _getProperty('_NET_DESKTOP_GEOMETRY') | ||
4563 | 61 | |||
4564 | 62 | |||
4565 | 63 | def _setProperty(_type, data, win=None, mask=None): | ||
4566 | 64 | """ Send a ClientMessage event to a window""" | ||
4567 | 65 | if not win: | ||
4568 | 66 | win = get_display().screen().root | ||
4569 | 67 | if type(data) is str: | ||
4570 | 68 | dataSize = 8 | ||
4571 | 69 | else: | ||
4572 | 70 | # data length must be 5 - pad with 0's if it's short, truncate otherwise. | ||
4573 | 71 | data = (data + [0] * (5 - len(data)))[:5] | ||
4574 | 72 | dataSize = 32 | ||
4575 | 73 | |||
4576 | 74 | ev = protocol.event.ClientMessage(window=win, | ||
4577 | 75 | client_type=get_display().get_atom(_type), | ||
4578 | 76 | data=(dataSize, data)) | ||
4579 | 77 | |||
4580 | 78 | if not mask: | ||
4581 | 79 | mask = (X.SubstructureRedirectMask | X.SubstructureNotifyMask) | ||
4582 | 80 | get_display().screen().root.send_event(ev, event_mask=mask) | ||
4583 | 81 | |||
4584 | 82 | |||
4585 | 83 | def _getProperty(_type, win=None): | ||
4586 | 84 | if not win: | ||
4587 | 85 | win = get_display().screen().root | ||
4588 | 86 | atom = win.get_full_property(get_display().get_atom(_type), X.AnyPropertyType) | ||
4589 | 87 | if atom: return atom.value | ||
4590 | 88 | |||
4591 | 89 | |||
4592 | 90 | def get_compiz_setting(plugin_name, setting_name): | ||
4593 | 91 | """Get a compiz setting object. | ||
4594 | 92 | |||
4595 | 93 | 'plugin_name' is the name of the plugin (e.g. 'core' or 'unityshell') | ||
4596 | 94 | 'setting_name' is the name of the setting (e.g. 'alt_tab_timeout') | ||
4597 | 95 | |||
4598 | 96 | This function will raise KeyError if the plugin or setting named does not | ||
4599 | 97 | exist. | ||
4600 | 98 | |||
4601 | 99 | """ | ||
4602 | 100 | # circular dependancy: | ||
4603 | 101 | from autopilot.compizconfig import get_setting | ||
4604 | 102 | return get_setting(plugin_name, setting_name) | ||
4605 | 103 | |||
4606 | 104 | |||
4607 | 105 | def get_compiz_option(plugin_name, setting_name): | ||
4608 | 106 | """Get a compiz setting value. | ||
4609 | 107 | |||
4610 | 108 | This is the same as calling: | ||
4611 | 109 | |||
4612 | 110 | >>> get_compiz_setting(plugin_name, setting_name).Value | ||
4613 | 111 | |||
4614 | 112 | """ | ||
4615 | 113 | return get_compiz_setting(plugin_name, setting_name).Value | ||
4631 | 114 | 37 | ||
4632 | 115 | 38 | ||
4633 | 116 | # Taken from http://code.activestate.com/recipes/577564-context-manager-for-low-level-redirection-of-stdou/ | 39 | # Taken from http://code.activestate.com/recipes/577564-context-manager-for-low-level-redirection-of-stdou/ |
4634 | @@ -226,7 +149,33 @@ | |||
4635 | 226 | def fdec(fn): | 149 | def fdec(fn): |
4636 | 227 | @wraps(fn) | 150 | @wraps(fn) |
4637 | 228 | def wrapped(*args, **kwargs): | 151 | def wrapped(*args, **kwargs): |
4639 | 229 | sys.stderr.write("WARNING: This function is deprecated. Please use '%s' instead.\n" % alternative) | 152 | import sys |
4640 | 153 | outerframe_details = inspect.getouterframes(inspect.currentframe())[1] | ||
4641 | 154 | filename, line_number, function_name = outerframe_details[1:4] | ||
4642 | 155 | sys.stderr.write("WARNING: in file \"{0}\", line {1} in {2}\n".format(filename, line_number, function_name)) | ||
4643 | 156 | sys.stderr.write("This function is deprecated. Please use '%s' instead.\n" % alternative) | ||
4644 | 230 | return fn(*args, **kwargs) | 157 | return fn(*args, **kwargs) |
4645 | 231 | return wrapped | 158 | return wrapped |
4646 | 232 | return fdec | 159 | return fdec |
4647 | 160 | |||
4648 | 161 | |||
4649 | 162 | class _CleanupWrapper(object): | ||
4650 | 163 | """Support for calling 'addCleanup' outside the test case.""" | ||
4651 | 164 | |||
4652 | 165 | def __init__(self): | ||
4653 | 166 | self._test_instance = None | ||
4654 | 167 | |||
4655 | 168 | def __call__(self, callable, *args, **kwargs): | ||
4656 | 169 | if self._test_instance is None: | ||
4657 | 170 | raise RuntimeError("Out-of-test addCleanup can only be called while an autopilot test case is running!") | ||
4658 | 171 | self._test_instance.addCleanup(callable, *args, **kwargs) | ||
4659 | 172 | |||
4660 | 173 | def set_test_instance(self, test_instance): | ||
4661 | 174 | self._test_instance = test_instance | ||
4662 | 175 | test_instance.addCleanup(self._on_test_ended) | ||
4663 | 176 | |||
4664 | 177 | def _on_test_ended(self): | ||
4665 | 178 | self._test_instance = None | ||
4666 | 179 | |||
4667 | 180 | |||
4668 | 181 | addCleanup = _CleanupWrapper() | ||
4669 | 233 | 182 | ||
4670 | === modified file 'bin/autopilot' | |||
4671 | --- bin/autopilot 2013-02-21 02:37:04 +0000 | |||
4672 | +++ bin/autopilot 2013-04-15 21:43:32 +0000 | |||
4673 | @@ -27,13 +27,13 @@ | |||
4674 | 27 | from argparse import ArgumentParser | 27 | from argparse import ArgumentParser |
4675 | 28 | from unittest.loader import TestLoader | 28 | from unittest.loader import TestLoader |
4676 | 29 | from unittest import TestSuite | 29 | from unittest import TestSuite |
4679 | 30 | from autopilot.introspection.gtk import GtkIntrospectionTestMixin | 30 | from autopilot.introspection import launch_application |
4680 | 31 | from autopilot.introspection.qt import QtIntrospectionTestMixin | 31 | from autopilot.introspection.gtk import GtkApplicationLauncher |
4681 | 32 | from autopilot.introspection.qt import QtApplicationLauncher | ||
4682 | 32 | 33 | ||
4683 | 33 | # list autopilot depends here, with the form: | 34 | # list autopilot depends here, with the form: |
4684 | 34 | # ('python module name', 'ubuntu package name'), | 35 | # ('python module name', 'ubuntu package name'), |
4685 | 35 | DEPENDS = [ | 36 | DEPENDS = [ |
4686 | 36 | ('compizconfig', 'python-compizconfig'), | ||
4687 | 37 | ('dbus', 'python-dbus'), | 37 | ('dbus', 'python-dbus'), |
4688 | 38 | ('gi.repository.GConf', 'gir1.2-gconf-2.0'), | 38 | ('gi.repository.GConf', 'gir1.2-gconf-2.0'), |
4689 | 39 | ('gi.repository.IBus', 'gir1.2-ibus-1.0'), | 39 | ('gi.repository.IBus', 'gir1.2-ibus-1.0'), |
4690 | @@ -345,27 +345,19 @@ | |||
4691 | 345 | exit(1) | 345 | exit(1) |
4692 | 346 | 346 | ||
4693 | 347 | # We now have a full path to the application. | 347 | # We now have a full path to the application. |
4695 | 348 | IntrospectionBase = None | 348 | launcher = None |
4696 | 349 | if args.interface == 'Auto': | 349 | if args.interface == 'Auto': |
4698 | 350 | IntrospectionBase = get_application_introspection_base(app_name) | 350 | launcher = get_application_introspection_base(app_name) |
4699 | 351 | elif args.interface == 'Gtk': | 351 | elif args.interface == 'Gtk': |
4701 | 352 | IntrospectionBase = GtkIntrospectionTestMixin | 352 | launcher = GtkApplicationLauncher() |
4702 | 353 | elif args.interface == 'Qt': | 353 | elif args.interface == 'Qt': |
4705 | 354 | IntrospectionBase = QtIntrospectionTestMixin | 354 | launcher = QtApplicationLauncher() |
4706 | 355 | if IntrospectionBase is None: | 355 | if launcher is None: |
4707 | 356 | print "Error: Could not determine introspection type to use for application '%s'." % app_name | 356 | print "Error: Could not determine introspection type to use for application '%s'." % app_name |
4708 | 357 | exit(1) | 357 | exit(1) |
4709 | 358 | 358 | ||
4710 | 359 | # IntrospectionBase is supposed to be a mixin class with a TestCase, and makes | ||
4711 | 360 | # use of addCleanup to shut down the app after the test has completed. We | ||
4712 | 361 | # patch that function here so we don't error... | ||
4713 | 362 | def fake_cleanup(self, *args, **kwargs): | ||
4714 | 363 | pass | ||
4715 | 364 | IntrospectionBase.addCleanup = fake_cleanup | ||
4716 | 365 | |||
4717 | 366 | b = IntrospectionBase() | ||
4718 | 367 | try: | 359 | try: |
4720 | 368 | b.launch_test_application(app_name, capture_output=False) | 360 | launch_application(launcher, app_name, capture_output=False) |
4721 | 369 | except RuntimeError as e: | 361 | except RuntimeError as e: |
4722 | 370 | print "Error: " + e.message | 362 | print "Error: " + e.message |
4723 | 371 | exit(1) | 363 | exit(1) |
4724 | @@ -387,9 +379,9 @@ | |||
4725 | 387 | print "Use the '-i' argument to specify an interface." | 379 | print "Use the '-i' argument to specify an interface." |
4726 | 388 | exit(1) | 380 | exit(1) |
4727 | 389 | if 'libqtcore' in ldd_output: | 381 | if 'libqtcore' in ldd_output: |
4729 | 390 | return QtIntrospectionTestMixin | 382 | return QtApplicationLauncher |
4730 | 391 | elif 'libgtk' in ldd_output: | 383 | elif 'libgtk' in ldd_output: |
4732 | 392 | return GtkIntrospectionTestMixin | 384 | return GtkApplicationLauncher |
4733 | 393 | return None | 385 | return None |
4734 | 394 | 386 | ||
4735 | 395 | 387 | ||
4736 | 396 | 388 | ||
4737 | === modified file 'debian/changelog' | |||
4738 | --- debian/changelog 2013-03-26 00:02:00 +0000 | |||
4739 | +++ debian/changelog 2013-04-15 21:43:32 +0000 | |||
4740 | @@ -1,3 +1,9 @@ | |||
4741 | 1 | autopilot (1.3) UNRELEASED; urgency=low | ||
4742 | 2 | |||
4743 | 3 | * Create version 1.3 (LP: #1168971) | ||
4744 | 4 | |||
4745 | 5 | -- Thomi Richards <thomi.richards@canonical.com> Mon, 15 Apr 2013 09:33:21 +1200 | ||
4746 | 6 | |||
4747 | 1 | autopilot (1.2daily13.03.26-0ubuntu1) raring; urgency=low | 7 | autopilot (1.2daily13.03.26-0ubuntu1) raring; urgency=low |
4748 | 2 | 8 | ||
4749 | 3 | * Automatic snapshot from revision 155 | 9 | * Automatic snapshot from revision 155 |
4750 | 4 | 10 | ||
4751 | === modified file 'debian/control' | |||
4752 | --- debian/control 2012-12-04 11:43:20 +0000 | |||
4753 | +++ debian/control 2013-04-15 21:43:32 +0000 | |||
4754 | @@ -9,6 +9,7 @@ | |||
4755 | 9 | gir1.2-gtk-2.0, | 9 | gir1.2-gtk-2.0, |
4756 | 10 | python (>= 2.6), | 10 | python (>= 2.6), |
4757 | 11 | python-dbus, | 11 | python-dbus, |
4758 | 12 | python-debian, | ||
4759 | 12 | python-setuptools, | 13 | python-setuptools, |
4760 | 13 | python-sphinx, | 14 | python-sphinx, |
4761 | 14 | python-testtools, | 15 | python-testtools, |
4762 | @@ -28,7 +29,6 @@ | |||
4763 | 28 | gir1.2-glib-2.0, | 29 | gir1.2-glib-2.0, |
4764 | 29 | gir1.2-gtk-2.0, | 30 | gir1.2-gtk-2.0, |
4765 | 30 | gir1.2-ibus-1.0, | 31 | gir1.2-ibus-1.0, |
4766 | 31 | python-compizconfig, | ||
4767 | 32 | python-dbus, | 32 | python-dbus, |
4768 | 33 | python-junitxml, | 33 | python-junitxml, |
4769 | 34 | python-qt4, | 34 | python-qt4, |
4770 | 35 | 35 | ||
4771 | === added file 'docs/_templates/indexcontent.html' | |||
4772 | --- docs/_templates/indexcontent.html 1970-01-01 00:00:00 +0000 | |||
4773 | +++ docs/_templates/indexcontent.html 2013-04-15 21:43:32 +0000 | |||
4774 | @@ -0,0 +1,45 @@ | |||
4775 | 1 | {% extends "defindex.html" %} | ||
4776 | 2 | {% block tables %} | ||
4777 | 3 | <p>Autopilot is a tool for writing <i>functional tests</i> for <i>GUI</i> applications. It works out-of-the-box for Several GUI toolkits, including Gtk2, Gtk3, Qt4, and Qt5/Qml.</p> | ||
4778 | 4 | <p><strong>Parts of the documentation:</strong></p> | ||
4779 | 5 | <table class="contentstable" align="center"> | ||
4780 | 6 | <tr> | ||
4781 | 7 | <td width="50%"> | ||
4782 | 8 | <p class="biglink"> | ||
4783 | 9 | <a class="biglink" href="{{ pathto("tutorial/tutorial") }}">Getting started with Autopilot</a><br/> | ||
4784 | 10 | <span class="linkdescr">How to write your first Autopilot test.</span> | ||
4785 | 11 | </p> | ||
4786 | 12 | </td> | ||
4787 | 13 | <td width="50%"> | ||
4788 | 14 | <p class="biglink"> | ||
4789 | 15 | <a class="biglink" href="{{ pathto("api/autopilot") }}">API Reference</a><br/> | ||
4790 | 16 | <span class="linkdescr">API reference documentation for Autopilot.</span> | ||
4791 | 17 | </p> | ||
4792 | 18 | </td> | ||
4793 | 19 | </tr> | ||
4794 | 20 | <tr> | ||
4795 | 21 | <td> | ||
4796 | 22 | <p class="biglink"> | ||
4797 | 23 | <a class="biglink" href="{{ pathto("faq/faq") }}">Frequently Asked Questions</a><br/> | ||
4798 | 24 | <span class="linkdescr">...with answers!</span> | ||
4799 | 25 | </p> | ||
4800 | 26 | </td> | ||
4801 | 27 | <td> | ||
4802 | 28 | <p class="biglink"> | ||
4803 | 29 | <a class="biglink" href="{{ pathto("porting/porting") }}">Porting Autopilot Tests</a><br/> | ||
4804 | 30 | <span class="linkdescr">How to port your tests from earlier versions of Autopilot.</span> | ||
4805 | 31 | </p> | ||
4806 | 32 | </td> | ||
4807 | 33 | </tr> | ||
4808 | 34 | </table> | ||
4809 | 35 | |||
4810 | 36 | <p><strong>Indices and tables:</strong></p> | ||
4811 | 37 | <table class="contentstable" align="center"><tr> | ||
4812 | 38 | <td width="50%"> | ||
4813 | 39 | <p class="biglink"><a class="biglink" href="{{ pathto("py-modindex") }}">Module Index</a><br/> | ||
4814 | 40 | <span class="linkdescr">quick access to all modules</span></p> | ||
4815 | 41 | {# <p class="biglink"><a class="biglink" href="{{ pathto("contents") }}">Complete Table of Contents</a><br/> | ||
4816 | 42 | <span class="linkdescr">lists all sections and subsections</span></p> #} | ||
4817 | 43 | </td></tr> | ||
4818 | 44 | </table> | ||
4819 | 45 | {% endblock %} | ||
4820 | 0 | 46 | ||
4821 | === modified file 'docs/api/autopilot.rst' | |||
4822 | --- docs/api/autopilot.rst 2013-02-28 01:01:11 +0000 | |||
4823 | +++ docs/api/autopilot.rst 2013-04-15 21:43:32 +0000 | |||
4824 | @@ -1,103 +1,10 @@ | |||
4825 | 1 | :orphan: | ||
4826 | 2 | |||
4827 | 1 | Autopilot API Documentation | 3 | Autopilot API Documentation |
4828 | 2 | =========================== | 4 | =========================== |
4829 | 3 | 5 | ||
4930 | 4 | Autopilot Utility Modules | 6 | .. toctree:: |
4931 | 5 | +++++++++++++++++++++++++ | 7 | :maxdepth: 1 |
4932 | 6 | 8 | :glob: | |
4933 | 7 | :mod:`testcase` Module | 9 | |
4934 | 8 | ---------------------- | 10 | * |
4835 | 9 | |||
4836 | 10 | .. autoclass:: autopilot.testcase.AutopilotTestCase | ||
4837 | 11 | :members: | ||
4838 | 12 | |||
4839 | 13 | .. autofunction:: autopilot.testcase.multiply_scenarios | ||
4840 | 14 | |||
4841 | 15 | :mod:`keybindings` Module | ||
4842 | 16 | ------------------------- | ||
4843 | 17 | |||
4844 | 18 | .. automodule:: autopilot.keybindings | ||
4845 | 19 | :members: | ||
4846 | 20 | :undoc-members: | ||
4847 | 21 | :show-inheritance: | ||
4848 | 22 | |||
4849 | 23 | Emulators Package | ||
4850 | 24 | +++++++++++++++++ | ||
4851 | 25 | |||
4852 | 26 | :mod:`input` Module | ||
4853 | 27 | ------------------- | ||
4854 | 28 | |||
4855 | 29 | .. automodule:: autopilot.emulators.input | ||
4856 | 30 | :members: | ||
4857 | 31 | :undoc-members: | ||
4858 | 32 | :show-inheritance: | ||
4859 | 33 | |||
4860 | 34 | :mod:`bamf` Module | ||
4861 | 35 | ------------------ | ||
4862 | 36 | |||
4863 | 37 | .. automodule:: autopilot.emulators.bamf | ||
4864 | 38 | :members: | ||
4865 | 39 | :undoc-members: | ||
4866 | 40 | :show-inheritance: | ||
4867 | 41 | |||
4868 | 42 | :mod:`ibus` Module | ||
4869 | 43 | ------------------ | ||
4870 | 44 | |||
4871 | 45 | .. automodule:: autopilot.emulators.ibus | ||
4872 | 46 | :members: | ||
4873 | 47 | :undoc-members: | ||
4874 | 48 | :show-inheritance: | ||
4875 | 49 | |||
4876 | 50 | :mod:`zeitgeist` Module | ||
4877 | 51 | ----------------------- | ||
4878 | 52 | |||
4879 | 53 | .. automodule:: autopilot.emulators.zeitgeist | ||
4880 | 54 | :members: | ||
4881 | 55 | :undoc-members: | ||
4882 | 56 | :show-inheritance: | ||
4883 | 57 | |||
4884 | 58 | Introspection Package | ||
4885 | 59 | +++++++++++++++++++++ | ||
4886 | 60 | |||
4887 | 61 | :mod:`introspection` Package | ||
4888 | 62 | ---------------------------- | ||
4889 | 63 | |||
4890 | 64 | .. automodule:: autopilot.introspection | ||
4891 | 65 | :members: | ||
4892 | 66 | :undoc-members: | ||
4893 | 67 | :show-inheritance: | ||
4894 | 68 | |||
4895 | 69 | :mod:`dbus` Module | ||
4896 | 70 | ------------------- | ||
4897 | 71 | |||
4898 | 72 | .. automodule:: autopilot.introspection.dbus | ||
4899 | 73 | :members: | ||
4900 | 74 | :undoc-members: | ||
4901 | 75 | :show-inheritance: | ||
4902 | 76 | |||
4903 | 77 | :mod:`qt` Module | ||
4904 | 78 | ------------------- | ||
4905 | 79 | |||
4906 | 80 | .. automodule:: autopilot.introspection.qt | ||
4907 | 81 | :members: | ||
4908 | 82 | :undoc-members: | ||
4909 | 83 | :show-inheritance: | ||
4910 | 84 | |||
4911 | 85 | :mod:`gtk` Module | ||
4912 | 86 | ------------------- | ||
4913 | 87 | |||
4914 | 88 | .. automodule:: autopilot.introspection.gtk | ||
4915 | 89 | :members: | ||
4916 | 90 | :undoc-members: | ||
4917 | 91 | :show-inheritance: | ||
4918 | 92 | |||
4919 | 93 | Matchers Package | ||
4920 | 94 | ++++++++++++++++ | ||
4921 | 95 | |||
4922 | 96 | :mod:`matchers` Package | ||
4923 | 97 | ----------------------- | ||
4924 | 98 | |||
4925 | 99 | .. automodule:: autopilot.matchers | ||
4926 | 100 | :members: | ||
4927 | 101 | :undoc-members: | ||
4928 | 102 | :show-inheritance: | ||
4929 | 103 | |||
4935 | 104 | 11 | ||
4936 | === added file 'docs/api/display.rst' | |||
4937 | --- docs/api/display.rst 1970-01-01 00:00:00 +0000 | |||
4938 | +++ docs/api/display.rst 2013-04-15 21:43:32 +0000 | |||
4939 | @@ -0,0 +1,7 @@ | |||
4940 | 1 | ``display`` - Get information about the current display(s) | ||
4941 | 2 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
4942 | 3 | |||
4943 | 4 | |||
4944 | 5 | .. automodule:: autopilot.display | ||
4945 | 6 | :members: | ||
4946 | 7 | :undoc-members: | ||
4947 | 0 | 8 | ||
4948 | === added file 'docs/api/emulators.rst' | |||
4949 | --- docs/api/emulators.rst 1970-01-01 00:00:00 +0000 | |||
4950 | +++ docs/api/emulators.rst 2013-04-15 21:43:32 +0000 | |||
4951 | @@ -0,0 +1,20 @@ | |||
4952 | 1 | ``emulators`` - Backwards compatibility for autopilot v1.2 | ||
4953 | 2 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
4954 | 3 | |||
4955 | 4 | |||
4956 | 5 | .. module autopilot.emulators | ||
4957 | 6 | :synopsis: Backwards compatibility module to provide the 'emulators' namespace. | ||
4958 | 7 | |||
4959 | 8 | |||
4960 | 9 | The emulators module exists for backwards compatibility only. | ||
4961 | 10 | |||
4962 | 11 | This module exists to make it easier to upgrade from autopilot v1.2 to v1.3 by | ||
4963 | 12 | providing the old 'emulators' namespace. However, it's a bad idea to rely on this | ||
4964 | 13 | module continuing to exist. It contains several sub-modules: | ||
4965 | 14 | |||
4966 | 15 | * :mod:`autopilot.display` | ||
4967 | 16 | * autopilot.clipboard (deprecated) | ||
4968 | 17 | * autopilot.dbus_handler (for internal use only) | ||
4969 | 18 | * autopilot.ibus (deprecated) | ||
4970 | 19 | * :mod:`autopilot.input` | ||
4971 | 20 | |||
4972 | 0 | 21 | ||
4973 | === added file 'docs/api/gestures.rst' | |||
4974 | --- docs/api/gestures.rst 1970-01-01 00:00:00 +0000 | |||
4975 | +++ docs/api/gestures.rst 2013-04-15 21:43:32 +0000 | |||
4976 | @@ -0,0 +1,6 @@ | |||
4977 | 1 | ``gestures`` - Gestural and multi-touch support | ||
4978 | 2 | +++++++++++++++++++++++++++++++++++++++++++++++ | ||
4979 | 3 | |||
4980 | 4 | |||
4981 | 5 | .. automodule:: autopilot.gestures | ||
4982 | 6 | :members: | ||
4983 | 0 | 7 | ||
4984 | === added file 'docs/api/input.rst' | |||
4985 | --- docs/api/input.rst 1970-01-01 00:00:00 +0000 | |||
4986 | +++ docs/api/input.rst 2013-04-15 21:43:32 +0000 | |||
4987 | @@ -0,0 +1,7 @@ | |||
4988 | 1 | ``input`` - Generate keyboard, mouse, and touch input events | ||
4989 | 2 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
4990 | 3 | |||
4991 | 4 | |||
4992 | 5 | .. automodule:: autopilot.input | ||
4993 | 6 | :members: | ||
4994 | 7 | :undoc-members: | ||
4995 | 0 | 8 | ||
4996 | === added file 'docs/api/introspection.rst' | |||
4997 | --- docs/api/introspection.rst 1970-01-01 00:00:00 +0000 | |||
4998 | +++ docs/api/introspection.rst 2013-04-15 21:43:32 +0000 | |||
4999 | @@ -0,0 +1,6 @@ | |||
5000 | 1 | ``introspection`` - Autopilot introspection internals |
just scrolled quickly through it (no real review yet) but stumbled across this:
3442 + ... a Qt4 Qml application might be launched like this:: test_applicatio n('qmlscene' , 'my_scene.qml')
3443 +
3444 + app_proxy = self.launch_
There is no qmlscene in Qt4. It was the QWidget based "qmlviewer" back then. qmlscene is the new Qt5 version which directly paints qml on a openGL scenegraph.