Merge lp:~facundo/magicicada-client/all-venv into lp:magicicada-client
- all-venv
- Merge into trunk
Proposed by
Facundo Batista
Status: | Rejected |
---|---|
Rejected by: | Facundo Batista |
Proposed branch: | lp:~facundo/magicicada-client/all-venv |
Merge into: | lp:magicicada-client |
Diff against target: |
2996 lines (+2723/-51) 29 files modified
Makefile (+1/-1) contrib/dirspec/__init__.py (+16/-0) contrib/dirspec/basedir.py (+159/-0) contrib/dirspec/utils.py (+188/-0) contrib/u1trial (+40/-0) data/dbus-session.conf.in (+63/-0) dependencies-devel.txt (+0/-3) dependencies.txt (+5/-8) requirements-devel.txt (+2/-0) requirements.txt (+6/-1) run-tests (+1/-1) setup.py (+14/-37) ubuntuone/devtools/__init__.py (+1/-0) ubuntuone/devtools/compat.py (+49/-0) ubuntuone/devtools/errors.py (+35/-0) ubuntuone/devtools/handlers.py (+97/-0) ubuntuone/devtools/reactors/__init__.py (+1/-0) ubuntuone/devtools/reactors/gi.py (+53/-0) ubuntuone/devtools/runners/__init__.py (+304/-0) ubuntuone/devtools/runners/txrunner.py (+133/-0) ubuntuone/devtools/services/__init__.py (+66/-0) ubuntuone/devtools/services/dbus.py (+121/-0) ubuntuone/devtools/testcases/__init__.py (+187/-0) ubuntuone/devtools/testcases/dbus.py (+138/-0) ubuntuone/devtools/testcases/txsocketserver.py (+357/-0) ubuntuone/devtools/testing/__init__.py (+1/-0) ubuntuone/devtools/testing/txcheck.py (+381/-0) ubuntuone/devtools/testing/txwebserver.py (+124/-0) ubuntuone/devtools/utils.py (+180/-0) |
To merge this branch: | bzr merge lp:~facundo/magicicada-client/all-venv |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
chicharreros | Pending | ||
Review via email: mp+347169@code.launchpad.net |
Commit message
Full virtualenv.
Description of the change
To post a comment you must log in.
Unmerged revisions
- 1445. By Facundo Batista
-
Full virtualenv.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Makefile' | |||
2 | --- Makefile 2018-04-14 23:34:20 +0000 | |||
3 | +++ Makefile 2018-05-30 21:37:37 +0000 | |||
4 | @@ -43,7 +43,7 @@ | |||
5 | 43 | cat dependencies-devel.txt | xargs apt-get install -y --no-install-recommends | 43 | cat dependencies-devel.txt | xargs apt-get install -y --no-install-recommends |
6 | 44 | 44 | ||
7 | 45 | venv: | 45 | venv: |
9 | 46 | virtualenv --system-site-packages $(ENV) | 46 | virtualenv $(ENV) |
10 | 47 | $(ENV)/bin/pip install -r requirements.txt -r requirements-devel.txt | 47 | $(ENV)/bin/pip install -r requirements.txt -r requirements-devel.txt |
11 | 48 | 48 | ||
12 | 49 | lint: | 49 | lint: |
13 | 50 | 50 | ||
14 | === added directory 'contrib/dirspec' | |||
15 | === added file 'contrib/dirspec/__init__.py' | |||
16 | --- contrib/dirspec/__init__.py 1970-01-01 00:00:00 +0000 | |||
17 | +++ contrib/dirspec/__init__.py 2018-05-30 21:37:37 +0000 | |||
18 | @@ -0,0 +1,16 @@ | |||
19 | 1 | # -*- coding: utf-8 -*- | ||
20 | 2 | # | ||
21 | 3 | # Copyright 2011 Canonical Ltd. | ||
22 | 4 | # | ||
23 | 5 | # This program is free software: you can redistribute it and/or modify | ||
24 | 6 | # it under the terms of the GNU Lesser General Public License version 3 | ||
25 | 7 | # as published by the Free Software Foundation. | ||
26 | 8 | # | ||
27 | 9 | # This program is distributed in the hope that it will be useful, | ||
28 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
29 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
30 | 12 | # GNU Lesser General Public License for more details. | ||
31 | 13 | # | ||
32 | 14 | # You should have received a copy of the GNU Lesser General Public License | ||
33 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
34 | 16 | """dirspec package.""" | ||
35 | 0 | 17 | ||
36 | === added file 'contrib/dirspec/basedir.py' | |||
37 | --- contrib/dirspec/basedir.py 1970-01-01 00:00:00 +0000 | |||
38 | +++ contrib/dirspec/basedir.py 2018-05-30 21:37:37 +0000 | |||
39 | @@ -0,0 +1,159 @@ | |||
40 | 1 | # -*- coding: utf-8 -*- | ||
41 | 2 | # | ||
42 | 3 | # Copyright 2011-2012 Canonical Ltd. | ||
43 | 4 | # | ||
44 | 5 | # This program is free software: you can redistribute it and/or modify | ||
45 | 6 | # it under the terms of the GNU Lesser General Public License version 3 | ||
46 | 7 | # as published by the Free Software Foundation. | ||
47 | 8 | # | ||
48 | 9 | # This program is distributed in the hope that it will be useful, | ||
49 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
50 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
51 | 12 | # GNU Lesser General Public License for more details. | ||
52 | 13 | # | ||
53 | 14 | # You should have received a copy of the GNU Lesser General Public License | ||
54 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
55 | 16 | """XDG Base Directory paths.""" | ||
56 | 17 | |||
57 | 18 | from __future__ import unicode_literals, print_function | ||
58 | 19 | |||
59 | 20 | import os | ||
60 | 21 | |||
61 | 22 | from dirspec.utils import (default_cache_home, | ||
62 | 23 | default_config_path, default_config_home, | ||
63 | 24 | default_data_path, default_data_home, | ||
64 | 25 | get_env_path, unicode_path) | ||
65 | 26 | |||
66 | 27 | __all__ = ['xdg_cache_home', | ||
67 | 28 | 'xdg_config_home', | ||
68 | 29 | 'xdg_data_home', | ||
69 | 30 | 'xdg_config_dirs', | ||
70 | 31 | 'xdg_data_dirs', | ||
71 | 32 | 'load_config_paths', | ||
72 | 33 | 'load_data_paths', | ||
73 | 34 | 'load_first_config', | ||
74 | 35 | 'save_config_path', | ||
75 | 36 | 'save_data_path', | ||
76 | 37 | ] | ||
77 | 38 | |||
78 | 39 | |||
79 | 40 | def get_xdg_cache_home(): | ||
80 | 41 | """Get the path for XDG cache directory in user's HOME.""" | ||
81 | 42 | return get_env_path('XDG_CACHE_HOME', default_cache_home) | ||
82 | 43 | |||
83 | 44 | |||
84 | 45 | def get_xdg_config_home(): | ||
85 | 46 | """Get the path for XDG config directory in user's HOME.""" | ||
86 | 47 | return get_env_path('XDG_CONFIG_HOME', default_config_home) | ||
87 | 48 | |||
88 | 49 | |||
89 | 50 | def get_xdg_data_home(): | ||
90 | 51 | """Get the path for XDG data directory in user's HOME.""" | ||
91 | 52 | return get_env_path('XDG_DATA_HOME', default_data_home) | ||
92 | 53 | |||
93 | 54 | |||
94 | 55 | def get_xdg_config_dirs(): | ||
95 | 56 | """Get the paths for the XDG config directories.""" | ||
96 | 57 | result = [get_xdg_config_home()] | ||
97 | 58 | result.extend([x.encode('utf-8') for x in get_env_path( | ||
98 | 59 | 'XDG_CONFIG_DIRS', | ||
99 | 60 | default_config_path).decode('utf-8').split(os.pathsep)]) | ||
100 | 61 | return result | ||
101 | 62 | |||
102 | 63 | |||
103 | 64 | def get_xdg_data_dirs(): | ||
104 | 65 | """Get the paths for the XDG data directories.""" | ||
105 | 66 | result = [get_xdg_data_home()] | ||
106 | 67 | result.extend([x.encode('utf-8') for x in get_env_path( | ||
107 | 68 | 'XDG_DATA_DIRS', | ||
108 | 69 | default_data_path).decode('utf-8').split(os.pathsep)]) | ||
109 | 70 | return result | ||
110 | 71 | |||
111 | 72 | |||
112 | 73 | def load_config_paths(*resource): | ||
113 | 74 | """Iterator of configuration paths. | ||
114 | 75 | |||
115 | 76 | Return an iterator which gives each directory named 'resource' in | ||
116 | 77 | the configuration search path. Information provided by earlier | ||
117 | 78 | directories should take precedence over later ones (ie, the user's | ||
118 | 79 | config dir comes first). | ||
119 | 80 | """ | ||
120 | 81 | resource = os.path.join(*resource) | ||
121 | 82 | assert not resource.startswith('/') | ||
122 | 83 | for config_dir in get_xdg_config_dirs(): | ||
123 | 84 | path = os.path.join(config_dir, resource.encode('utf-8')) | ||
124 | 85 | # access the file system always with unicode | ||
125 | 86 | # to properly behave in some operating systems | ||
126 | 87 | if os.path.exists(unicode_path(path)): | ||
127 | 88 | yield path | ||
128 | 89 | |||
129 | 90 | |||
130 | 91 | def load_data_paths(*resource): | ||
131 | 92 | """Iterator of data paths. | ||
132 | 93 | |||
133 | 94 | Return an iterator which gives each directory named 'resource' in | ||
134 | 95 | the stored data search path. Information provided by earlier | ||
135 | 96 | directories should take precedence over later ones. | ||
136 | 97 | """ | ||
137 | 98 | resource = os.path.join(*resource) | ||
138 | 99 | assert not resource.startswith('/') | ||
139 | 100 | for data_dir in get_xdg_data_dirs(): | ||
140 | 101 | path = os.path.join(data_dir, resource.encode('utf-8')) | ||
141 | 102 | # access the file system always with unicode | ||
142 | 103 | # to properly behave in some operating systems | ||
143 | 104 | if os.path.exists(unicode_path(path)): | ||
144 | 105 | yield path | ||
145 | 106 | |||
146 | 107 | |||
147 | 108 | def load_first_config(*resource): | ||
148 | 109 | """Returns the first result from load_config_paths, or None if nothing | ||
149 | 110 | is found to load. | ||
150 | 111 | """ | ||
151 | 112 | for path in load_config_paths(*resource): | ||
152 | 113 | return path | ||
153 | 114 | return None | ||
154 | 115 | |||
155 | 116 | |||
156 | 117 | def save_config_path(*resource): | ||
157 | 118 | """Path to save configuration. | ||
158 | 119 | |||
159 | 120 | Ensure $XDG_CONFIG_HOME/<resource>/ exists, and return its path. | ||
160 | 121 | 'resource' should normally be the name of your application. Use this | ||
161 | 122 | when SAVING configuration settings. Use the xdg_config_dirs variable | ||
162 | 123 | for loading. | ||
163 | 124 | """ | ||
164 | 125 | resource = os.path.join(*resource) | ||
165 | 126 | assert not resource.startswith('/') | ||
166 | 127 | path = os.path.join(get_xdg_config_home(), resource.encode('utf-8')) | ||
167 | 128 | # access the file system always with unicode | ||
168 | 129 | # to properly behave in some operating systems | ||
169 | 130 | if not os.path.isdir(unicode_path(path)): | ||
170 | 131 | os.makedirs(unicode_path(path), 0o700) | ||
171 | 132 | return path | ||
172 | 133 | |||
173 | 134 | |||
174 | 135 | def save_data_path(*resource): | ||
175 | 136 | """Path to save data. | ||
176 | 137 | |||
177 | 138 | Ensure $XDG_DATA_HOME/<resource>/ exists, and return its path. | ||
178 | 139 | 'resource' should normally be the name of your application. Use this | ||
179 | 140 | when STORING a resource. Use the xdg_data_dirs variable for loading. | ||
180 | 141 | """ | ||
181 | 142 | resource = os.path.join(*resource) | ||
182 | 143 | assert not resource.startswith('/') | ||
183 | 144 | path = os.path.join(get_xdg_data_home(), resource.encode('utf-8')) | ||
184 | 145 | # access the file system always with unicode | ||
185 | 146 | # to properly behave in some operating systems | ||
186 | 147 | if not os.path.isdir(unicode_path(path)): | ||
187 | 148 | os.makedirs(unicode_path(path), 0o700) | ||
188 | 149 | return path | ||
189 | 150 | |||
190 | 151 | |||
191 | 152 | # pylint: disable=C0103 | ||
192 | 153 | xdg_cache_home = get_xdg_cache_home() | ||
193 | 154 | xdg_config_home = get_xdg_config_home() | ||
194 | 155 | xdg_data_home = get_xdg_data_home() | ||
195 | 156 | |||
196 | 157 | xdg_config_dirs = [x for x in get_xdg_config_dirs() if x] | ||
197 | 158 | xdg_data_dirs = [x for x in get_xdg_data_dirs() if x] | ||
198 | 159 | # pylint: disable=C0103 | ||
199 | 0 | 160 | ||
200 | === added file 'contrib/dirspec/utils.py' | |||
201 | --- contrib/dirspec/utils.py 1970-01-01 00:00:00 +0000 | |||
202 | +++ contrib/dirspec/utils.py 2018-05-30 21:37:37 +0000 | |||
203 | @@ -0,0 +1,188 @@ | |||
204 | 1 | # -*- coding: utf-8 -*- | ||
205 | 2 | # | ||
206 | 3 | # Copyright 2011-2012 Canonical Ltd. | ||
207 | 4 | # | ||
208 | 5 | # This program is free software: you can redistribute it and/or modify | ||
209 | 6 | # it under the terms of the GNU Lesser General Public License version 3 | ||
210 | 7 | # as published by the Free Software Foundation. | ||
211 | 8 | # | ||
212 | 9 | # This program is distributed in the hope that it will be useful, | ||
213 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
214 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
215 | 12 | # GNU Lesser General Public License for more details. | ||
216 | 13 | # | ||
217 | 14 | # You should have received a copy of the GNU Lesser General Public License | ||
218 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
219 | 16 | """Utilities for multiplatform support of XDG directory handling.""" | ||
220 | 17 | |||
221 | 18 | from __future__ import unicode_literals, print_function | ||
222 | 19 | |||
223 | 20 | import errno | ||
224 | 21 | import os | ||
225 | 22 | import sys | ||
226 | 23 | |||
227 | 24 | __all__ = ['user_home', | ||
228 | 25 | 'default_cache_home', | ||
229 | 26 | 'default_config_home', | ||
230 | 27 | 'default_config_path', | ||
231 | 28 | 'default_data_home', | ||
232 | 29 | 'default_data_path', | ||
233 | 30 | 'get_env_path', | ||
234 | 31 | 'get_program_path', | ||
235 | 32 | 'unicode_path', | ||
236 | 33 | ] | ||
237 | 34 | |||
238 | 35 | |||
239 | 36 | def _get_exe_path_frozen_win32(exe_name): | ||
240 | 37 | """Get path to the helper .exe on packaged windows.""" | ||
241 | 38 | # all the .exes are in the same place on windows: | ||
242 | 39 | cur_exec_path = os.path.abspath(sys.executable) | ||
243 | 40 | exe_dir = os.path.dirname(cur_exec_path) | ||
244 | 41 | return os.path.join(exe_dir, exe_name + ".exe") | ||
245 | 42 | |||
246 | 43 | |||
247 | 44 | def _get_exe_path_frozen_darwin(exe_name, app_names): | ||
248 | 45 | """Get path to the sub-app executable on packaged darwin.""" | ||
249 | 46 | |||
250 | 47 | sub_app_name = app_names[exe_name] | ||
251 | 48 | main_app_dir = "".join(__file__.partition(".app")[:-1]) | ||
252 | 49 | main_app_resources_dir = os.path.join(main_app_dir, | ||
253 | 50 | "Contents", | ||
254 | 51 | "Resources") | ||
255 | 52 | exe_bin = os.path.join(main_app_resources_dir, | ||
256 | 53 | sub_app_name, | ||
257 | 54 | "Contents", "MacOS", | ||
258 | 55 | exe_name) | ||
259 | 56 | return exe_bin | ||
260 | 57 | |||
261 | 58 | |||
262 | 59 | def get_program_path(program_name, *args, **kwargs): | ||
263 | 60 | """Given a program name, returns the path to run that program. | ||
264 | 61 | |||
265 | 62 | Raises OSError if the program is not found. | ||
266 | 63 | |||
267 | 64 | :param program_name: The name of the program to find. For darwin and win32 | ||
268 | 65 | platforms, the behavior is changed slightly, when sys.frozen is set, | ||
269 | 66 | to look in the packaged program locations for the program. | ||
270 | 67 | :param search_dirs: A list of directories to look for the program in. This | ||
271 | 68 | is only available as a keyword argument. | ||
272 | 69 | :param app_names: A dict of program names mapped to sub-app names. Used | ||
273 | 70 | for discovering paths in embedded .app bundles on the darwin platform. | ||
274 | 71 | This is only available as a keyword argument. | ||
275 | 72 | :return: The path to the discovered program. | ||
276 | 73 | """ | ||
277 | 74 | search_dirs = kwargs.get('fallback_dirs', None) | ||
278 | 75 | app_names = kwargs.get('app_names', None) | ||
279 | 76 | |||
280 | 77 | if getattr(sys, "frozen", None) is not None: | ||
281 | 78 | if sys.platform == 'win32': | ||
282 | 79 | program_path = _get_exe_path_frozen_win32(program_name) | ||
283 | 80 | elif sys.platform == 'darwin': | ||
284 | 81 | program_path = _get_exe_path_frozen_darwin(program_name, | ||
285 | 82 | app_names) | ||
286 | 83 | else: | ||
287 | 84 | raise Exception("Unsupported platform for frozen execution: %r" % | ||
288 | 85 | sys.platform) | ||
289 | 86 | else: | ||
290 | 87 | if search_dirs is not None: | ||
291 | 88 | for dirname in search_dirs: | ||
292 | 89 | program_path = os.path.join(dirname, program_name) | ||
293 | 90 | if os.path.exists(program_path): | ||
294 | 91 | return program_path | ||
295 | 92 | else: | ||
296 | 93 | # Check in normal system $PATH, if no fallback dirs specified | ||
297 | 94 | from distutils.spawn import find_executable | ||
298 | 95 | program_path = find_executable(program_name) | ||
299 | 96 | |||
300 | 97 | if program_path is None or not os.path.exists(program_path): | ||
301 | 98 | raise OSError(errno.ENOENT, | ||
302 | 99 | "Could not find executable %r" % program_name) | ||
303 | 100 | |||
304 | 101 | return program_path | ||
305 | 102 | |||
306 | 103 | |||
307 | 104 | def get_env_path(key, default): | ||
308 | 105 | """Get a UTF-8 encoded path from an environment variable.""" | ||
309 | 106 | if key in os.environ: | ||
310 | 107 | # on windows, environment variables are mbcs bytes | ||
311 | 108 | # so we must turn them into utf-8 Syncdaemon paths | ||
312 | 109 | try: | ||
313 | 110 | path = os.environb.get(key.encode('utf-8')) | ||
314 | 111 | except AttributeError: | ||
315 | 112 | path = os.environ[key] | ||
316 | 113 | return path.decode(sys.getfilesystemencoding()).encode('utf-8') | ||
317 | 114 | else: | ||
318 | 115 | if not isinstance(default, bytes): | ||
319 | 116 | return default.encode('utf-8') | ||
320 | 117 | return default | ||
321 | 118 | |||
322 | 119 | |||
323 | 120 | def unicode_path(utf8path): | ||
324 | 121 | """Turn an utf8 path into a unicode path.""" | ||
325 | 122 | if isinstance(utf8path, bytes): | ||
326 | 123 | return utf8path.decode("utf-8") | ||
327 | 124 | return utf8path | ||
328 | 125 | |||
329 | 126 | |||
330 | 127 | def get_special_folders(): | ||
331 | 128 | """ Routine to grab all the Windows Special Folders locations. | ||
332 | 129 | |||
333 | 130 | If successful, returns dictionary | ||
334 | 131 | of shell folder locations indexed on Windows keyword for each; | ||
335 | 132 | otherwise, returns an empty dictionary. | ||
336 | 133 | """ | ||
337 | 134 | # pylint: disable=W0621, F0401, E0611 | ||
338 | 135 | special_folders = {} | ||
339 | 136 | |||
340 | 137 | if sys.platform == 'win32': | ||
341 | 138 | from win32com.shell import shell, shellcon | ||
342 | 139 | # CSIDL_LOCAL_APPDATA = C:\Users\<username>\AppData\Local | ||
343 | 140 | # CSIDL_PROFILE = C:\Users\<username> | ||
344 | 141 | # CSIDL_COMMON_APPDATA = C:\ProgramData | ||
345 | 142 | # More information on these constants at | ||
346 | 143 | # http://msdn.microsoft.com/en-us/library/bb762494 | ||
347 | 144 | |||
348 | 145 | # per http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181, | ||
349 | 146 | # SHGetFolderPath is deprecated, replaced by SHGetKnownFolderPath | ||
350 | 147 | # (http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188) | ||
351 | 148 | def get_path(name): | ||
352 | 149 | return shell.SHGetFolderPath(0, getattr(shellcon, name), | ||
353 | 150 | None, 0).encode('utf8') | ||
354 | 151 | special_folders['Personal'] = get_path("CSIDL_PROFILE") | ||
355 | 152 | special_folders['Local AppData'] = get_path("CSIDL_LOCAL_APPDATA") | ||
356 | 153 | special_folders['AppData'] = os.path.dirname( | ||
357 | 154 | special_folders['Local AppData']) | ||
358 | 155 | special_folders['Common AppData'] = get_path("CSIDL_COMMON_APPDATA") | ||
359 | 156 | |||
360 | 157 | return special_folders | ||
361 | 158 | |||
362 | 159 | |||
363 | 160 | # pylint: disable=C0103 | ||
364 | 161 | if sys.platform == 'win32': | ||
365 | 162 | special_folders = get_special_folders() | ||
366 | 163 | user_home = special_folders['Personal'] | ||
367 | 164 | default_config_path = special_folders['Common AppData'] | ||
368 | 165 | default_config_home = special_folders['Local AppData'] | ||
369 | 166 | default_data_path = os.path.join(default_config_path, b'xdg') | ||
370 | 167 | default_data_home = os.path.join(default_config_home, b'xdg') | ||
371 | 168 | default_cache_home = os.path.join(default_data_home, b'cache') | ||
372 | 169 | elif sys.platform == 'darwin': | ||
373 | 170 | user_home = os.path.expanduser(b'~') | ||
374 | 171 | default_cache_home = os.path.join(user_home, b'Library', b'Caches') | ||
375 | 172 | default_config_path = b'/Library/Preferences:/etc/xdg' | ||
376 | 173 | default_config_home = os.path.join(user_home, b'Library', b'Preferences') | ||
377 | 174 | default_data_path = b':'.join([b'/Library/Application Support', | ||
378 | 175 | b'/usr/local/share', | ||
379 | 176 | b'/usr/share']) | ||
380 | 177 | default_data_home = os.path.join(user_home, b'Library', | ||
381 | 178 | b'Application Support') | ||
382 | 179 | else: | ||
383 | 180 | user_home = os.path.expanduser(b'~') | ||
384 | 181 | default_cache_home = os.path.join(user_home, | ||
385 | 182 | b'.cache') | ||
386 | 183 | default_config_path = b'/etc/xdg' | ||
387 | 184 | default_config_home = os.path.join(user_home, | ||
388 | 185 | b'.config') | ||
389 | 186 | default_data_path = b'/usr/local/share:/usr/share' | ||
390 | 187 | default_data_home = os.path.join(user_home, | ||
391 | 188 | b'.local', b'share') | ||
392 | 0 | 189 | ||
393 | === added file 'contrib/u1trial' | |||
394 | --- contrib/u1trial 1970-01-01 00:00:00 +0000 | |||
395 | +++ contrib/u1trial 2018-05-30 21:37:37 +0000 | |||
396 | @@ -0,0 +1,40 @@ | |||
397 | 1 | #! /usr/bin/python | ||
398 | 2 | # | ||
399 | 3 | # Copyright 2009-2012 Canonical Ltd. | ||
400 | 4 | # | ||
401 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
402 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
403 | 7 | # by the Free Software Foundation. | ||
404 | 8 | # | ||
405 | 9 | # This program is distributed in the hope that it will be useful, but | ||
406 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
407 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
408 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
409 | 13 | # | ||
410 | 14 | # You should have received a copy of the GNU General Public License along | ||
411 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
412 | 16 | # | ||
413 | 17 | # In addition, as a special exception, the copyright holders give | ||
414 | 18 | # permission to link the code of portions of this program with the | ||
415 | 19 | # OpenSSL library under certain conditions as described in each | ||
416 | 20 | # individual source file, and distribute linked combinations | ||
417 | 21 | # including the two. | ||
418 | 22 | # You must obey the GNU General Public License in all respects | ||
419 | 23 | # for all of the code used other than OpenSSL. If you modify | ||
420 | 24 | # file(s) with this exception, you may extend this exception to your | ||
421 | 25 | # version of the file(s), but you are not obligated to do so. If you | ||
422 | 26 | # do not wish to do so, delete this exception statement from your | ||
423 | 27 | # version. If you delete this exception statement from all source | ||
424 | 28 | # files in the program, then also delete it here. | ||
425 | 29 | """Test runner which works with special services and main loops.""" | ||
426 | 30 | |||
427 | 31 | import os | ||
428 | 32 | import sys | ||
429 | 33 | |||
430 | 34 | sys.path.insert(0, os.path.abspath(".")) | ||
431 | 35 | |||
432 | 36 | from ubuntuone.devtools.runners import main # noqa | ||
433 | 37 | |||
434 | 38 | |||
435 | 39 | if __name__ == '__main__': | ||
436 | 40 | main() | ||
437 | 0 | 41 | ||
438 | === added file 'data/dbus-session.conf.in' | |||
439 | --- data/dbus-session.conf.in 1970-01-01 00:00:00 +0000 | |||
440 | +++ data/dbus-session.conf.in 2018-05-30 21:37:37 +0000 | |||
441 | @@ -0,0 +1,63 @@ | |||
442 | 1 | <!-- This configuration file controls our test-only session bus --> | ||
443 | 2 | |||
444 | 3 | <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" | ||
445 | 4 | "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> | ||
446 | 5 | <busconfig> | ||
447 | 6 | <!-- We only use a session bus --> | ||
448 | 7 | <type>session</type> | ||
449 | 8 | |||
450 | 9 | <listen>@ADDRESS@</listen> | ||
451 | 10 | |||
452 | 11 | <!-- Load our own services. | ||
453 | 12 | To make other dbus service in this session bus, just add another servicedir entry. --> | ||
454 | 13 | <servicedir>dbus-session</servicedir> | ||
455 | 14 | <!-- Load the standard session services --> | ||
456 | 15 | <!--standard_session_servicedirs /--> | ||
457 | 16 | |||
458 | 17 | <policy context="default"> | ||
459 | 18 | <!-- Allow everything to be sent --> | ||
460 | 19 | <allow send_destination="*" eavesdrop="true"/> | ||
461 | 20 | <!-- Allow everything to be received --> | ||
462 | 21 | <allow eavesdrop="true"/> | ||
463 | 22 | <!-- Allow anyone to own anything --> | ||
464 | 23 | <allow own="*"/> | ||
465 | 24 | </policy> | ||
466 | 25 | |||
467 | 26 | <!-- Config files are placed here that among other things, | ||
468 | 27 | further restrict the above policy for specific services. --> | ||
469 | 28 | <includedir>/etc/dbus-1/session.d</includedir> | ||
470 | 29 | |||
471 | 30 | <!-- raise the service start timeout to 40 seconds as it can timeout | ||
472 | 31 | on the live cd on slow machines --> | ||
473 | 32 | <limit name="service_start_timeout">60000</limit> | ||
474 | 33 | |||
475 | 34 | <!-- This is included last so local configuration can override what's | ||
476 | 35 | in this standard file --> | ||
477 | 36 | <include ignore_missing="yes">session-local.conf</include> | ||
478 | 37 | |||
479 | 38 | <include ignore_missing="yes" if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include> | ||
480 | 39 | |||
481 | 40 | <!-- For the session bus, override the default relatively-low limits | ||
482 | 41 | with essentially infinite limits, since the bus is just running | ||
483 | 42 | as the user anyway, using up bus resources is not something we need | ||
484 | 43 | to worry about. In some cases, we do set the limits lower than | ||
485 | 44 | "all available memory" if exceeding the limit is almost certainly a bug, | ||
486 | 45 | having the bus enforce a limit is nicer than a huge memory leak. But the | ||
487 | 46 | intent is that these limits should never be hit. --> | ||
488 | 47 | |||
489 | 48 | <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max --> | ||
490 | 49 | <limit name="max_incoming_bytes">1000000000</limit> | ||
491 | 50 | <limit name="max_outgoing_bytes">1000000000</limit> | ||
492 | 51 | <limit name="max_message_size">1000000000</limit> | ||
493 | 52 | <limit name="service_start_timeout">120000</limit> | ||
494 | 53 | <limit name="auth_timeout">240000</limit> | ||
495 | 54 | <limit name="max_completed_connections">100000</limit> | ||
496 | 55 | <limit name="max_incomplete_connections">10000</limit> | ||
497 | 56 | <limit name="max_connections_per_user">100000</limit> | ||
498 | 57 | <limit name="max_pending_service_starts">10000</limit> | ||
499 | 58 | <limit name="max_names_per_connection">50000</limit> | ||
500 | 59 | <limit name="max_match_rules_per_connection">50000</limit> | ||
501 | 60 | <limit name="max_replies_per_connection">50000</limit> | ||
502 | 61 | <limit name="reply_timeout">300000</limit> | ||
503 | 62 | |||
504 | 63 | </busconfig> | ||
505 | 0 | 64 | ||
506 | === modified file 'dependencies-devel.txt' | |||
507 | --- dependencies-devel.txt 2018-03-18 11:59:08 +0000 | |||
508 | +++ dependencies-devel.txt 2018-05-30 21:37:37 +0000 | |||
509 | @@ -1,5 +1,2 @@ | |||
510 | 1 | bzr | 1 | bzr |
511 | 2 | make | 2 | make |
512 | 3 | python-mocker | ||
513 | 4 | ubuntuone-dev-tools | ||
514 | 5 | virtualenv | ||
515 | 6 | 3 | ||
516 | === modified file 'dependencies.txt' | |||
517 | --- dependencies.txt 2018-04-14 23:34:20 +0000 | |||
518 | +++ dependencies.txt 2018-05-30 21:37:37 +0000 | |||
519 | @@ -1,8 +1,5 @@ | |||
528 | 1 | gir1.2-soup-2.4 | 1 | libgirepository1.0-dev |
529 | 2 | python-configglue | 2 | libgtk2.0-dev |
530 | 3 | python-dirspec | 3 | pkg-config |
531 | 4 | python-distutils-extra | 4 | python-dev |
532 | 5 | python-gi | 5 | virtualenv |
525 | 6 | python-protobuf | ||
526 | 7 | python-pyinotify | ||
527 | 8 | python-twisted | ||
533 | 9 | 6 | ||
534 | === modified file 'requirements-devel.txt' | |||
535 | --- requirements-devel.txt 2018-03-18 15:03:09 +0000 | |||
536 | +++ requirements-devel.txt 2018-05-30 21:37:37 +0000 | |||
537 | @@ -1,1 +1,3 @@ | |||
538 | 1 | coverage==3.7.1 | ||
539 | 1 | flake8==3.5.0 | 2 | flake8==3.5.0 |
540 | 3 | mocker==1.1.1 | ||
541 | 2 | 4 | ||
542 | === modified file 'requirements.txt' | |||
543 | --- requirements.txt 2018-04-14 23:34:20 +0000 | |||
544 | +++ requirements.txt 2018-05-30 21:37:37 +0000 | |||
545 | @@ -1,2 +1,7 @@ | |||
546 | 1 | configglue==1.1.3.post0 | ||
547 | 2 | dbus-python==1.2.8 | ||
548 | 3 | magicicadaprotocol==2.0 | ||
549 | 4 | PyGObject==3.28.2 | ||
550 | 5 | pyinotify==0.9.6 | ||
551 | 1 | Send2Trash==1.5.0 | 6 | Send2Trash==1.5.0 |
553 | 2 | magicicadaprotocol==2.0 | 7 | Twisted==18.4.0 |
554 | 3 | 8 | ||
555 | === modified file 'run-tests' | |||
556 | --- run-tests 2018-03-18 11:59:08 +0000 | |||
557 | +++ run-tests 2018-05-30 21:37:37 +0000 | |||
558 | @@ -49,5 +49,5 @@ | |||
559 | 49 | 49 | ||
560 | 50 | echo "*** Running test suite for ""$MODULE"" ***" | 50 | echo "*** Running test suite for ""$MODULE"" ***" |
561 | 51 | export SSL_CERTIFICATES_DIR=/etc/ssl/certs | 51 | export SSL_CERTIFICATES_DIR=/etc/ssl/certs |
563 | 52 | .env/bin/python /usr/bin/u1trial -i "$IGNORE_FILES" -p "$IGNORE_PATHS" $MODULE | 52 | .env/bin/python contrib/u1trial -i "$IGNORE_FILES" -p "$IGNORE_PATHS" $MODULE |
564 | 53 | rm -rf _trial_temp | 53 | rm -rf _trial_temp |
565 | 54 | 54 | ||
566 | === modified file 'setup.py' | |||
567 | --- setup.py 2018-04-23 02:21:03 +0000 | |||
568 | +++ setup.py 2018-05-30 21:37:37 +0000 | |||
569 | @@ -32,15 +32,9 @@ | |||
570 | 32 | import os | 32 | import os |
571 | 33 | import sys | 33 | import sys |
572 | 34 | 34 | ||
582 | 35 | try: | 35 | from setuptools import setup |
583 | 36 | from DistUtilsExtra.command import build_extra, build_i18n | 36 | from setuptools.command.install import install |
584 | 37 | import DistUtilsExtra.auto | 37 | from distutils.command import build, clean |
576 | 38 | except ImportError: | ||
577 | 39 | print >> sys.stderr, 'To build this program you need '\ | ||
578 | 40 | 'https://launchpad.net/python-distutils-extra' | ||
579 | 41 | raise | ||
580 | 42 | assert DistUtilsExtra.auto.__version__ >= '2.18', \ | ||
581 | 43 | 'needs DistUtilsExtra.auto >= 2.18' | ||
585 | 44 | 38 | ||
586 | 45 | 39 | ||
587 | 46 | PROJECT_NAME = 'magicicada-client' | 40 | PROJECT_NAME = 'magicicada-client' |
588 | @@ -83,7 +77,7 @@ | |||
589 | 83 | out_file.write(content) | 77 | out_file.write(content) |
590 | 84 | 78 | ||
591 | 85 | 79 | ||
593 | 86 | class Install(DistUtilsExtra.auto.install_auto): | 80 | class Install(install): |
594 | 87 | """Class to install proper files.""" | 81 | """Class to install proper files.""" |
595 | 88 | 82 | ||
596 | 89 | def run(self): | 83 | def run(self): |
597 | @@ -110,7 +104,8 @@ | |||
598 | 110 | prefix = self.install_data.replace( | 104 | prefix = self.install_data.replace( |
599 | 111 | self.root if self.root is not None else '', '') | 105 | self.root if self.root is not None else '', '') |
600 | 112 | replace_variables(SERVICE_FILES, prefix) | 106 | replace_variables(SERVICE_FILES, prefix) |
602 | 113 | DistUtilsExtra.auto.install_auto.run(self) | 107 | install.run(self) |
603 | 108 | |||
604 | 114 | # Replace the CLIENTDEFS paths here, so that we can do it directly in | 109 | # Replace the CLIENTDEFS paths here, so that we can do it directly in |
605 | 115 | # the installed copy, rather than the lcoal copy. This allows us to | 110 | # the installed copy, rather than the lcoal copy. This allows us to |
606 | 116 | # have a semi-generated version for use in tests, and a full version | 111 | # have a semi-generated version for use in tests, and a full version |
607 | @@ -127,7 +122,7 @@ | |||
608 | 127 | out_file.write(content) | 122 | out_file.write(content) |
609 | 128 | 123 | ||
610 | 129 | 124 | ||
612 | 130 | class Build(build_extra.build_extra): | 125 | class Build(build.build): |
613 | 131 | """Build PyQt (.ui) files and resources.""" | 126 | """Build PyQt (.ui) files and resources.""" |
614 | 132 | 127 | ||
615 | 133 | description = "build PyQt GUIs (.ui) and resources (.qrc)" | 128 | description = "build PyQt GUIs (.ui) and resources (.qrc)" |
616 | @@ -135,10 +130,10 @@ | |||
617 | 135 | def run(self): | 130 | def run(self): |
618 | 136 | """Execute the command.""" | 131 | """Execute the command.""" |
619 | 137 | replace_variables(BUILD_FILES) | 132 | replace_variables(BUILD_FILES) |
624 | 138 | build_extra.build_extra.run(self) | 133 | build.build.run(self) |
625 | 139 | 134 | ||
626 | 140 | 135 | ||
627 | 141 | class Clean(DistUtilsExtra.auto.clean_build_tree): | 136 | class Clean(clean.clean): |
628 | 142 | """Class to clean up after the build.""" | 137 | """Class to clean up after the build.""" |
629 | 143 | 138 | ||
630 | 144 | def run(self): | 139 | def run(self): |
631 | @@ -147,24 +142,7 @@ | |||
632 | 147 | if os.path.exists(built_file): | 142 | if os.path.exists(built_file): |
633 | 148 | os.unlink(built_file) | 143 | os.unlink(built_file) |
634 | 149 | 144 | ||
653 | 150 | DistUtilsExtra.auto.clean_build_tree.run(self) | 145 | clean.clean.run(self) |
636 | 151 | |||
637 | 152 | |||
638 | 153 | class BuildLocale(build_i18n.build_i18n): | ||
639 | 154 | """Work around a bug in DistUtilsExtra.""" | ||
640 | 155 | |||
641 | 156 | def run(self): | ||
642 | 157 | """Magic.""" | ||
643 | 158 | build_i18n.build_i18n.run(self) | ||
644 | 159 | i = 0 | ||
645 | 160 | for df in self.distribution.data_files: | ||
646 | 161 | if df[0].startswith('etc/xdg/'): | ||
647 | 162 | if sys.platform not in ('darwin', 'win32'): | ||
648 | 163 | new_df = (df[0].replace('etc/xdg/', '/etc/xdg/'), df[1]) | ||
649 | 164 | self.distribution.data_files[i] = new_df | ||
650 | 165 | else: | ||
651 | 166 | self.distribution.data_files.pop(i) | ||
652 | 167 | i += 1 | ||
654 | 168 | 146 | ||
655 | 169 | 147 | ||
656 | 170 | def set_py2exe_paths(): | 148 | def set_py2exe_paths(): |
657 | @@ -191,10 +169,9 @@ | |||
658 | 191 | 169 | ||
659 | 192 | 170 | ||
660 | 193 | cmdclass = { | 171 | cmdclass = { |
661 | 194 | 'install': Install, | ||
662 | 195 | 'build': Build, | 172 | 'build': Build, |
663 | 196 | 'clean': Clean, | 173 | 'clean': Clean, |
665 | 197 | 'build_i18n': BuildLocale, | 174 | 'install': Install, |
666 | 198 | } | 175 | } |
667 | 199 | 176 | ||
668 | 200 | bin_scripts = [ | 177 | bin_scripts = [ |
669 | @@ -236,7 +213,7 @@ | |||
670 | 236 | scripts.extend(bin_scripts) | 213 | scripts.extend(bin_scripts) |
671 | 237 | extra = {} | 214 | extra = {} |
672 | 238 | 215 | ||
674 | 239 | DistUtilsExtra.auto.setup( | 216 | setup( |
675 | 240 | name=PROJECT_NAME, | 217 | name=PROJECT_NAME, |
676 | 241 | version=VERSION, | 218 | version=VERSION, |
677 | 242 | license='GPL v3', | 219 | license='GPL v3', |
678 | 243 | 220 | ||
679 | === added directory 'ubuntuone/devtools' | |||
680 | === added file 'ubuntuone/devtools/__init__.py' | |||
681 | --- ubuntuone/devtools/__init__.py 1970-01-01 00:00:00 +0000 | |||
682 | +++ ubuntuone/devtools/__init__.py 2018-05-30 21:37:37 +0000 | |||
683 | @@ -0,0 +1,1 @@ | |||
684 | 1 | """Testing utilities for Ubuntu One client code.""" | ||
685 | 0 | 2 | ||
686 | === added file 'ubuntuone/devtools/compat.py' | |||
687 | --- ubuntuone/devtools/compat.py 1970-01-01 00:00:00 +0000 | |||
688 | +++ ubuntuone/devtools/compat.py 2018-05-30 21:37:37 +0000 | |||
689 | @@ -0,0 +1,49 @@ | |||
690 | 1 | # -*- coding: utf-8 -*- | ||
691 | 2 | # | ||
692 | 3 | # Copyright 2012 Canonical Ltd. | ||
693 | 4 | # | ||
694 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
695 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
696 | 7 | # by the Free Software Foundation. | ||
697 | 8 | # | ||
698 | 9 | # This program is distributed in the hope that it will be useful, but | ||
699 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
700 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
701 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
702 | 13 | # | ||
703 | 14 | # You should have received a copy of the GNU General Public License along | ||
704 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
705 | 16 | # | ||
706 | 17 | # In addition, as a special exception, the copyright holders give | ||
707 | 18 | # permission to link the code of portions of this program with the | ||
708 | 19 | # OpenSSL library under certain conditions as described in each | ||
709 | 20 | # individual source file, and distribute linked combinations | ||
710 | 21 | # including the two. | ||
711 | 22 | # You must obey the GNU General Public License in all respects | ||
712 | 23 | # for all of the code used other than OpenSSL. If you modify | ||
713 | 24 | # file(s) with this exception, you may extend this exception to your | ||
714 | 25 | # version of the file(s), but you are not obligated to do so. If you | ||
715 | 26 | # do not wish to do so, delete this exception statement from your | ||
716 | 27 | # version. If you delete this exception statement from all source | ||
717 | 28 | # files in the program, then also delete it here. | ||
718 | 29 | """Python 2 and 3 compatibility.""" | ||
719 | 30 | |||
720 | 31 | from __future__ import unicode_literals | ||
721 | 32 | |||
722 | 33 | # The following approach was outlined in Lennart Regebro's | ||
723 | 34 | # "Porting to Python 3" book. | ||
724 | 35 | # http://python3porting.com/noconv.html#more-bytes-strings-and-unicode | ||
725 | 36 | |||
726 | 37 | import sys | ||
727 | 38 | |||
728 | 39 | # Disable redefined builtin, invalid name warning | ||
729 | 40 | # pylint: disable=W0622,C0103 | ||
730 | 41 | |||
731 | 42 | if sys.version_info < (3,): | ||
732 | 43 | text_type = unicode | ||
733 | 44 | binary_type = str | ||
734 | 45 | basestring = basestring | ||
735 | 46 | else: | ||
736 | 47 | text_type = str | ||
737 | 48 | binary_type = bytes | ||
738 | 49 | basestring = str | ||
739 | 0 | 50 | ||
740 | === added file 'ubuntuone/devtools/errors.py' | |||
741 | --- ubuntuone/devtools/errors.py 1970-01-01 00:00:00 +0000 | |||
742 | +++ ubuntuone/devtools/errors.py 2018-05-30 21:37:37 +0000 | |||
743 | @@ -0,0 +1,35 @@ | |||
744 | 1 | # Copyright 2012 Canonical Ltd. | ||
745 | 2 | # | ||
746 | 3 | # This program is free software: you can redistribute it and/or modify it | ||
747 | 4 | # under the terms of the GNU General Public License version 3, as published | ||
748 | 5 | # by the Free Software Foundation. | ||
749 | 6 | # | ||
750 | 7 | # This program is distributed in the hope that it will be useful, but | ||
751 | 8 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
752 | 9 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
753 | 10 | # PURPOSE. See the GNU General Public License for more details. | ||
754 | 11 | # | ||
755 | 12 | # You should have received a copy of the GNU General Public License along | ||
756 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
757 | 14 | # | ||
758 | 15 | # In addition, as a special exception, the copyright holders give | ||
759 | 16 | # permission to link the code of portions of this program with the | ||
760 | 17 | # OpenSSL library under certain conditions as described in each | ||
761 | 18 | # individual source file, and distribute linked combinations | ||
762 | 19 | # including the two. | ||
763 | 20 | # You must obey the GNU General Public License in all respects | ||
764 | 21 | # for all of the code used other than OpenSSL. If you modify | ||
765 | 22 | # file(s) with this exception, you may extend this exception to your | ||
766 | 23 | # version of the file(s), but you are not obligated to do so. If you | ||
767 | 24 | # do not wish to do so, delete this exception statement from your | ||
768 | 25 | # version. If you delete this exception statement from all source | ||
769 | 26 | # files in the program, then also delete it here. | ||
770 | 27 | """Custom error types for Ubuntu One developer tools.""" | ||
771 | 28 | |||
772 | 29 | |||
773 | 30 | class TestError(Exception): | ||
774 | 31 | """An error occurred in attempting to load or start the tests.""" | ||
775 | 32 | |||
776 | 33 | |||
777 | 34 | class UsageError(Exception): | ||
778 | 35 | """An error occurred in parsing the command line arguments.""" | ||
779 | 0 | 36 | ||
780 | === added file 'ubuntuone/devtools/handlers.py' | |||
781 | --- ubuntuone/devtools/handlers.py 1970-01-01 00:00:00 +0000 | |||
782 | +++ ubuntuone/devtools/handlers.py 2018-05-30 21:37:37 +0000 | |||
783 | @@ -0,0 +1,97 @@ | |||
784 | 1 | # -*- coding: utf-8 -*- | ||
785 | 2 | |||
786 | 3 | # Author: Guillermo Gonzalez <guillermo.gonzalez@canonical.com> | ||
787 | 4 | # Author: Facundo Batista <facundo@canonical.com> | ||
788 | 5 | # | ||
789 | 6 | # Copyright 2009-2012 Canonical Ltd. | ||
790 | 7 | # | ||
791 | 8 | # This program is free software: you can redistribute it and/or modify it | ||
792 | 9 | # under the terms of the GNU General Public License version 3, as published | ||
793 | 10 | # by the Free Software Foundation. | ||
794 | 11 | # | ||
795 | 12 | # This program is distributed in the hope that it will be useful, but | ||
796 | 13 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
797 | 14 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
798 | 15 | # PURPOSE. See the GNU General Public License for more details. | ||
799 | 16 | # | ||
800 | 17 | # You should have received a copy of the GNU General Public License along | ||
801 | 18 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
802 | 19 | # | ||
803 | 20 | # In addition, as a special exception, the copyright holders give | ||
804 | 21 | # permission to link the code of portions of this program with the | ||
805 | 22 | # OpenSSL library under certain conditions as described in each | ||
806 | 23 | # individual source file, and distribute linked combinations | ||
807 | 24 | # including the two. | ||
808 | 25 | # You must obey the GNU General Public License in all respects | ||
809 | 26 | # for all of the code used other than OpenSSL. If you modify | ||
810 | 27 | # file(s) with this exception, you may extend this exception to your | ||
811 | 28 | # version of the file(s), but you are not obligated to do so. If you | ||
812 | 29 | # do not wish to do so, delete this exception statement from your | ||
813 | 30 | # version. If you delete this exception statement from all source | ||
814 | 31 | # files in the program, then also delete it here. | ||
815 | 32 | """Set of helpers handlers.""" | ||
816 | 33 | |||
817 | 34 | from __future__ import print_function | ||
818 | 35 | |||
819 | 36 | import logging | ||
820 | 37 | |||
821 | 38 | |||
822 | 39 | class MementoHandler(logging.Handler): | ||
823 | 40 | """ A handler class which store logging records in a list """ | ||
824 | 41 | |||
825 | 42 | def __init__(self, *args, **kwargs): | ||
826 | 43 | """ Create the instance, and add a records attribute. """ | ||
827 | 44 | logging.Handler.__init__(self, *args, **kwargs) | ||
828 | 45 | self.records = [] | ||
829 | 46 | self.debug = False | ||
830 | 47 | |||
831 | 48 | def emit(self, record): | ||
832 | 49 | """ Just add the record to self.records. """ | ||
833 | 50 | self.format(record) | ||
834 | 51 | self.records.append(record) | ||
835 | 52 | |||
836 | 53 | def dump_contents(self, msgs): | ||
837 | 54 | """Dumps the contents of the MementoHandler.""" | ||
838 | 55 | if self.debug: | ||
839 | 56 | print("Expecting:") | ||
840 | 57 | for msg in msgs: | ||
841 | 58 | print("\t", msg) | ||
842 | 59 | print("MementoHandler contents:") | ||
843 | 60 | for rec in self.records: | ||
844 | 61 | print("\t", rec.exc_info) | ||
845 | 62 | print("\t", logging.getLevelName(rec.levelno)) | ||
846 | 63 | print("\t\t", rec.message) | ||
847 | 64 | print("\t\t", rec.exc_text) | ||
848 | 65 | |||
849 | 66 | def check(self, level, *msgs): | ||
850 | 67 | """Verifies that the msgs are logged in the specified level""" | ||
851 | 68 | for rec in self.records: | ||
852 | 69 | if rec.levelno == level and all(m in rec.message for m in msgs): | ||
853 | 70 | return rec | ||
854 | 71 | self.dump_contents(msgs) | ||
855 | 72 | return False | ||
856 | 73 | |||
857 | 74 | def check_debug(self, *msgs): | ||
858 | 75 | """Shortcut for checking in DEBUG.""" | ||
859 | 76 | return self.check(logging.DEBUG, *msgs) | ||
860 | 77 | |||
861 | 78 | def check_info(self, *msgs): | ||
862 | 79 | """Shortcut for checking in INFO.""" | ||
863 | 80 | return self.check(logging.INFO, *msgs) | ||
864 | 81 | |||
865 | 82 | def check_warning(self, *msgs): | ||
866 | 83 | """Shortcut for checking in WARNING.""" | ||
867 | 84 | return self.check(logging.WARNING, *msgs) | ||
868 | 85 | |||
869 | 86 | def check_error(self, *msgs): | ||
870 | 87 | """Shortcut for checking in ERROR.""" | ||
871 | 88 | return self.check(logging.ERROR, *msgs) | ||
872 | 89 | |||
873 | 90 | def check_exception(self, exception_info, *msgs): | ||
874 | 91 | """Shortcut for checking exceptions.""" | ||
875 | 92 | for rec in self.records: | ||
876 | 93 | if rec.levelno == logging.ERROR and \ | ||
877 | 94 | all(m in rec.exc_text + rec.message for m in msgs) and \ | ||
878 | 95 | exception_info in rec.exc_info: | ||
879 | 96 | return True | ||
880 | 97 | return False | ||
881 | 0 | 98 | ||
882 | === added directory 'ubuntuone/devtools/reactors' | |||
883 | === added file 'ubuntuone/devtools/reactors/__init__.py' | |||
884 | --- ubuntuone/devtools/reactors/__init__.py 1970-01-01 00:00:00 +0000 | |||
885 | +++ ubuntuone/devtools/reactors/__init__.py 2018-05-30 21:37:37 +0000 | |||
886 | @@ -0,0 +1,1 @@ | |||
887 | 1 | """Twisted reactors for testing.""" | ||
888 | 0 | 2 | ||
889 | === added file 'ubuntuone/devtools/reactors/gi.py' | |||
890 | --- ubuntuone/devtools/reactors/gi.py 1970-01-01 00:00:00 +0000 | |||
891 | +++ ubuntuone/devtools/reactors/gi.py 2018-05-30 21:37:37 +0000 | |||
892 | @@ -0,0 +1,53 @@ | |||
893 | 1 | # Copyright 2009-2012 Canonical Ltd. | ||
894 | 2 | # | ||
895 | 3 | # This program is free software: you can redistribute it and/or modify it | ||
896 | 4 | # under the terms of the GNU General Public License version 3, as published | ||
897 | 5 | # by the Free Software Foundation. | ||
898 | 6 | # | ||
899 | 7 | # This program is distributed in the hope that it will be useful, but | ||
900 | 8 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
901 | 9 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
902 | 10 | # PURPOSE. See the GNU General Public License for more details. | ||
903 | 11 | # | ||
904 | 12 | # You should have received a copy of the GNU General Public License along | ||
905 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
906 | 14 | # | ||
907 | 15 | # In addition, as a special exception, the copyright holders give | ||
908 | 16 | # permission to link the code of portions of this program with the | ||
909 | 17 | # OpenSSL library under certain conditions as described in each | ||
910 | 18 | # individual source file, and distribute linked combinations | ||
911 | 19 | # including the two. | ||
912 | 20 | # You must obey the GNU General Public License in all respects | ||
913 | 21 | # for all of the code used other than OpenSSL. If you modify | ||
914 | 22 | # file(s) with this exception, you may extend this exception to your | ||
915 | 23 | # version of the file(s), but you are not obligated to do so. If you | ||
916 | 24 | # do not wish to do so, delete this exception statement from your | ||
917 | 25 | # version. If you delete this exception statement from all source | ||
918 | 26 | # files in the program, then also delete it here. | ||
919 | 27 | """The introspection based main loop integration reactor for testing.""" | ||
920 | 28 | |||
921 | 29 | REACTOR_URL = 'http://twistedmatrix.com/trac/ticket/4558' | ||
922 | 30 | |||
923 | 31 | |||
924 | 32 | def load_reactor(reactor_name=None): | ||
925 | 33 | """Load the reactor module and return it.""" | ||
926 | 34 | return __import__(reactor_name, None, None, ['']) | ||
927 | 35 | |||
928 | 36 | |||
929 | 37 | def install(options=None): | ||
930 | 38 | """Install the reactor and parse any options we might need.""" | ||
931 | 39 | reactor = None | ||
932 | 40 | if options is not None and options['gui']: | ||
933 | 41 | try: | ||
934 | 42 | reactor = load_reactor('twisted.internet.gtk3reactor') | ||
935 | 43 | except ImportError: | ||
936 | 44 | print('Falling back to gtk2reactor module.') | ||
937 | 45 | reactor = load_reactor('twisted.internet.gtk2reactor') | ||
938 | 46 | else: | ||
939 | 47 | try: | ||
940 | 48 | reactor = load_reactor('twisted.internet.gireactor') | ||
941 | 49 | except ImportError: | ||
942 | 50 | print('Falling back to glib2reactor module.') | ||
943 | 51 | reactor = load_reactor('twisted.internet.glib2reactor') | ||
944 | 52 | |||
945 | 53 | reactor.install() | ||
946 | 0 | 54 | ||
947 | === added directory 'ubuntuone/devtools/runners' | |||
948 | === added file 'ubuntuone/devtools/runners/__init__.py' | |||
949 | --- ubuntuone/devtools/runners/__init__.py 1970-01-01 00:00:00 +0000 | |||
950 | +++ ubuntuone/devtools/runners/__init__.py 2018-05-30 21:37:37 +0000 | |||
951 | @@ -0,0 +1,304 @@ | |||
952 | 1 | # Copyright 2009-2012 Canonical Ltd. | ||
953 | 2 | # | ||
954 | 3 | # This program is free software: you can redistribute it and/or modify it | ||
955 | 4 | # under the terms of the GNU General Public License version 3, as published | ||
956 | 5 | # by the Free Software Foundation. | ||
957 | 6 | # | ||
958 | 7 | # This program is distributed in the hope that it will be useful, but | ||
959 | 8 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
960 | 9 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
961 | 10 | # PURPOSE. See the GNU General Public License for more details. | ||
962 | 11 | # | ||
963 | 12 | # You should have received a copy of the GNU General Public License along | ||
964 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
965 | 14 | # | ||
966 | 15 | # In addition, as a special exception, the copyright holders give | ||
967 | 16 | # permission to link the code of portions of this program with the | ||
968 | 17 | # OpenSSL library under certain conditions as described in each | ||
969 | 18 | # individual source file, and distribute linked combinations | ||
970 | 19 | # including the two. | ||
971 | 20 | # You must obey the GNU General Public License in all respects | ||
972 | 21 | # for all of the code used other than OpenSSL. If you modify | ||
973 | 22 | # file(s) with this exception, you may extend this exception to your | ||
974 | 23 | # version of the file(s), but you are not obligated to do so. If you | ||
975 | 24 | # do not wish to do so, delete this exception statement from your | ||
976 | 25 | # version. If you delete this exception statement from all source | ||
977 | 26 | # files in the program, then also delete it here. | ||
978 | 27 | """The base test runner object.""" | ||
979 | 28 | |||
980 | 29 | from __future__ import print_function, unicode_literals | ||
981 | 30 | |||
982 | 31 | import coverage | ||
983 | 32 | import gc | ||
984 | 33 | import inspect | ||
985 | 34 | import os | ||
986 | 35 | import re | ||
987 | 36 | import sys | ||
988 | 37 | import unittest | ||
989 | 38 | |||
990 | 39 | from ubuntuone.devtools.errors import TestError, UsageError | ||
991 | 40 | from ubuntuone.devtools.testing.txcheck import TXCheckSuite | ||
992 | 41 | from ubuntuone.devtools.utils import OptionParser | ||
993 | 42 | from ubuntuone.devtools.compat import text_type | ||
994 | 43 | |||
995 | 44 | __all__ = ['BaseTestOptions', 'BaseTestRunner', 'main'] | ||
996 | 45 | |||
997 | 46 | |||
998 | 47 | def _is_in_ignored_path(testcase, paths): | ||
999 | 48 | """Return if the testcase is in one of the ignored paths.""" | ||
1000 | 49 | for ignored_path in paths: | ||
1001 | 50 | if testcase.startswith(ignored_path): | ||
1002 | 51 | return True | ||
1003 | 52 | return False | ||
1004 | 53 | |||
1005 | 54 | |||
1006 | 55 | class BaseTestRunner(object): | ||
1007 | 56 | """The base test runner type. Does not actually run tests.""" | ||
1008 | 57 | |||
1009 | 58 | def __init__(self, options=None, *args, **kwargs): | ||
1010 | 59 | super(BaseTestRunner, self).__init__(*args, **kwargs) | ||
1011 | 60 | |||
1012 | 61 | # set $HOME to the _trial_temp dir, to avoid breaking user files | ||
1013 | 62 | trial_temp_dir = os.environ.get('TRIAL_TEMP_DIR', os.getcwd()) | ||
1014 | 63 | homedir = os.path.join(trial_temp_dir, options['temp-directory']) | ||
1015 | 64 | os.environ['HOME'] = homedir | ||
1016 | 65 | |||
1017 | 66 | # setup $XDG_*_HOME variables and create the directories | ||
1018 | 67 | xdg_cache = os.path.join(homedir, 'xdg_cache') | ||
1019 | 68 | xdg_config = os.path.join(homedir, 'xdg_config') | ||
1020 | 69 | xdg_data = os.path.join(homedir, 'xdg_data') | ||
1021 | 70 | os.environ['XDG_CACHE_HOME'] = xdg_cache | ||
1022 | 71 | os.environ['XDG_CONFIG_HOME'] = xdg_config | ||
1023 | 72 | os.environ['XDG_DATA_HOME'] = xdg_data | ||
1024 | 73 | |||
1025 | 74 | if not os.path.exists(xdg_cache): | ||
1026 | 75 | os.makedirs(xdg_cache) | ||
1027 | 76 | if not os.path.exists(xdg_config): | ||
1028 | 77 | os.makedirs(xdg_config) | ||
1029 | 78 | if not os.path.exists(xdg_data): | ||
1030 | 79 | os.makedirs(xdg_data) | ||
1031 | 80 | |||
1032 | 81 | # setup the ROOTDIR env var | ||
1033 | 82 | os.environ['ROOTDIR'] = os.getcwd() | ||
1034 | 83 | |||
1035 | 84 | # Need an attribute for tempdir so we can use it later | ||
1036 | 85 | self.tempdir = homedir | ||
1037 | 86 | self.working_dir = os.path.join(self.tempdir, 'trial') | ||
1038 | 87 | |||
1039 | 88 | self.source_files = [] | ||
1040 | 89 | self.required_services = [] | ||
1041 | 90 | |||
1042 | 91 | def _load_unittest(self, relpath): | ||
1043 | 92 | """Load unit tests from a Python module with the given 'relpath'.""" | ||
1044 | 93 | assert relpath.endswith(".py"), ( | ||
1045 | 94 | "%s does not appear to be a Python module" % relpath) | ||
1046 | 95 | if not os.path.basename(relpath).startswith('test_'): | ||
1047 | 96 | return | ||
1048 | 97 | modpath = relpath.replace(os.path.sep, ".")[:-3] | ||
1049 | 98 | module = __import__(modpath, None, None, [""]) | ||
1050 | 99 | |||
1051 | 100 | # If the module specifies required_services, make sure we get them | ||
1052 | 101 | members = [x[1] for x in inspect.getmembers(module, inspect.isclass)] | ||
1053 | 102 | for member_type in members: | ||
1054 | 103 | if hasattr(member_type, 'required_services'): | ||
1055 | 104 | member = member_type() | ||
1056 | 105 | for service in member.required_services(): | ||
1057 | 106 | if service not in self.required_services: | ||
1058 | 107 | self.required_services.append(service) | ||
1059 | 108 | del member | ||
1060 | 109 | gc.collect() | ||
1061 | 110 | |||
1062 | 111 | # If the module has a 'suite' or 'test_suite' function, use that | ||
1063 | 112 | # to load the tests. | ||
1064 | 113 | if hasattr(module, "suite"): | ||
1065 | 114 | return module.suite() | ||
1066 | 115 | elif hasattr(module, "test_suite"): | ||
1067 | 116 | return module.test_suite() | ||
1068 | 117 | else: | ||
1069 | 118 | return unittest.defaultTestLoader.loadTestsFromModule(module) | ||
1070 | 119 | |||
1071 | 120 | def _collect_tests(self, path, test_pattern, ignored_modules, | ||
1072 | 121 | ignored_paths): | ||
1073 | 122 | """Return the set of unittests.""" | ||
1074 | 123 | suite = TXCheckSuite() | ||
1075 | 124 | if test_pattern: | ||
1076 | 125 | pattern = re.compile('.*%s.*' % test_pattern) | ||
1077 | 126 | else: | ||
1078 | 127 | pattern = None | ||
1079 | 128 | |||
1080 | 129 | # Disable this lint warning as we need to access _tests in the | ||
1081 | 130 | # test suites, to collect the tests | ||
1082 | 131 | # pylint: disable=W0212 | ||
1083 | 132 | if path: | ||
1084 | 133 | try: | ||
1085 | 134 | module_suite = self._load_unittest(path) | ||
1086 | 135 | if pattern: | ||
1087 | 136 | for inner_suite in module_suite._tests: | ||
1088 | 137 | for test in inner_suite._tests: | ||
1089 | 138 | if pattern.match(test.id()): | ||
1090 | 139 | suite.addTest(test) | ||
1091 | 140 | else: | ||
1092 | 141 | suite.addTests(module_suite) | ||
1093 | 142 | return suite | ||
1094 | 143 | except AssertionError: | ||
1095 | 144 | pass | ||
1096 | 145 | else: | ||
1097 | 146 | raise TestError('Path should be defined.') | ||
1098 | 147 | |||
1099 | 148 | # We don't use the dirs variable, so ignore the warning | ||
1100 | 149 | # pylint: disable=W0612 | ||
1101 | 150 | for root, dirs, files in os.walk(path): | ||
1102 | 151 | for test in files: | ||
1103 | 152 | filepath = os.path.join(root, test) | ||
1104 | 153 | if test.endswith(".py") and test not in ignored_modules and \ | ||
1105 | 154 | not _is_in_ignored_path(filepath, ignored_paths): | ||
1106 | 155 | self.source_files.append(filepath) | ||
1107 | 156 | if test.startswith("test_"): | ||
1108 | 157 | module_suite = self._load_unittest(filepath) | ||
1109 | 158 | if pattern: | ||
1110 | 159 | for inner_suite in module_suite._tests: | ||
1111 | 160 | for test in inner_suite._tests: | ||
1112 | 161 | if pattern.match(test.id()): | ||
1113 | 162 | suite.addTest(test) | ||
1114 | 163 | else: | ||
1115 | 164 | suite.addTests(module_suite) | ||
1116 | 165 | return suite | ||
1117 | 166 | |||
1118 | 167 | def get_suite(self, config): | ||
1119 | 168 | """Get the test suite to use.""" | ||
1120 | 169 | suite = unittest.TestSuite() | ||
1121 | 170 | for path in config['tests']: | ||
1122 | 171 | suite.addTest(self._collect_tests(path, config['test'], | ||
1123 | 172 | config['ignore-modules'], | ||
1124 | 173 | config['ignore-paths'])) | ||
1125 | 174 | if config['loop']: | ||
1126 | 175 | old_suite = suite | ||
1127 | 176 | suite = unittest.TestSuite() | ||
1128 | 177 | for _ in range(config['loop']): | ||
1129 | 178 | suite.addTest(old_suite) | ||
1130 | 179 | |||
1131 | 180 | return suite | ||
1132 | 181 | |||
1133 | 182 | def run_tests(self, suite): | ||
1134 | 183 | """Run the test suite.""" | ||
1135 | 184 | return False | ||
1136 | 185 | |||
1137 | 186 | |||
1138 | 187 | class BaseTestOptions(OptionParser): | ||
1139 | 188 | """Base options for our test runner.""" | ||
1140 | 189 | |||
1141 | 190 | optFlags = [['coverage', 'c', 'Generate a coverage report for the tests.'], | ||
1142 | 191 | ['gui', None, 'Use the GUI mode of some runners.'], | ||
1143 | 192 | ['help', 'h', ''], | ||
1144 | 193 | ['help-runners', None, 'List information about test runners.'], | ||
1145 | 194 | ] | ||
1146 | 195 | |||
1147 | 196 | optParameters = [['test', 't', None, None], | ||
1148 | 197 | ['loop', None, 1, None], | ||
1149 | 198 | ['ignore-modules', 'i', '', None], | ||
1150 | 199 | ['ignore-paths', 'p', '', None], | ||
1151 | 200 | ['runner', None, 'txrunner', None], | ||
1152 | 201 | ['temp-directory', None, b'_trial_temp', None], | ||
1153 | 202 | ] | ||
1154 | 203 | |||
1155 | 204 | def __init__(self, *args, **kwargs): | ||
1156 | 205 | super(BaseTestOptions, self).__init__(*args, **kwargs) | ||
1157 | 206 | |||
1158 | 207 | def opt_help_runners(self): | ||
1159 | 208 | """List the runners which are supported.""" | ||
1160 | 209 | sys.exit(0) | ||
1161 | 210 | |||
1162 | 211 | def opt_ignore_modules(self, option): | ||
1163 | 212 | """Comma-separate list of test modules to ignore, | ||
1164 | 213 | e.g: test_gtk.py, test_account.py | ||
1165 | 214 | """ | ||
1166 | 215 | self['ignore-modules'] = list(map(text_type.strip, option.split(','))) | ||
1167 | 216 | |||
1168 | 217 | def opt_ignore_paths(self, option): | ||
1169 | 218 | """Comma-separated list of relative paths to ignore, | ||
1170 | 219 | e.g: tests/platform/windows, tests/platform/macosx | ||
1171 | 220 | """ | ||
1172 | 221 | self['ignore-paths'] = list(map(text_type.strip, option.split(','))) | ||
1173 | 222 | |||
1174 | 223 | def opt_loop(self, option): | ||
1175 | 224 | """Loop tests the specified number of times.""" | ||
1176 | 225 | try: | ||
1177 | 226 | self['loop'] = int(option) | ||
1178 | 227 | except ValueError: | ||
1179 | 228 | raise UsageError('A positive integer value must be specified.') | ||
1180 | 229 | |||
1181 | 230 | def opt_temp_directory(self, option): | ||
1182 | 231 | """Path to use as a working directory for tests. | ||
1183 | 232 | [default: _trial_temp] | ||
1184 | 233 | """ | ||
1185 | 234 | self['temp-directory'] = option | ||
1186 | 235 | |||
1187 | 236 | def opt_test(self, option): | ||
1188 | 237 | """Run specific tests, e.g: className.methodName""" | ||
1189 | 238 | self['test'] = option | ||
1190 | 239 | |||
1191 | 240 | # We use some camelcase names for trial compatibility here. | ||
1192 | 241 | def parseArgs(self, *args): | ||
1193 | 242 | """Handle the extra arguments.""" | ||
1194 | 243 | if isinstance(self.tests, set): | ||
1195 | 244 | self['tests'].update(args) | ||
1196 | 245 | elif isinstance(self.tests, list): | ||
1197 | 246 | self['tests'].extend(args) | ||
1198 | 247 | |||
1199 | 248 | |||
1200 | 249 | def _get_runner_options(runner_name): | ||
1201 | 250 | """Return the test runner module, and its options object.""" | ||
1202 | 251 | module_name = 'ubuntuone.devtools.runners.%s' % runner_name | ||
1203 | 252 | runner = __import__(module_name, None, None, ['']) | ||
1204 | 253 | options = None | ||
1205 | 254 | if getattr(runner, 'TestOptions', None) is not None: | ||
1206 | 255 | options = runner.TestOptions() | ||
1207 | 256 | if options is None: | ||
1208 | 257 | options = BaseTestOptions() | ||
1209 | 258 | return (runner, options) | ||
1210 | 259 | |||
1211 | 260 | |||
1212 | 261 | def main(): | ||
1213 | 262 | """Do the deed.""" | ||
1214 | 263 | if len(sys.argv) == 1: | ||
1215 | 264 | sys.argv.append('--help') | ||
1216 | 265 | |||
1217 | 266 | try: | ||
1218 | 267 | pos = sys.argv.index('--runner') | ||
1219 | 268 | runner_name = sys.argv.pop(pos + 1) | ||
1220 | 269 | sys.argv.pop(pos) | ||
1221 | 270 | except ValueError: | ||
1222 | 271 | runner_name = 'txrunner' | ||
1223 | 272 | finally: | ||
1224 | 273 | runner, options = _get_runner_options(runner_name) | ||
1225 | 274 | options.parseOptions() | ||
1226 | 275 | |||
1227 | 276 | test_runner = runner.TestRunner(options=options) | ||
1228 | 277 | suite = test_runner.get_suite(options) | ||
1229 | 278 | |||
1230 | 279 | if options['coverage']: | ||
1231 | 280 | coverage.erase() | ||
1232 | 281 | coverage.start() | ||
1233 | 282 | |||
1234 | 283 | running_services = [] | ||
1235 | 284 | |||
1236 | 285 | succeeded = False | ||
1237 | 286 | try: | ||
1238 | 287 | # Start any required services | ||
1239 | 288 | for service_obj in test_runner.required_services: | ||
1240 | 289 | service = service_obj() | ||
1241 | 290 | service.start_service(tempdir=test_runner.tempdir) | ||
1242 | 291 | running_services.append(service) | ||
1243 | 292 | |||
1244 | 293 | succeeded = test_runner.run_tests(suite) | ||
1245 | 294 | finally: | ||
1246 | 295 | # Stop all the running services | ||
1247 | 296 | for service in running_services: | ||
1248 | 297 | service.stop_service() | ||
1249 | 298 | |||
1250 | 299 | if options['coverage']: | ||
1251 | 300 | coverage.stop() | ||
1252 | 301 | coverage.report(test_runner.source_files, ignore_errors=True, | ||
1253 | 302 | show_missing=False) | ||
1254 | 303 | |||
1255 | 304 | sys.exit(not succeeded) | ||
1256 | 0 | 305 | ||
1257 | === added file 'ubuntuone/devtools/runners/txrunner.py' | |||
1258 | --- ubuntuone/devtools/runners/txrunner.py 1970-01-01 00:00:00 +0000 | |||
1259 | +++ ubuntuone/devtools/runners/txrunner.py 2018-05-30 21:37:37 +0000 | |||
1260 | @@ -0,0 +1,133 @@ | |||
1261 | 1 | # Copyright 2009-2012 Canonical Ltd. | ||
1262 | 2 | # | ||
1263 | 3 | # This program is free software: you can redistribute it and/or modify it | ||
1264 | 4 | # under the terms of the GNU General Public License version 3, as published | ||
1265 | 5 | # by the Free Software Foundation. | ||
1266 | 6 | # | ||
1267 | 7 | # This program is distributed in the hope that it will be useful, but | ||
1268 | 8 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1269 | 9 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1270 | 10 | # PURPOSE. See the GNU General Public License for more details. | ||
1271 | 11 | # | ||
1272 | 12 | # You should have received a copy of the GNU General Public License along | ||
1273 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1274 | 14 | # | ||
1275 | 15 | # In addition, as a special exception, the copyright holders give | ||
1276 | 16 | # permission to link the code of portions of this program with the | ||
1277 | 17 | # OpenSSL library under certain conditions as described in each | ||
1278 | 18 | # individual source file, and distribute linked combinations | ||
1279 | 19 | # including the two. | ||
1280 | 20 | # You must obey the GNU General Public License in all respects | ||
1281 | 21 | # for all of the code used other than OpenSSL. If you modify | ||
1282 | 22 | # file(s) with this exception, you may extend this exception to your | ||
1283 | 23 | # version of the file(s), but you are not obligated to do so. If you | ||
1284 | 24 | # do not wish to do so, delete this exception statement from your | ||
1285 | 25 | # version. If you delete this exception statement from all source | ||
1286 | 26 | # files in the program, then also delete it here. | ||
1287 | 27 | """The twisted test runner and options.""" | ||
1288 | 28 | |||
1289 | 29 | from __future__ import print_function, unicode_literals | ||
1290 | 30 | |||
1291 | 31 | import sys | ||
1292 | 32 | |||
1293 | 33 | from twisted.scripts import trial | ||
1294 | 34 | from twisted.trial.runner import TrialRunner | ||
1295 | 35 | |||
1296 | 36 | from ubuntuone.devtools.errors import TestError | ||
1297 | 37 | from ubuntuone.devtools.runners import BaseTestOptions, BaseTestRunner | ||
1298 | 38 | |||
1299 | 39 | __all__ = ['TestRunner', 'TestOptions'] | ||
1300 | 40 | |||
1301 | 41 | |||
1302 | 42 | class TestRunner(BaseTestRunner, TrialRunner): | ||
1303 | 43 | """The twisted test runner implementation.""" | ||
1304 | 44 | |||
1305 | 45 | def __init__(self, options=None): | ||
1306 | 46 | # Handle running trial in debug or dry-run mode | ||
1307 | 47 | self.config = options | ||
1308 | 48 | |||
1309 | 49 | try: | ||
1310 | 50 | reactor_name = ('ubuntuone.devtools.reactors.%s' % | ||
1311 | 51 | self.config['reactor']) | ||
1312 | 52 | reactor = __import__(reactor_name, None, None, ['']) | ||
1313 | 53 | except ImportError: | ||
1314 | 54 | raise TestError('The specified reactor is not supported.') | ||
1315 | 55 | else: | ||
1316 | 56 | try: | ||
1317 | 57 | reactor.install(options=self.config) | ||
1318 | 58 | except ImportError: | ||
1319 | 59 | raise TestError( | ||
1320 | 60 | 'The Python package providing the requested reactor is ' | ||
1321 | 61 | 'not installed. You can find it here: %s' % | ||
1322 | 62 | reactor.REACTOR_URL) | ||
1323 | 63 | |||
1324 | 64 | mode = None | ||
1325 | 65 | if self.config['debug']: | ||
1326 | 66 | mode = TrialRunner.DEBUG | ||
1327 | 67 | if self.config['dry-run']: | ||
1328 | 68 | mode = TrialRunner.DRY_RUN | ||
1329 | 69 | |||
1330 | 70 | # Hook up to the parent test runner | ||
1331 | 71 | super(TestRunner, self).__init__( | ||
1332 | 72 | options=options, | ||
1333 | 73 | reporterFactory=self.config['reporter'], | ||
1334 | 74 | mode=mode, | ||
1335 | 75 | profile=self.config['profile'], | ||
1336 | 76 | logfile=self.config['logfile'], | ||
1337 | 77 | tracebackFormat=self.config['tbformat'], | ||
1338 | 78 | realTimeErrors=self.config['rterrors'], | ||
1339 | 79 | uncleanWarnings=self.config['unclean-warnings'], | ||
1340 | 80 | forceGarbageCollection=self.config['force-gc']) | ||
1341 | 81 | # Named for trial compatibility. | ||
1342 | 82 | # pylint: disable=C0103 | ||
1343 | 83 | self.workingDirectory = self.working_dir | ||
1344 | 84 | # pylint: enable=C0103 | ||
1345 | 85 | |||
1346 | 86 | def run_tests(self, suite): | ||
1347 | 87 | """Run the twisted test suite.""" | ||
1348 | 88 | if self.config['until-failure']: | ||
1349 | 89 | result = self.runUntilFailure(suite) | ||
1350 | 90 | else: | ||
1351 | 91 | result = self.run(suite) | ||
1352 | 92 | return result.wasSuccessful() | ||
1353 | 93 | |||
1354 | 94 | |||
1355 | 95 | def _get_default_reactor(): | ||
1356 | 96 | """Return the platform-dependent default reactor to use.""" | ||
1357 | 97 | default_reactor = 'gi' | ||
1358 | 98 | if sys.platform in ['darwin', 'win32']: | ||
1359 | 99 | default_reactor = 'twisted' | ||
1360 | 100 | return default_reactor | ||
1361 | 101 | |||
1362 | 102 | |||
1363 | 103 | class TestOptions(trial.Options, BaseTestOptions): | ||
1364 | 104 | """Class for twisted options handling.""" | ||
1365 | 105 | |||
1366 | 106 | optFlags = [["help-reactors", None], | ||
1367 | 107 | ] | ||
1368 | 108 | |||
1369 | 109 | optParameters = [["reactor", "r", _get_default_reactor()], | ||
1370 | 110 | ] | ||
1371 | 111 | |||
1372 | 112 | def __init__(self, *args, **kwargs): | ||
1373 | 113 | super(TestOptions, self).__init__(*args, **kwargs) | ||
1374 | 114 | self['rterrors'] = True | ||
1375 | 115 | |||
1376 | 116 | def opt_coverage(self, option): | ||
1377 | 117 | """Handle special flags.""" | ||
1378 | 118 | self['coverage'] = True | ||
1379 | 119 | opt_c = opt_coverage | ||
1380 | 120 | |||
1381 | 121 | def opt_help_reactors(self): | ||
1382 | 122 | """Help on available reactors for use with tests""" | ||
1383 | 123 | synopsis = ('') | ||
1384 | 124 | print(synopsis) | ||
1385 | 125 | print('Need to get list of reactors and print them here.\n') | ||
1386 | 126 | sys.exit(0) | ||
1387 | 127 | |||
1388 | 128 | def opt_reactor(self, option): | ||
1389 | 129 | """Which reactor to use (see --help-reactors for a list | ||
1390 | 130 | of possibilities) | ||
1391 | 131 | """ | ||
1392 | 132 | self['reactor'] = option | ||
1393 | 133 | opt_r = opt_reactor | ||
1394 | 0 | 134 | ||
1395 | === added directory 'ubuntuone/devtools/services' | |||
1396 | === added file 'ubuntuone/devtools/services/__init__.py' | |||
1397 | --- ubuntuone/devtools/services/__init__.py 1970-01-01 00:00:00 +0000 | |||
1398 | +++ ubuntuone/devtools/services/__init__.py 2018-05-30 21:37:37 +0000 | |||
1399 | @@ -0,0 +1,66 @@ | |||
1400 | 1 | # | ||
1401 | 2 | # Copyright 2011-2012 Canonical Ltd. | ||
1402 | 3 | # | ||
1403 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
1404 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
1405 | 6 | # by the Free Software Foundation. | ||
1406 | 7 | # | ||
1407 | 8 | # This program is distributed in the hope that it will be useful, but | ||
1408 | 9 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1409 | 10 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1410 | 11 | # PURPOSE. See the GNU General Public License for more details. | ||
1411 | 12 | # | ||
1412 | 13 | # You should have received a copy of the GNU General Public License along | ||
1413 | 14 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1414 | 15 | # | ||
1415 | 16 | # In addition, as a special exception, the copyright holders give | ||
1416 | 17 | # permission to link the code of portions of this program with the | ||
1417 | 18 | # OpenSSL library under certain conditions as described in each | ||
1418 | 19 | # individual source file, and distribute linked combinations | ||
1419 | 20 | # including the two. | ||
1420 | 21 | # You must obey the GNU General Public License in all respects | ||
1421 | 22 | # for all of the code used other than OpenSSL. If you modify | ||
1422 | 23 | # file(s) with this exception, you may extend this exception to your | ||
1423 | 24 | # version of the file(s), but you are not obligated to do so. If you | ||
1424 | 25 | # do not wish to do so, delete this exception statement from your | ||
1425 | 26 | # version. If you delete this exception statement from all source | ||
1426 | 27 | # files in the program, then also delete it here. | ||
1427 | 28 | """Service runners for testing.""" | ||
1428 | 29 | |||
1429 | 30 | import os | ||
1430 | 31 | import socket | ||
1431 | 32 | |||
1432 | 33 | from dirspec.basedir import load_data_paths | ||
1433 | 34 | |||
1434 | 35 | |||
1435 | 36 | def find_config_file(in_config_file): | ||
1436 | 37 | """Find the first appropriate conf to use.""" | ||
1437 | 38 | # In case we're running from within the source tree | ||
1438 | 39 | path = os.path.abspath(os.path.join(os.path.dirname(__file__), | ||
1439 | 40 | os.path.pardir, os.path.pardir, | ||
1440 | 41 | os.path.pardir, | ||
1441 | 42 | "data", in_config_file)) | ||
1442 | 43 | if not os.path.exists(path): | ||
1443 | 44 | # Use the installed file in $pkgdatadir as source | ||
1444 | 45 | for path in load_data_paths("ubuntuone-dev-tools", in_config_file): | ||
1445 | 46 | if os.path.exists(path): | ||
1446 | 47 | break | ||
1447 | 48 | |||
1448 | 49 | # Check to make sure we didn't just fall out of the loop | ||
1449 | 50 | if not os.path.exists(path): | ||
1450 | 51 | raise IOError('Could not locate suitable %s' % in_config_file) | ||
1451 | 52 | return path | ||
1452 | 53 | |||
1453 | 54 | |||
1454 | 55 | def get_arbitrary_port(): | ||
1455 | 56 | """ | ||
1456 | 57 | Find an unused port, and return it. | ||
1457 | 58 | |||
1458 | 59 | There might be a small race condition here, but we aren't | ||
1459 | 60 | worried about it. | ||
1460 | 61 | """ | ||
1461 | 62 | sock = socket.socket() | ||
1462 | 63 | sock.bind(('localhost', 0)) | ||
1463 | 64 | _, port = sock.getsockname() | ||
1464 | 65 | sock.close() | ||
1465 | 66 | return port | ||
1466 | 0 | 67 | ||
1467 | === added file 'ubuntuone/devtools/services/dbus.py' | |||
1468 | --- ubuntuone/devtools/services/dbus.py 1970-01-01 00:00:00 +0000 | |||
1469 | +++ ubuntuone/devtools/services/dbus.py 2018-05-30 21:37:37 +0000 | |||
1470 | @@ -0,0 +1,121 @@ | |||
1471 | 1 | # | ||
1472 | 2 | # Author: Guillermo Gonzalez <guillermo.gonzalez@canonical.com> | ||
1473 | 3 | # | ||
1474 | 4 | # Copyright 2009-2012 Canonical Ltd. | ||
1475 | 5 | # | ||
1476 | 6 | # This program is free software: you can redistribute it and/or modify it | ||
1477 | 7 | # under the terms of the GNU General Public License version 3, as published | ||
1478 | 8 | # by the Free Software Foundation. | ||
1479 | 9 | # | ||
1480 | 10 | # This program is distributed in the hope that it will be useful, but | ||
1481 | 11 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1482 | 12 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1483 | 13 | # PURPOSE. See the GNU General Public License for more details. | ||
1484 | 14 | # | ||
1485 | 15 | # You should have received a copy of the GNU General Public License along | ||
1486 | 16 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1487 | 17 | # | ||
1488 | 18 | # In addition, as a special exception, the copyright holders give | ||
1489 | 19 | # permission to link the code of portions of this program with the | ||
1490 | 20 | # OpenSSL library under certain conditions as described in each | ||
1491 | 21 | # individual source file, and distribute linked combinations | ||
1492 | 22 | # including the two. | ||
1493 | 23 | # You must obey the GNU General Public License in all respects | ||
1494 | 24 | # for all of the code used other than OpenSSL. If you modify | ||
1495 | 25 | # file(s) with this exception, you may extend this exception to your | ||
1496 | 26 | # version of the file(s), but you are not obligated to do so. If you | ||
1497 | 27 | # do not wish to do so, delete this exception statement from your | ||
1498 | 28 | # version. If you delete this exception statement from all source | ||
1499 | 29 | # files in the program, then also delete it here. | ||
1500 | 30 | """Utilities for finding and running a dbus session bus for testing.""" | ||
1501 | 31 | |||
1502 | 32 | from __future__ import unicode_literals | ||
1503 | 33 | |||
1504 | 34 | import os | ||
1505 | 35 | import signal | ||
1506 | 36 | import subprocess | ||
1507 | 37 | |||
1508 | 38 | from distutils.spawn import find_executable | ||
1509 | 39 | |||
1510 | 40 | # pylint: disable=F0401,E0611 | ||
1511 | 41 | try: | ||
1512 | 42 | from urllib.parse import quote | ||
1513 | 43 | except ImportError: | ||
1514 | 44 | from urllib import quote | ||
1515 | 45 | # pylint: enable=F0401,E0611 | ||
1516 | 46 | |||
1517 | 47 | from ubuntuone.devtools.services import find_config_file | ||
1518 | 48 | DBUS_CONFIG_FILE = 'dbus-session.conf.in' | ||
1519 | 49 | |||
1520 | 50 | |||
1521 | 51 | class DBusLaunchError(Exception): | ||
1522 | 52 | """Error while launching dbus-daemon""" | ||
1523 | 53 | pass | ||
1524 | 54 | |||
1525 | 55 | |||
1526 | 56 | class NotFoundError(Exception): | ||
1527 | 57 | """Not found error""" | ||
1528 | 58 | pass | ||
1529 | 59 | |||
1530 | 60 | |||
1531 | 61 | class DBusRunner(object): | ||
1532 | 62 | """Class for running dbus-daemon with a private session.""" | ||
1533 | 63 | |||
1534 | 64 | def __init__(self): | ||
1535 | 65 | self.dbus_address = None | ||
1536 | 66 | self.dbus_pid = None | ||
1537 | 67 | self.running = False | ||
1538 | 68 | self.config_file = None | ||
1539 | 69 | |||
1540 | 70 | def _generate_config_file(self, tempdir=None): | ||
1541 | 71 | """Find the first appropriate dbus-session.conf to use.""" | ||
1542 | 72 | # load the config file | ||
1543 | 73 | path = find_config_file(DBUS_CONFIG_FILE) | ||
1544 | 74 | # replace config settings | ||
1545 | 75 | self.config_file = os.path.join(tempdir, 'dbus-session.conf') | ||
1546 | 76 | dbus_address = 'unix:tmpdir=%s' % quote(tempdir) | ||
1547 | 77 | with open(path) as in_file: | ||
1548 | 78 | content = in_file.read() | ||
1549 | 79 | with open(self.config_file, 'w') as out_file: | ||
1550 | 80 | out_file.write(content.replace('@ADDRESS@', dbus_address)) | ||
1551 | 81 | |||
1552 | 82 | def start_service(self, tempdir=None): | ||
1553 | 83 | """Start our own session bus daemon for testing.""" | ||
1554 | 84 | dbus = find_executable("dbus-daemon") | ||
1555 | 85 | if not dbus: | ||
1556 | 86 | raise NotFoundError("dbus-daemon was not found.") | ||
1557 | 87 | |||
1558 | 88 | self._generate_config_file(tempdir) | ||
1559 | 89 | |||
1560 | 90 | dbus_args = ["--fork", | ||
1561 | 91 | "--config-file=" + self.config_file, | ||
1562 | 92 | "--print-address=1", | ||
1563 | 93 | "--print-pid=2"] | ||
1564 | 94 | sp = subprocess.Popen([dbus] + dbus_args, | ||
1565 | 95 | bufsize=4096, stdout=subprocess.PIPE, | ||
1566 | 96 | stderr=subprocess.PIPE) | ||
1567 | 97 | |||
1568 | 98 | # Call wait here as under the qt4 reactor we get an error about | ||
1569 | 99 | # interrupted system call if we don't. | ||
1570 | 100 | sp.wait() | ||
1571 | 101 | self.dbus_address = b"".join(sp.stdout.readlines()).strip() | ||
1572 | 102 | self.dbus_pid = int(b"".join(sp.stderr.readlines()).strip()) | ||
1573 | 103 | |||
1574 | 104 | if self.dbus_address != "": | ||
1575 | 105 | os.environ["DBUS_SESSION_BUS_ADDRESS"] = \ | ||
1576 | 106 | self.dbus_address.decode("utf8") | ||
1577 | 107 | else: | ||
1578 | 108 | os.kill(self.dbus_pid, signal.SIGKILL) | ||
1579 | 109 | raise DBusLaunchError("There was a problem launching dbus-daemon.") | ||
1580 | 110 | self.running = True | ||
1581 | 111 | |||
1582 | 112 | def stop_service(self): | ||
1583 | 113 | """Stop our DBus session bus daemon.""" | ||
1584 | 114 | try: | ||
1585 | 115 | del os.environ["DBUS_SESSION_BUS_ADDRESS"] | ||
1586 | 116 | except KeyError: | ||
1587 | 117 | pass | ||
1588 | 118 | os.kill(self.dbus_pid, signal.SIGKILL) | ||
1589 | 119 | self.running = False | ||
1590 | 120 | os.unlink(self.config_file) | ||
1591 | 121 | self.config_file = None | ||
1592 | 0 | 122 | ||
1593 | === added directory 'ubuntuone/devtools/testcases' | |||
1594 | === added file 'ubuntuone/devtools/testcases/__init__.py' | |||
1595 | --- ubuntuone/devtools/testcases/__init__.py 1970-01-01 00:00:00 +0000 | |||
1596 | +++ ubuntuone/devtools/testcases/__init__.py 2018-05-30 21:37:37 +0000 | |||
1597 | @@ -0,0 +1,187 @@ | |||
1598 | 1 | # -*- coding: utf-8 -*- | ||
1599 | 2 | # | ||
1600 | 3 | # Copyright 2009-2012 Canonical Ltd. | ||
1601 | 4 | # | ||
1602 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
1603 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
1604 | 7 | # by the Free Software Foundation. | ||
1605 | 8 | # | ||
1606 | 9 | # This program is distributed in the hope that it will be useful, but | ||
1607 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1608 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1609 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
1610 | 13 | # | ||
1611 | 14 | # You should have received a copy of the GNU General Public License along | ||
1612 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1613 | 16 | # | ||
1614 | 17 | # In addition, as a special exception, the copyright holders give | ||
1615 | 18 | # permission to link the code of portions of this program with the | ||
1616 | 19 | # OpenSSL library under certain conditions as described in each | ||
1617 | 20 | # individual source file, and distribute linked combinations | ||
1618 | 21 | # including the two. | ||
1619 | 22 | # You must obey the GNU General Public License in all respects | ||
1620 | 23 | # for all of the code used other than OpenSSL. If you modify | ||
1621 | 24 | # file(s) with this exception, you may extend this exception to your | ||
1622 | 25 | # version of the file(s), but you are not obligated to do so. If you | ||
1623 | 26 | # do not wish to do so, delete this exception statement from your | ||
1624 | 27 | # version. If you delete this exception statement from all source | ||
1625 | 28 | # files in the program, then also delete it here. | ||
1626 | 29 | """Base tests cases and test utilities.""" | ||
1627 | 30 | |||
1628 | 31 | from __future__ import with_statement | ||
1629 | 32 | |||
1630 | 33 | import contextlib | ||
1631 | 34 | import os | ||
1632 | 35 | import shutil | ||
1633 | 36 | import sys | ||
1634 | 37 | |||
1635 | 38 | from functools import wraps | ||
1636 | 39 | |||
1637 | 40 | from twisted.trial.unittest import TestCase, SkipTest | ||
1638 | 41 | |||
1639 | 42 | |||
1640 | 43 | @contextlib.contextmanager | ||
1641 | 44 | def environ(env_var, new_value): | ||
1642 | 45 | """context manager to replace/add an environ value""" | ||
1643 | 46 | old_value = os.environ.get(env_var, None) | ||
1644 | 47 | os.environ[env_var] = new_value | ||
1645 | 48 | yield | ||
1646 | 49 | if old_value is None: | ||
1647 | 50 | os.environ.pop(env_var) | ||
1648 | 51 | else: | ||
1649 | 52 | os.environ[env_var] = old_value | ||
1650 | 53 | |||
1651 | 54 | |||
1652 | 55 | def _id(obj): | ||
1653 | 56 | """Return the obj calling the funct.""" | ||
1654 | 57 | return obj | ||
1655 | 58 | |||
1656 | 59 | |||
1657 | 60 | # pylint: disable=C0103 | ||
1658 | 61 | def skipTest(reason): | ||
1659 | 62 | """Unconditionally skip a test.""" | ||
1660 | 63 | |||
1661 | 64 | def decorator(test_item): | ||
1662 | 65 | """Decorate the test so that it is skipped.""" | ||
1663 | 66 | if not (isinstance(test_item, type) and | ||
1664 | 67 | issubclass(test_item, TestCase)): | ||
1665 | 68 | |||
1666 | 69 | @wraps(test_item) | ||
1667 | 70 | def skip_wrapper(*args, **kwargs): | ||
1668 | 71 | """Skip a test method raising an exception.""" | ||
1669 | 72 | raise SkipTest(reason) | ||
1670 | 73 | test_item = skip_wrapper | ||
1671 | 74 | |||
1672 | 75 | # tell twisted.trial.unittest to skip the test, pylint will complain | ||
1673 | 76 | # since it thinks we are redefining a name out of the scope | ||
1674 | 77 | # pylint: disable=W0621,W0612 | ||
1675 | 78 | test_item.skip = reason | ||
1676 | 79 | # pylint: enable=W0621,W0612 | ||
1677 | 80 | # because the item was skipped, we will make sure that no | ||
1678 | 81 | # services are started for it | ||
1679 | 82 | if hasattr(test_item, "required_services"): | ||
1680 | 83 | # pylint: disable=W0612 | ||
1681 | 84 | test_item.required_services = lambda *args, **kwargs: [] | ||
1682 | 85 | # pylint: enable=W0612 | ||
1683 | 86 | return test_item | ||
1684 | 87 | return decorator | ||
1685 | 88 | |||
1686 | 89 | |||
1687 | 90 | def skipIf(condition, reason): | ||
1688 | 91 | """Skip a test if the condition is true.""" | ||
1689 | 92 | if condition: | ||
1690 | 93 | return skipTest(reason) | ||
1691 | 94 | return _id | ||
1692 | 95 | |||
1693 | 96 | |||
1694 | 97 | def skipIfOS(current_os, reason): | ||
1695 | 98 | """Skip test for a particular os or lists of them.""" | ||
1696 | 99 | if os: | ||
1697 | 100 | if sys.platform in current_os or sys.platform == current_os: | ||
1698 | 101 | return skipTest(reason) | ||
1699 | 102 | return _id | ||
1700 | 103 | return _id | ||
1701 | 104 | |||
1702 | 105 | |||
1703 | 106 | def skipIfNotOS(current_os, reason): | ||
1704 | 107 | """Skip test we are not in a particular os.""" | ||
1705 | 108 | if os: | ||
1706 | 109 | if sys.platform not in current_os or \ | ||
1707 | 110 | sys.platform != current_os: | ||
1708 | 111 | return skipTest(reason) | ||
1709 | 112 | return _id | ||
1710 | 113 | return _id | ||
1711 | 114 | |||
1712 | 115 | |||
1713 | 116 | def skipIfJenkins(current_os, reason): | ||
1714 | 117 | """Skip test for a particular os or lists of them | ||
1715 | 118 | when running on Jenkins.""" | ||
1716 | 119 | if os.getenv("JENKINS", False) and (sys.platform in current_os or | ||
1717 | 120 | sys.platform == current_os): | ||
1718 | 121 | return skipTest(reason) | ||
1719 | 122 | return _id | ||
1720 | 123 | |||
1721 | 124 | |||
1722 | 125 | # pylint: enable=C0103 | ||
1723 | 126 | |||
1724 | 127 | |||
1725 | 128 | class BaseTestCase(TestCase): | ||
1726 | 129 | """Base TestCase with helper methods to handle temp dir. | ||
1727 | 130 | |||
1728 | 131 | This class provides: | ||
1729 | 132 | mktemp(name): helper to create temporary dirs | ||
1730 | 133 | rmtree(path): support read-only shares | ||
1731 | 134 | makedirs(path): support read-only shares | ||
1732 | 135 | |||
1733 | 136 | """ | ||
1734 | 137 | |||
1735 | 138 | def required_services(self): | ||
1736 | 139 | """Return the list of required services for DBusTestCase.""" | ||
1737 | 140 | return [] | ||
1738 | 141 | |||
1739 | 142 | def mktemp(self, name='temp'): | ||
1740 | 143 | """Customized mktemp that accepts an optional name argument.""" | ||
1741 | 144 | tempdir = os.path.join(self.tmpdir, name) | ||
1742 | 145 | if os.path.exists(tempdir): | ||
1743 | 146 | self.rmtree(tempdir) | ||
1744 | 147 | self.makedirs(tempdir) | ||
1745 | 148 | return tempdir | ||
1746 | 149 | |||
1747 | 150 | @property | ||
1748 | 151 | def tmpdir(self): | ||
1749 | 152 | """Default tmpdir: module/class/test_method.""" | ||
1750 | 153 | # check if we already generated the root path | ||
1751 | 154 | root_dir = getattr(self, '__root', None) | ||
1752 | 155 | if root_dir: | ||
1753 | 156 | return root_dir | ||
1754 | 157 | max_filename = 32 # some platforms limit lengths of filenames | ||
1755 | 158 | base = os.path.join(self.__class__.__module__[:max_filename], | ||
1756 | 159 | self.__class__.__name__[:max_filename], | ||
1757 | 160 | self._testMethodName[:max_filename]) | ||
1758 | 161 | # use _trial_temp dir, it should be os.gwtcwd() | ||
1759 | 162 | # define the root temp dir of the testcase, pylint: disable=W0201 | ||
1760 | 163 | self.__root = os.path.join(os.getcwd(), base) | ||
1761 | 164 | return self.__root | ||
1762 | 165 | |||
1763 | 166 | def rmtree(self, path): | ||
1764 | 167 | """Custom rmtree that handle ro parent(s) and childs.""" | ||
1765 | 168 | if not os.path.exists(path): | ||
1766 | 169 | return | ||
1767 | 170 | # change perms to rw, so we can delete the temp dir | ||
1768 | 171 | if path != getattr(self, '__root', None): | ||
1769 | 172 | os.chmod(os.path.dirname(path), 0o755) | ||
1770 | 173 | if not os.access(path, os.W_OK): | ||
1771 | 174 | os.chmod(path, 0o755) | ||
1772 | 175 | # pylint: disable=W0612 | ||
1773 | 176 | for dirpath, dirs, files in os.walk(path): | ||
1774 | 177 | for dirname in dirs: | ||
1775 | 178 | if not os.access(os.path.join(dirpath, dirname), os.W_OK): | ||
1776 | 179 | os.chmod(os.path.join(dirpath, dirname), 0o777) | ||
1777 | 180 | shutil.rmtree(path) | ||
1778 | 181 | |||
1779 | 182 | def makedirs(self, path): | ||
1780 | 183 | """Custom makedirs that handle ro parent.""" | ||
1781 | 184 | parent = os.path.dirname(path) | ||
1782 | 185 | if os.path.exists(parent): | ||
1783 | 186 | os.chmod(parent, 0o755) | ||
1784 | 187 | os.makedirs(path) | ||
1785 | 0 | 188 | ||
1786 | === added file 'ubuntuone/devtools/testcases/dbus.py' | |||
1787 | --- ubuntuone/devtools/testcases/dbus.py 1970-01-01 00:00:00 +0000 | |||
1788 | +++ ubuntuone/devtools/testcases/dbus.py 2018-05-30 21:37:37 +0000 | |||
1789 | @@ -0,0 +1,138 @@ | |||
1790 | 1 | # -*- coding: utf-8 -*- | ||
1791 | 2 | # | ||
1792 | 3 | # Copyright 2009-2012 Canonical Ltd. | ||
1793 | 4 | # | ||
1794 | 5 | # This program is free software: you can redistribute it and/or modify it | ||
1795 | 6 | # under the terms of the GNU General Public License version 3, as published | ||
1796 | 7 | # by the Free Software Foundation. | ||
1797 | 8 | # | ||
1798 | 9 | # This program is distributed in the hope that it will be useful, but | ||
1799 | 10 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1800 | 11 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1801 | 12 | # PURPOSE. See the GNU General Public License for more details. | ||
1802 | 13 | # | ||
1803 | 14 | # You should have received a copy of the GNU General Public License along | ||
1804 | 15 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1805 | 16 | # | ||
1806 | 17 | # In addition, as a special exception, the copyright holders give | ||
1807 | 18 | # permission to link the code of portions of this program with the | ||
1808 | 19 | # OpenSSL library under certain conditions as described in each | ||
1809 | 20 | # individual source file, and distribute linked combinations | ||
1810 | 21 | # including the two. | ||
1811 | 22 | # You must obey the GNU General Public License in all respects | ||
1812 | 23 | # for all of the code used other than OpenSSL. If you modify | ||
1813 | 24 | # file(s) with this exception, you may extend this exception to your | ||
1814 | 25 | # version of the file(s), but you are not obligated to do so. If you | ||
1815 | 26 | # do not wish to do so, delete this exception statement from your | ||
1816 | 27 | # version. If you delete this exception statement from all source | ||
1817 | 28 | # files in the program, then also delete it here. | ||
1818 | 29 | """Base dbus tests cases and test utilities.""" | ||
1819 | 30 | |||
1820 | 31 | from __future__ import absolute_import, with_statement | ||
1821 | 32 | |||
1822 | 33 | import os | ||
1823 | 34 | |||
1824 | 35 | from twisted.internet import defer | ||
1825 | 36 | |||
1826 | 37 | from ubuntuone.devtools.testcases import BaseTestCase, skipIf | ||
1827 | 38 | |||
1828 | 39 | # DBusRunner for DBusTestCase using tests | ||
1829 | 40 | from ubuntuone.devtools.services.dbus import DBusRunner | ||
1830 | 41 | |||
1831 | 42 | |||
1832 | 43 | # pylint: disable=F0401,C0103,W0406,E0611 | ||
1833 | 44 | try: | ||
1834 | 45 | import dbus | ||
1835 | 46 | except ImportError as e: | ||
1836 | 47 | dbus = None | ||
1837 | 48 | |||
1838 | 49 | try: | ||
1839 | 50 | import dbus.service as service | ||
1840 | 51 | except ImportError: | ||
1841 | 52 | service = None | ||
1842 | 53 | |||
1843 | 54 | try: | ||
1844 | 55 | from dbus.mainloop.glib import DBusGMainLoop | ||
1845 | 56 | except ImportError: | ||
1846 | 57 | DBusGMainLoop = None | ||
1847 | 58 | |||
1848 | 59 | # pylint: enable=F0401,C0103,W0406,E0611 | ||
1849 | 60 | |||
1850 | 61 | |||
1851 | 62 | class InvalidSessionBus(Exception): | ||
1852 | 63 | """Error when we are connected to the wrong session bus in tests.""" | ||
1853 | 64 | |||
1854 | 65 | |||
1855 | 66 | class FakeDBusInterface(object): | ||
1856 | 67 | """A fake DBusInterface...""" | ||
1857 | 68 | |||
1858 | 69 | def shutdown(self, with_restart=False): | ||
1859 | 70 | """...that only knows how to go away""" | ||
1860 | 71 | |||
1861 | 72 | |||
1862 | 73 | @skipIf(dbus is None or service is None or DBusGMainLoop is None, | ||
1863 | 74 | "The test requires dbus.") | ||
1864 | 75 | class DBusTestCase(BaseTestCase): | ||
1865 | 76 | """Test the DBus event handling.""" | ||
1866 | 77 | |||
1867 | 78 | def required_services(self): | ||
1868 | 79 | """Return the list of required services for DBusTestCase.""" | ||
1869 | 80 | services = super(DBusTestCase, self).required_services() | ||
1870 | 81 | services.extend([DBusRunner]) | ||
1871 | 82 | return services | ||
1872 | 83 | |||
1873 | 84 | @defer.inlineCallbacks | ||
1874 | 85 | def setUp(self): | ||
1875 | 86 | """Setup the infrastructure fo the test (dbus service).""" | ||
1876 | 87 | # Class 'BaseTestCase' has no 'setUp' member | ||
1877 | 88 | # pylint: disable=E1101 | ||
1878 | 89 | # dbus modules will be imported by the decorator | ||
1879 | 90 | # pylint: disable=E0602 | ||
1880 | 91 | yield super(DBusTestCase, self).setUp() | ||
1881 | 92 | |||
1882 | 93 | # We need to ensure DBUS_SESSION_BUS_ADDRESS is private here | ||
1883 | 94 | # pylint: disable=F0401,E0611 | ||
1884 | 95 | try: | ||
1885 | 96 | from urllib.parse import unquote | ||
1886 | 97 | except ImportError: | ||
1887 | 98 | from urllib import unquote | ||
1888 | 99 | # pylint: enable=F0401,E0611 | ||
1889 | 100 | |||
1890 | 101 | bus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS', None) | ||
1891 | 102 | if os.path.dirname(unquote(bus_address.split(',')[0].split('=')[1])) \ | ||
1892 | 103 | != os.path.dirname(os.getcwd()): | ||
1893 | 104 | raise InvalidSessionBus('DBUS_SESSION_BUS_ADDRESS is wrong.') | ||
1894 | 105 | |||
1895 | 106 | # Set up the main loop and bus connection | ||
1896 | 107 | self.loop = DBusGMainLoop(set_as_default=True) | ||
1897 | 108 | |||
1898 | 109 | # NOTE: The address_or_type value must remain explicitly as | ||
1899 | 110 | # str instead of anything from ubuntuone.devtools.compat. dbus | ||
1900 | 111 | # expects this to be str regardless of version. | ||
1901 | 112 | self.bus = dbus.bus.BusConnection(address_or_type=str(bus_address), | ||
1902 | 113 | mainloop=self.loop) | ||
1903 | 114 | |||
1904 | 115 | # Monkeypatch the dbus.SessionBus/SystemBus methods, to ensure we | ||
1905 | 116 | # always point at our own private bus instance. | ||
1906 | 117 | self.patch(dbus, 'SessionBus', lambda: self.bus) | ||
1907 | 118 | self.patch(dbus, 'SystemBus', lambda: self.bus) | ||
1908 | 119 | |||
1909 | 120 | # Check that we are on the correct bus for real | ||
1910 | 121 | # Disable this for now, because our tests are extremely broken :( | ||
1911 | 122 | # bus_names = self.bus.list_names() | ||
1912 | 123 | # if len(bus_names) > 2: | ||
1913 | 124 | # raise InvalidSessionBus('Too many bus connections: %s (%r)' % | ||
1914 | 125 | # (len(bus_names), bus_names)) | ||
1915 | 126 | |||
1916 | 127 | # monkeypatch busName.__del__ to avoid errors on gc | ||
1917 | 128 | # we take care of releasing the name in shutdown | ||
1918 | 129 | service.BusName.__del__ = lambda _: None | ||
1919 | 130 | yield self.bus.set_exit_on_disconnect(False) | ||
1920 | 131 | self.signal_receivers = set() | ||
1921 | 132 | |||
1922 | 133 | @defer.inlineCallbacks | ||
1923 | 134 | def tearDown(self): | ||
1924 | 135 | """Cleanup the test.""" | ||
1925 | 136 | yield self.bus.flush() | ||
1926 | 137 | yield self.bus.close() | ||
1927 | 138 | yield super(DBusTestCase, self).tearDown() | ||
1928 | 0 | 139 | ||
1929 | === added file 'ubuntuone/devtools/testcases/txsocketserver.py' | |||
1930 | --- ubuntuone/devtools/testcases/txsocketserver.py 1970-01-01 00:00:00 +0000 | |||
1931 | +++ ubuntuone/devtools/testcases/txsocketserver.py 2018-05-30 21:37:37 +0000 | |||
1932 | @@ -0,0 +1,357 @@ | |||
1933 | 1 | # -*- coding: utf-8 -*- | ||
1934 | 2 | # Copyright 2012 Canonical Ltd. | ||
1935 | 3 | # | ||
1936 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
1937 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
1938 | 6 | # by the Free Software Foundation. | ||
1939 | 7 | # | ||
1940 | 8 | # This program is distributed in the hope that it will be useful, but | ||
1941 | 9 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1942 | 10 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1943 | 11 | # PURPOSE. See the GNU General Public License for more details. | ||
1944 | 12 | # | ||
1945 | 13 | # You should have received a copy of the GNU General Public License along | ||
1946 | 14 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1947 | 15 | # | ||
1948 | 16 | # In addition, as a special exception, the copyright holders give | ||
1949 | 17 | # permission to link the code of portions of this program with the | ||
1950 | 18 | # OpenSSL library under certain conditions as described in each | ||
1951 | 19 | # individual source file, and distribute linked combinations | ||
1952 | 20 | # including the two. | ||
1953 | 21 | # You must obey the GNU General Public License in all respects | ||
1954 | 22 | # for all of the code used other than OpenSSL. If you modify | ||
1955 | 23 | # file(s) with this exception, you may extend this exception to your | ||
1956 | 24 | # version of the file(s), but you are not obligated to do so. If you | ||
1957 | 25 | # do not wish to do so, delete this exception statement from your | ||
1958 | 26 | # version. If you delete this exception statement from all source | ||
1959 | 27 | # files in the program, then also delete it here. | ||
1960 | 28 | |||
1961 | 29 | """Base test case for twisted servers.""" | ||
1962 | 30 | |||
1963 | 31 | import os | ||
1964 | 32 | import shutil | ||
1965 | 33 | import tempfile | ||
1966 | 34 | |||
1967 | 35 | from twisted.internet import defer, endpoints, protocol | ||
1968 | 36 | from twisted.spread import pb | ||
1969 | 37 | |||
1970 | 38 | from ubuntuone.devtools.testcases import BaseTestCase | ||
1971 | 39 | |||
1972 | 40 | # no init method + twisted common warnings | ||
1973 | 41 | # pylint: disable=W0232, C0103, E1101 | ||
1974 | 42 | |||
1975 | 43 | |||
1976 | 44 | def server_protocol_factory(cls): | ||
1977 | 45 | """Factory to create tidy protocols.""" | ||
1978 | 46 | |||
1979 | 47 | if cls is None: | ||
1980 | 48 | cls = protocol.Protocol | ||
1981 | 49 | |||
1982 | 50 | class ServerTidyProtocol(cls): | ||
1983 | 51 | """A tidy protocol.""" | ||
1984 | 52 | |||
1985 | 53 | def connectionLost(self, *args): | ||
1986 | 54 | """Lost the connection.""" | ||
1987 | 55 | cls.connectionLost(self, *args) | ||
1988 | 56 | # lets tell everyone | ||
1989 | 57 | # pylint: disable=W0212 | ||
1990 | 58 | if (self.factory._disconnecting and | ||
1991 | 59 | self.factory.testserver_on_connection_lost is not None and | ||
1992 | 60 | not self.factory.testserver_on_connection_lost.called): | ||
1993 | 61 | self.factory.testserver_on_connection_lost.callback(self) | ||
1994 | 62 | # pylint: enable=W0212 | ||
1995 | 63 | |||
1996 | 64 | return ServerTidyProtocol | ||
1997 | 65 | |||
1998 | 66 | |||
1999 | 67 | def server_factory_factory(cls): | ||
2000 | 68 | """Factory that creates special types of factories for tests.""" | ||
2001 | 69 | |||
2002 | 70 | if cls is None: | ||
2003 | 71 | cls = protocol.ServerFactory | ||
2004 | 72 | |||
2005 | 73 | class TidyServerFactory(cls): | ||
2006 | 74 | """A tidy factory.""" | ||
2007 | 75 | |||
2008 | 76 | testserver_on_connection_lost = None | ||
2009 | 77 | |||
2010 | 78 | def buildProtocol(self, addr): | ||
2011 | 79 | prot = cls.buildProtocol(self, addr) | ||
2012 | 80 | self.testserver_on_connection_lost = defer.Deferred() | ||
2013 | 81 | return prot | ||
2014 | 82 | |||
2015 | 83 | return TidyServerFactory | ||
2016 | 84 | |||
2017 | 85 | |||
2018 | 86 | def client_protocol_factory(cls): | ||
2019 | 87 | """Factory to create tidy protocols.""" | ||
2020 | 88 | |||
2021 | 89 | if cls is None: | ||
2022 | 90 | cls = protocol.Protocol | ||
2023 | 91 | |||
2024 | 92 | class ClientTidyProtocol(cls): | ||
2025 | 93 | """A tidy protocol.""" | ||
2026 | 94 | |||
2027 | 95 | def connectionLost(self, *a): | ||
2028 | 96 | """Connection list.""" | ||
2029 | 97 | cls.connectionLost(self, *a) | ||
2030 | 98 | # pylint: disable=W0212 | ||
2031 | 99 | if (self.factory._disconnecting and | ||
2032 | 100 | self.factory.testserver_on_connection_lost is not None and | ||
2033 | 101 | not self.factory.testserver_on_connection_lost.called): | ||
2034 | 102 | self.factory.testserver_on_connection_lost.callback(self) | ||
2035 | 103 | # pylint: enable=W0212 | ||
2036 | 104 | |||
2037 | 105 | return ClientTidyProtocol | ||
2038 | 106 | |||
2039 | 107 | |||
2040 | 108 | class TidySocketServer(object): | ||
2041 | 109 | """Ensure that twisted servers are correctly managed in tests. | ||
2042 | 110 | |||
2043 | 111 | Closing a twisted server is a complicated matter. In order to do so you | ||
2044 | 112 | have to ensure that three different deferreds are fired: | ||
2045 | 113 | |||
2046 | 114 | 1. The server must stop listening. | ||
2047 | 115 | 2. The client connection must disconnect. | ||
2048 | 116 | 3. The server connection must disconnect. | ||
2049 | 117 | |||
2050 | 118 | This class allows to create a server and a client that will ensure that | ||
2051 | 119 | the reactor is left clean by following the pattern described at | ||
2052 | 120 | http://mumak.net/stuff/twisted-disconnect.html | ||
2053 | 121 | """ | ||
2054 | 122 | def __init__(self): | ||
2055 | 123 | """Create a new instance.""" | ||
2056 | 124 | self.listener = None | ||
2057 | 125 | self.server_factory = None | ||
2058 | 126 | |||
2059 | 127 | self.connector = None | ||
2060 | 128 | self.client_factory = None | ||
2061 | 129 | |||
2062 | 130 | def get_server_endpoint(self): | ||
2063 | 131 | """Return the server endpoint description.""" | ||
2064 | 132 | raise NotImplementedError('To be implemented by child classes.') | ||
2065 | 133 | |||
2066 | 134 | def get_client_endpoint(self): | ||
2067 | 135 | """Return the client endpoint description.""" | ||
2068 | 136 | raise NotImplementedError('To be implemented by child classes.') | ||
2069 | 137 | |||
2070 | 138 | @defer.inlineCallbacks | ||
2071 | 139 | def listen_server(self, server_class, *args, **kwargs): | ||
2072 | 140 | """Start a server in a random port.""" | ||
2073 | 141 | from twisted.internet import reactor | ||
2074 | 142 | tidy_class = server_factory_factory(server_class) | ||
2075 | 143 | self.server_factory = tidy_class(*args, **kwargs) | ||
2076 | 144 | self.server_factory._disconnecting = False | ||
2077 | 145 | self.server_factory.protocol = server_protocol_factory( | ||
2078 | 146 | self.server_factory.protocol) | ||
2079 | 147 | endpoint = endpoints.serverFromString(reactor, | ||
2080 | 148 | self.get_server_endpoint()) | ||
2081 | 149 | self.listener = yield endpoint.listen(self.server_factory) | ||
2082 | 150 | defer.returnValue(self.server_factory) | ||
2083 | 151 | |||
2084 | 152 | @defer.inlineCallbacks | ||
2085 | 153 | def connect_client(self, client_class, *args, **kwargs): | ||
2086 | 154 | """Conect a client to a given server.""" | ||
2087 | 155 | from twisted.internet import reactor | ||
2088 | 156 | |||
2089 | 157 | if self.server_factory is None: | ||
2090 | 158 | raise ValueError('Server Factory was not provided.') | ||
2091 | 159 | if self.listener is None: | ||
2092 | 160 | raise ValueError('%s has not started listening.', | ||
2093 | 161 | self.server_factory) | ||
2094 | 162 | |||
2095 | 163 | self.client_factory = client_class(*args, **kwargs) | ||
2096 | 164 | self.client_factory._disconnecting = False | ||
2097 | 165 | self.client_factory.protocol = client_protocol_factory( | ||
2098 | 166 | self.client_factory.protocol) | ||
2099 | 167 | self.client_factory.testserver_on_connection_lost = defer.Deferred() | ||
2100 | 168 | endpoint = endpoints.clientFromString(reactor, | ||
2101 | 169 | self.get_client_endpoint()) | ||
2102 | 170 | self.connector = yield endpoint.connect(self.client_factory) | ||
2103 | 171 | defer.returnValue(self.client_factory) | ||
2104 | 172 | |||
2105 | 173 | def clean_up(self): | ||
2106 | 174 | """Action to be performed for clean up.""" | ||
2107 | 175 | if self.server_factory is None or self.listener is None: | ||
2108 | 176 | # nothing to clean | ||
2109 | 177 | return defer.succeed(None) | ||
2110 | 178 | |||
2111 | 179 | if self.listener and self.connector: | ||
2112 | 180 | # clean client and server | ||
2113 | 181 | self.server_factory._disconnecting = True | ||
2114 | 182 | self.client_factory._disconnecting = True | ||
2115 | 183 | d = defer.maybeDeferred(self.listener.stopListening) | ||
2116 | 184 | self.connector.transport.loseConnection() | ||
2117 | 185 | if self.server_factory.testserver_on_connection_lost: | ||
2118 | 186 | return defer.gatherResults( | ||
2119 | 187 | [d, | ||
2120 | 188 | self.client_factory.testserver_on_connection_lost, | ||
2121 | 189 | self.server_factory.testserver_on_connection_lost]) | ||
2122 | 190 | else: | ||
2123 | 191 | return defer.gatherResults( | ||
2124 | 192 | [d, | ||
2125 | 193 | self.client_factory.testserver_on_connection_lost]) | ||
2126 | 194 | if self.listener: | ||
2127 | 195 | # just clean the server since there is no client | ||
2128 | 196 | # pylint: disable=W0201 | ||
2129 | 197 | self.server_factory._disconnecting = True | ||
2130 | 198 | return defer.maybeDeferred(self.listener.stopListening) | ||
2131 | 199 | # pylint: enable=W0201 | ||
2132 | 200 | |||
2133 | 201 | |||
2134 | 202 | class TidyTCPServer(TidySocketServer): | ||
2135 | 203 | """A tidy tcp domain sockets server.""" | ||
2136 | 204 | |||
2137 | 205 | client_endpoint_pattern = 'tcp:host=127.0.0.1:port=%s' | ||
2138 | 206 | server_endpoint_pattern = 'tcp:0:interface=127.0.0.1' | ||
2139 | 207 | |||
2140 | 208 | def get_server_endpoint(self): | ||
2141 | 209 | """Return the server endpoint description.""" | ||
2142 | 210 | return self.server_endpoint_pattern | ||
2143 | 211 | |||
2144 | 212 | def get_client_endpoint(self): | ||
2145 | 213 | """Return the client endpoint description.""" | ||
2146 | 214 | if self.server_factory is None: | ||
2147 | 215 | raise ValueError('Server Factory was not provided.') | ||
2148 | 216 | if self.listener is None: | ||
2149 | 217 | raise ValueError('%s has not started listening.', | ||
2150 | 218 | self.server_factory) | ||
2151 | 219 | return self.client_endpoint_pattern % self.listener.getHost().port | ||
2152 | 220 | |||
2153 | 221 | |||
2154 | 222 | class TidyUnixServer(TidySocketServer): | ||
2155 | 223 | """A tidy unix domain sockets server.""" | ||
2156 | 224 | |||
2157 | 225 | client_endpoint_pattern = 'unix:path=%s' | ||
2158 | 226 | server_endpoint_pattern = 'unix:%s' | ||
2159 | 227 | |||
2160 | 228 | def __init__(self): | ||
2161 | 229 | """Create a new instance.""" | ||
2162 | 230 | super(TidyUnixServer, self).__init__() | ||
2163 | 231 | self.temp_dir = tempfile.mkdtemp() | ||
2164 | 232 | self.path = os.path.join(self.temp_dir, 'tidy_unix_server') | ||
2165 | 233 | |||
2166 | 234 | def get_server_endpoint(self): | ||
2167 | 235 | """Return the server endpoint description.""" | ||
2168 | 236 | return self.server_endpoint_pattern % self.path | ||
2169 | 237 | |||
2170 | 238 | def get_client_endpoint(self): | ||
2171 | 239 | """Return the client endpoint description.""" | ||
2172 | 240 | return self.client_endpoint_pattern % self.path | ||
2173 | 241 | |||
2174 | 242 | def clean_up(self): | ||
2175 | 243 | """Action to be performed for clean up.""" | ||
2176 | 244 | result = super(TidyUnixServer, self).clean_up() | ||
2177 | 245 | # remove the dir once we are disconnected | ||
2178 | 246 | result.addCallback(lambda _: shutil.rmtree(self.temp_dir)) | ||
2179 | 247 | return result | ||
2180 | 248 | |||
2181 | 249 | |||
2182 | 250 | class ServerTestCase(BaseTestCase): | ||
2183 | 251 | """Base test case for tidy servers.""" | ||
2184 | 252 | |||
2185 | 253 | @defer.inlineCallbacks | ||
2186 | 254 | def setUp(self): | ||
2187 | 255 | """Set the diff tests.""" | ||
2188 | 256 | yield super(ServerTestCase, self).setUp() | ||
2189 | 257 | |||
2190 | 258 | try: | ||
2191 | 259 | self.server_runner = self.get_server() | ||
2192 | 260 | except NotImplementedError: | ||
2193 | 261 | self.server_runner = None | ||
2194 | 262 | |||
2195 | 263 | self.server_factory = None | ||
2196 | 264 | self.client_factory = None | ||
2197 | 265 | self.server_disconnected = None | ||
2198 | 266 | self.client_connected = None | ||
2199 | 267 | self.client_disconnected = None | ||
2200 | 268 | self.listener = None | ||
2201 | 269 | self.connector = None | ||
2202 | 270 | self.addCleanup(self.tear_down_server_client) | ||
2203 | 271 | |||
2204 | 272 | def get_server(self): | ||
2205 | 273 | """Return the server to be used to run the tests.""" | ||
2206 | 274 | raise NotImplementedError('To be implemented by child classes.') | ||
2207 | 275 | |||
2208 | 276 | @defer.inlineCallbacks | ||
2209 | 277 | def listen_server(self, server_class, *args, **kwargs): | ||
2210 | 278 | """Listen a server. | ||
2211 | 279 | |||
2212 | 280 | The method takes the server class and the arguments that should be | ||
2213 | 281 | passed to the server constructor. | ||
2214 | 282 | """ | ||
2215 | 283 | self.server_factory = yield self.server_runner.listen_server( | ||
2216 | 284 | server_class, *args, **kwargs) | ||
2217 | 285 | self.server_disconnected = \ | ||
2218 | 286 | self.server_factory.testserver_on_connection_lost | ||
2219 | 287 | self.listener = self.server_runner.listener | ||
2220 | 288 | |||
2221 | 289 | @defer.inlineCallbacks | ||
2222 | 290 | def connect_client(self, client_class, *args, **kwargs): | ||
2223 | 291 | """Connect the client. | ||
2224 | 292 | |||
2225 | 293 | The method takes the client factory class and the arguments that | ||
2226 | 294 | should be passed to the client constructor. | ||
2227 | 295 | """ | ||
2228 | 296 | self.client_factory = yield self.server_runner.connect_client( | ||
2229 | 297 | client_class, *args, **kwargs) | ||
2230 | 298 | self.client_disconnected = \ | ||
2231 | 299 | self.client_factory.testserver_on_connection_lost | ||
2232 | 300 | self.connector = self.server_runner.connector | ||
2233 | 301 | |||
2234 | 302 | def tear_down_server_client(self): | ||
2235 | 303 | """Clean the server and client.""" | ||
2236 | 304 | if self.server_runner: | ||
2237 | 305 | return self.server_runner.clean_up() | ||
2238 | 306 | |||
2239 | 307 | |||
2240 | 308 | class TCPServerTestCase(ServerTestCase): | ||
2241 | 309 | """Test that uses a single twisted server.""" | ||
2242 | 310 | |||
2243 | 311 | def get_server(self): | ||
2244 | 312 | """Return the server to be used to run the tests.""" | ||
2245 | 313 | return TidyTCPServer() | ||
2246 | 314 | |||
2247 | 315 | |||
2248 | 316 | class UnixServerTestCase(ServerTestCase): | ||
2249 | 317 | """Test that uses a single twisted server.""" | ||
2250 | 318 | |||
2251 | 319 | def get_server(self): | ||
2252 | 320 | """Return the server to be used to run the tests.""" | ||
2253 | 321 | return TidyUnixServer() | ||
2254 | 322 | |||
2255 | 323 | |||
2256 | 324 | class PbServerTestCase(ServerTestCase): | ||
2257 | 325 | """Test a pb server.""" | ||
2258 | 326 | |||
2259 | 327 | def get_server(self): | ||
2260 | 328 | """Return the server to be used to run the tests.""" | ||
2261 | 329 | raise NotImplementedError('To be implemented by child classes.') | ||
2262 | 330 | |||
2263 | 331 | @defer.inlineCallbacks | ||
2264 | 332 | def listen_server(self, *args, **kwargs): | ||
2265 | 333 | """Listen a pb server.""" | ||
2266 | 334 | yield super(PbServerTestCase, self).listen_server(pb.PBServerFactory, | ||
2267 | 335 | *args, **kwargs) | ||
2268 | 336 | |||
2269 | 337 | @defer.inlineCallbacks | ||
2270 | 338 | def connect_client(self, *args, **kwargs): | ||
2271 | 339 | """Connect a pb client.""" | ||
2272 | 340 | yield super(PbServerTestCase, self).connect_client(pb.PBClientFactory, | ||
2273 | 341 | *args, **kwargs) | ||
2274 | 342 | |||
2275 | 343 | |||
2276 | 344 | class TCPPbServerTestCase(PbServerTestCase): | ||
2277 | 345 | """Test a pb server over TCP.""" | ||
2278 | 346 | |||
2279 | 347 | def get_server(self): | ||
2280 | 348 | """Return the server to be used to run the tests.""" | ||
2281 | 349 | return TidyTCPServer() | ||
2282 | 350 | |||
2283 | 351 | |||
2284 | 352 | class UnixPbServerTestCase(PbServerTestCase): | ||
2285 | 353 | """Test a pb server over Unix domain sockets.""" | ||
2286 | 354 | |||
2287 | 355 | def get_server(self): | ||
2288 | 356 | """Return the server to be used to run the tests.""" | ||
2289 | 357 | return TidyUnixServer() | ||
2290 | 0 | 358 | ||
2291 | === added directory 'ubuntuone/devtools/testing' | |||
2292 | === added file 'ubuntuone/devtools/testing/__init__.py' | |||
2293 | --- ubuntuone/devtools/testing/__init__.py 1970-01-01 00:00:00 +0000 | |||
2294 | +++ ubuntuone/devtools/testing/__init__.py 2018-05-30 21:37:37 +0000 | |||
2295 | @@ -0,0 +1,1 @@ | |||
2296 | 1 | """Testing helpers.""" | ||
2297 | 0 | 2 | ||
2298 | === added file 'ubuntuone/devtools/testing/txcheck.py' | |||
2299 | --- ubuntuone/devtools/testing/txcheck.py 1970-01-01 00:00:00 +0000 | |||
2300 | +++ ubuntuone/devtools/testing/txcheck.py 2018-05-30 21:37:37 +0000 | |||
2301 | @@ -0,0 +1,381 @@ | |||
2302 | 1 | # -*- coding: utf-8 -*- | ||
2303 | 2 | |||
2304 | 3 | # Author: Tim Cole <tim.cole@canonical.com> | ||
2305 | 4 | # | ||
2306 | 5 | # Copyright 2011-2012 Canonical Ltd. | ||
2307 | 6 | # | ||
2308 | 7 | # This program is free software: you can redistribute it and/or modify it | ||
2309 | 8 | # under the terms of the GNU General Public License version 3, as published | ||
2310 | 9 | # by the Free Software Foundation. | ||
2311 | 10 | # | ||
2312 | 11 | # This program is distributed in the hope that it will be useful, but | ||
2313 | 12 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2314 | 13 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2315 | 14 | # PURPOSE. See the GNU General Public License for more details. | ||
2316 | 15 | # | ||
2317 | 16 | # You should have received a copy of the GNU General Public License along | ||
2318 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2319 | 18 | # | ||
2320 | 19 | # In addition, as a special exception, the copyright holders give | ||
2321 | 20 | # permission to link the code of portions of this program with the | ||
2322 | 21 | # OpenSSL library under certain conditions as described in each | ||
2323 | 22 | # individual source file, and distribute linked combinations | ||
2324 | 23 | # including the two. | ||
2325 | 24 | # You must obey the GNU General Public License in all respects | ||
2326 | 25 | # for all of the code used other than OpenSSL. If you modify | ||
2327 | 26 | # file(s) with this exception, you may extend this exception to your | ||
2328 | 27 | # version of the file(s), but you are not obligated to do so. If you | ||
2329 | 28 | # do not wish to do so, delete this exception statement from your | ||
2330 | 29 | # version. If you delete this exception statement from all source | ||
2331 | 30 | # files in the program, then also delete it here. | ||
2332 | 31 | """Utilities for performing correctness checks.""" | ||
2333 | 32 | |||
2334 | 33 | import sys | ||
2335 | 34 | import ast | ||
2336 | 35 | from inspect import getsource | ||
2337 | 36 | from textwrap import dedent | ||
2338 | 37 | from itertools import takewhile | ||
2339 | 38 | from unittest import TestCase, TestSuite, TestResult | ||
2340 | 39 | |||
2341 | 40 | from twisted.trial.unittest import TestCase as TwistedTestCase | ||
2342 | 41 | |||
2343 | 42 | |||
2344 | 43 | def type_to_name(type_obj): | ||
2345 | 44 | """Return a name for a type.""" | ||
2346 | 45 | package_name = getattr(type_obj, '__module__', None) | ||
2347 | 46 | if package_name: | ||
2348 | 47 | return "%s.%s" % (package_name, type_obj.__name__) | ||
2349 | 48 | else: | ||
2350 | 49 | return type_obj.__name__ | ||
2351 | 50 | |||
2352 | 51 | |||
2353 | 52 | class Problem(AssertionError): | ||
2354 | 53 | """An object representing a problem in a method.""" | ||
2355 | 54 | |||
2356 | 55 | def __init__(self, method, test_class, ancestor_class): | ||
2357 | 56 | """Initialize an instance.""" | ||
2358 | 57 | super(Problem, self).__init__() | ||
2359 | 58 | self.method = method | ||
2360 | 59 | self.test_class = test_class | ||
2361 | 60 | self.ancestor_class = ancestor_class | ||
2362 | 61 | |||
2363 | 62 | def __eq__(self, other): | ||
2364 | 63 | """Test equality.""" | ||
2365 | 64 | return type(self) == type(other) and self.__dict__ == other.__dict__ | ||
2366 | 65 | |||
2367 | 66 | def __ne__(self, other): | ||
2368 | 67 | """Test inequality.""" | ||
2369 | 68 | return not (self == other) | ||
2370 | 69 | |||
2371 | 70 | def __hash__(self): | ||
2372 | 71 | """Return hash.""" | ||
2373 | 72 | member_hash = 0 | ||
2374 | 73 | for (key, value) in self.__dict__.items(): | ||
2375 | 74 | member_hash ^= hash(key) ^ hash(value) | ||
2376 | 75 | return hash(type(self)) ^ member_hash | ||
2377 | 76 | |||
2378 | 77 | def __str__(self): | ||
2379 | 78 | """Return a friendlier representation.""" | ||
2380 | 79 | if self.ancestor_class != self.test_class: | ||
2381 | 80 | method_string = ("%s in ancestor method %s.%s" % | ||
2382 | 81 | (type_to_name(self.test_class), | ||
2383 | 82 | type_to_name(self.ancestor_class), | ||
2384 | 83 | self.method)) | ||
2385 | 84 | else: | ||
2386 | 85 | method_string = ("%s.%s" % | ||
2387 | 86 | (type_to_name(self.test_class), self.method)) | ||
2388 | 87 | return ("%s for %s" % (type(self).__name__, method_string)) | ||
2389 | 88 | |||
2390 | 89 | def __repr__(self): | ||
2391 | 90 | """Return representation string.""" | ||
2392 | 91 | return "<%s %r>" % (type(self), self.__dict__) | ||
2393 | 92 | |||
2394 | 93 | |||
2395 | 94 | class MethodShadowed(Problem): | ||
2396 | 95 | """Problem when trial's run method is shadowed.""" | ||
2397 | 96 | |||
2398 | 97 | |||
2399 | 98 | class SuperResultDiscarded(Problem): | ||
2400 | 99 | """Problem when callback chains are broken.""" | ||
2401 | 100 | |||
2402 | 101 | |||
2403 | 102 | class SuperNotCalled(Problem): | ||
2404 | 103 | """Problem when super isn't called.""" | ||
2405 | 104 | |||
2406 | 105 | |||
2407 | 106 | class MissingInlineCallbacks(Problem): | ||
2408 | 107 | """Problem when the inlineCallbacks decorator is missing.""" | ||
2409 | 108 | |||
2410 | 109 | |||
2411 | 110 | class MissingReturnValue(Problem): | ||
2412 | 111 | """Problem when there's no return value.""" | ||
2413 | 112 | |||
2414 | 113 | |||
2415 | 114 | def match_type(expected_type): | ||
2416 | 115 | """Return predicate matching nodes of given type.""" | ||
2417 | 116 | return lambda node: isinstance(node, expected_type) | ||
2418 | 117 | |||
2419 | 118 | |||
2420 | 119 | def match_equal(expected_value): | ||
2421 | 120 | """Return predicate matching nodes equaling the given value.""" | ||
2422 | 121 | return lambda node: expected_value == node | ||
2423 | 122 | |||
2424 | 123 | |||
2425 | 124 | def match_in(expected_values): | ||
2426 | 125 | """Return predicate matching node if in collection of expected values.""" | ||
2427 | 126 | return lambda node: node in expected_values | ||
2428 | 127 | |||
2429 | 128 | |||
2430 | 129 | def match_not_none(): | ||
2431 | 130 | """Returns a predicate matching nodes which are not None.""" | ||
2432 | 131 | return lambda node: node is not None | ||
2433 | 132 | |||
2434 | 133 | |||
2435 | 134 | def match_any(*subtests): | ||
2436 | 135 | """Return short-circuiting predicate matching any given subpredicate.""" | ||
2437 | 136 | if len(subtests) == 1: | ||
2438 | 137 | return subtests[0] | ||
2439 | 138 | else: | ||
2440 | 139 | |||
2441 | 140 | def test(node): | ||
2442 | 141 | """Try each subtest until we find one that passes.""" | ||
2443 | 142 | for subtest in subtests: | ||
2444 | 143 | if subtest(node): | ||
2445 | 144 | return True | ||
2446 | 145 | return False | ||
2447 | 146 | |||
2448 | 147 | return test | ||
2449 | 148 | |||
2450 | 149 | |||
2451 | 150 | def match_all(*subtests): | ||
2452 | 151 | """Return short-circuiting predicate matching all given subpredicates.""" | ||
2453 | 152 | if len(subtests) == 1: | ||
2454 | 153 | return subtests[0] | ||
2455 | 154 | else: | ||
2456 | 155 | |||
2457 | 156 | def test(node): | ||
2458 | 157 | """Try each subtest until we find one that fails.""" | ||
2459 | 158 | for subtest in subtests: | ||
2460 | 159 | if not subtest(node): | ||
2461 | 160 | return False | ||
2462 | 161 | return True | ||
2463 | 162 | |||
2464 | 163 | return test | ||
2465 | 164 | |||
2466 | 165 | |||
2467 | 166 | def match_attr(attr_name, *tests): | ||
2468 | 167 | """Return predicate matching subpredicates against an attribute value.""" | ||
2469 | 168 | return lambda node: match_all(*tests)(getattr(node, attr_name)) | ||
2470 | 169 | |||
2471 | 170 | |||
2472 | 171 | def match_path(initial_test, *components): | ||
2473 | 172 | """Return predicate which recurses into the tree via given attributes.""" | ||
2474 | 173 | components = list(components) | ||
2475 | 174 | components.reverse() | ||
2476 | 175 | |||
2477 | 176 | def test(node): | ||
2478 | 177 | return True | ||
2479 | 178 | |||
2480 | 179 | for component in components: | ||
2481 | 180 | attr_name = component[0] | ||
2482 | 181 | subtests = component[1:] | ||
2483 | 182 | test = match_attr(attr_name, match_all(match_all(*subtests), test)) | ||
2484 | 183 | return match_all(initial_test, test) | ||
2485 | 184 | |||
2486 | 185 | |||
2487 | 186 | def match_child(*tests): | ||
2488 | 187 | """Return predicate which tests any child.""" | ||
2489 | 188 | subtest = match_all(*tests) | ||
2490 | 189 | |||
2491 | 190 | def test(node): | ||
2492 | 191 | """Try each child until we find one that matches.""" | ||
2493 | 192 | for child in ast.iter_child_nodes(node): | ||
2494 | 193 | if subtest(child): | ||
2495 | 194 | return True | ||
2496 | 195 | return False | ||
2497 | 196 | |||
2498 | 197 | return test | ||
2499 | 198 | |||
2500 | 199 | |||
2501 | 200 | def match_descendant(subtest, prune): | ||
2502 | 201 | """Return predicate which tests a node and any descendants.""" | ||
2503 | 202 | |||
2504 | 203 | def test(node): | ||
2505 | 204 | """Recursively (breadth-first) search for a matching node.""" | ||
2506 | 205 | for child in ast.iter_child_nodes(node): | ||
2507 | 206 | if prune(child): | ||
2508 | 207 | continue | ||
2509 | 208 | if subtest(child) or test(child): | ||
2510 | 209 | return True | ||
2511 | 210 | return False | ||
2512 | 211 | |||
2513 | 212 | return test | ||
2514 | 213 | |||
2515 | 214 | |||
2516 | 215 | def matches(node, *tests): | ||
2517 | 216 | """Convenience function to try predicates on a node.""" | ||
2518 | 217 | return match_all(*tests)(node) | ||
2519 | 218 | |||
2520 | 219 | |||
2521 | 220 | def any_matches(nodes, *tests): | ||
2522 | 221 | """Convenience function to try predicates on any of a sequence of nodes.""" | ||
2523 | 222 | test = match_all(*tests) | ||
2524 | 223 | for node in nodes: | ||
2525 | 224 | if test(node): | ||
2526 | 225 | return True | ||
2527 | 226 | return False | ||
2528 | 227 | |||
2529 | 228 | |||
2530 | 229 | def iter_matching_child_nodes(node, *tests): | ||
2531 | 230 | """Yields every matching child node.""" | ||
2532 | 231 | test = match_all(*tests) | ||
2533 | 232 | for child in ast.iter_child_nodes(node): | ||
2534 | 233 | if test(child): | ||
2535 | 234 | yield child | ||
2536 | 235 | |||
2537 | 236 | |||
2538 | 237 | SETUP_FUNCTION_NAMES = ('setUp', 'tearDown') | ||
2539 | 238 | SETUP_FUNCTION = match_path(match_type(ast.FunctionDef), | ||
2540 | 239 | ('name', match_in(SETUP_FUNCTION_NAMES))) | ||
2541 | 240 | |||
2542 | 241 | SUPER = match_path(match_type(ast.Call), | ||
2543 | 242 | ('func', match_type(ast.Attribute)), | ||
2544 | 243 | ('value', match_type(ast.Call)), | ||
2545 | 244 | ('func', match_type(ast.Name)), | ||
2546 | 245 | ('id', match_equal("super"))) | ||
2547 | 246 | |||
2548 | 247 | BARE_SUPER = match_path(match_type(ast.Expr), | ||
2549 | 248 | ('value', SUPER)) | ||
2550 | 249 | |||
2551 | 250 | YIELD = match_type(ast.Yield) | ||
2552 | 251 | |||
2553 | 252 | INLINE_CALLBACKS_DECORATOR = \ | ||
2554 | 253 | match_any(match_path(match_type(ast.Attribute), | ||
2555 | 254 | ('attr', match_equal('inlineCallbacks'))), | ||
2556 | 255 | match_path(match_type(ast.Name), | ||
2557 | 256 | ('id', match_equal('inlineCallbacks')))) | ||
2558 | 257 | |||
2559 | 258 | RETURN_VALUE = \ | ||
2560 | 259 | match_path(match_type(ast.Return), | ||
2561 | 260 | ('value', match_not_none())) | ||
2562 | 261 | |||
2563 | 262 | DEFS = match_any(match_type(ast.ClassDef), | ||
2564 | 263 | match_type(ast.FunctionDef)) | ||
2565 | 264 | |||
2566 | 265 | |||
2567 | 266 | def find_problems(class_to_check): | ||
2568 | 267 | """Check twisted test setup in a given test class.""" | ||
2569 | 268 | mro = class_to_check.__mro__ | ||
2570 | 269 | if TwistedTestCase not in mro: | ||
2571 | 270 | return set() | ||
2572 | 271 | |||
2573 | 272 | problems = set() | ||
2574 | 273 | |||
2575 | 274 | ancestry = takewhile(lambda c: c != TwistedTestCase, mro) | ||
2576 | 275 | for ancestor_class in ancestry: | ||
2577 | 276 | if 'run' in ancestor_class.__dict__: | ||
2578 | 277 | problem = MethodShadowed(method='run', | ||
2579 | 278 | test_class=class_to_check, | ||
2580 | 279 | ancestor_class=ancestor_class) | ||
2581 | 280 | problems.add(problem) | ||
2582 | 281 | |||
2583 | 282 | source = dedent(getsource(ancestor_class)) | ||
2584 | 283 | tree = ast.parse(source) | ||
2585 | 284 | # the top level of the tree is a Module | ||
2586 | 285 | class_node = tree.body[0] | ||
2587 | 286 | |||
2588 | 287 | # Check setUp/tearDown | ||
2589 | 288 | for def_node in iter_matching_child_nodes(class_node, SETUP_FUNCTION): | ||
2590 | 289 | if matches(def_node, match_child(BARE_SUPER)): | ||
2591 | 290 | # Superclass method called, but its result wasn't used | ||
2592 | 291 | problem = SuperResultDiscarded(method=def_node.name, | ||
2593 | 292 | test_class=class_to_check, | ||
2594 | 293 | ancestor_class=ancestor_class) | ||
2595 | 294 | problems.add(problem) | ||
2596 | 295 | if not matches(def_node, match_descendant(SUPER, DEFS)): | ||
2597 | 296 | # The call to the overridden superclass method is missing | ||
2598 | 297 | problem = SuperNotCalled(method=def_node.name, | ||
2599 | 298 | test_class=class_to_check, | ||
2600 | 299 | ancestor_class=ancestor_class) | ||
2601 | 300 | problems.add(problem) | ||
2602 | 301 | |||
2603 | 302 | decorators = def_node.decorator_list | ||
2604 | 303 | |||
2605 | 304 | if matches(def_node, match_descendant(YIELD, DEFS)): | ||
2606 | 305 | # Yield was used, making this a generator | ||
2607 | 306 | if not any_matches(decorators, INLINE_CALLBACKS_DECORATOR): | ||
2608 | 307 | # ...but the inlineCallbacks decorator is missing | ||
2609 | 308 | problem = MissingInlineCallbacks( | ||
2610 | 309 | method=def_node.name, | ||
2611 | 310 | test_class=class_to_check, | ||
2612 | 311 | ancestor_class=ancestor_class) | ||
2613 | 312 | problems.add(problem) | ||
2614 | 313 | else: | ||
2615 | 314 | if not matches(def_node, match_descendant(RETURN_VALUE, DEFS)): | ||
2616 | 315 | # The function fails to return a deferred | ||
2617 | 316 | problem = MissingReturnValue( | ||
2618 | 317 | method=def_node.name, | ||
2619 | 318 | test_class=class_to_check, | ||
2620 | 319 | ancestor_class=ancestor_class) | ||
2621 | 320 | problems.add(problem) | ||
2622 | 321 | |||
2623 | 322 | return problems | ||
2624 | 323 | |||
2625 | 324 | |||
2626 | 325 | def get_test_classes(suite): | ||
2627 | 326 | """Return all the unique test classes involved in a suite.""" | ||
2628 | 327 | classes = set() | ||
2629 | 328 | |||
2630 | 329 | def find_classes(suite_or_test): | ||
2631 | 330 | """Recursively find all the test classes.""" | ||
2632 | 331 | if isinstance(suite_or_test, TestSuite): | ||
2633 | 332 | for subtest in suite_or_test: | ||
2634 | 333 | find_classes(subtest) | ||
2635 | 334 | else: | ||
2636 | 335 | classes.add(type(suite_or_test)) | ||
2637 | 336 | |||
2638 | 337 | find_classes(suite) | ||
2639 | 338 | |||
2640 | 339 | return classes | ||
2641 | 340 | |||
2642 | 341 | |||
2643 | 342 | def make_check_testcase(tests): | ||
2644 | 343 | """Make TestCase which checks the given twisted tests.""" | ||
2645 | 344 | |||
2646 | 345 | class TXCheckTest(TestCase): | ||
2647 | 346 | """Test case which checks the test classes for problems.""" | ||
2648 | 347 | |||
2649 | 348 | def runTest(self): # pylint: disable=C0103 | ||
2650 | 349 | """Do nothing.""" | ||
2651 | 350 | |||
2652 | 351 | def run(self, result=None): | ||
2653 | 352 | """Check all the test classes for problems.""" | ||
2654 | 353 | if result is None: | ||
2655 | 354 | result = TestResult() | ||
2656 | 355 | |||
2657 | 356 | test_classes = set() | ||
2658 | 357 | |||
2659 | 358 | for test_object in tests: | ||
2660 | 359 | test_classes |= get_test_classes(test_object) | ||
2661 | 360 | |||
2662 | 361 | for test_class in test_classes: | ||
2663 | 362 | problems = find_problems(test_class) | ||
2664 | 363 | for problem in problems: | ||
2665 | 364 | try: | ||
2666 | 365 | raise problem | ||
2667 | 366 | except Problem: | ||
2668 | 367 | result.addFailure(self, sys.exc_info()) | ||
2669 | 368 | |||
2670 | 369 | return TXCheckTest() | ||
2671 | 370 | |||
2672 | 371 | |||
2673 | 372 | class TXCheckSuite(TestSuite): | ||
2674 | 373 | """Test suite which checks twisted tests.""" | ||
2675 | 374 | |||
2676 | 375 | def __init__(self, tests=()): | ||
2677 | 376 | """Initialize with the given tests, and add a special test.""" | ||
2678 | 377 | |||
2679 | 378 | tests = list(tests) | ||
2680 | 379 | tests.insert(0, make_check_testcase(self)) | ||
2681 | 380 | |||
2682 | 381 | super(TXCheckSuite, self).__init__(tests) | ||
2683 | 0 | 382 | ||
2684 | === added file 'ubuntuone/devtools/testing/txwebserver.py' | |||
2685 | --- ubuntuone/devtools/testing/txwebserver.py 1970-01-01 00:00:00 +0000 | |||
2686 | +++ ubuntuone/devtools/testing/txwebserver.py 2018-05-30 21:37:37 +0000 | |||
2687 | @@ -0,0 +1,124 @@ | |||
2688 | 1 | # -*- coding: utf-8 -*- | ||
2689 | 2 | # Copyright 2012 Canonical Ltd. | ||
2690 | 3 | # | ||
2691 | 4 | # This program is free software: you can redistribute it and/or modify it | ||
2692 | 5 | # under the terms of the GNU General Public License version 3, as published | ||
2693 | 6 | # by the Free Software Foundation. | ||
2694 | 7 | # | ||
2695 | 8 | # This program is distributed in the hope that it will be useful, but | ||
2696 | 9 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2697 | 10 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2698 | 11 | # PURPOSE. See the GNU General Public License for more details. | ||
2699 | 12 | # | ||
2700 | 13 | # You should have received a copy of the GNU General Public License along | ||
2701 | 14 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2702 | 15 | # | ||
2703 | 16 | # In addition, as a special exception, the copyright holders give | ||
2704 | 17 | # permission to link the code of portions of this program with the | ||
2705 | 18 | # OpenSSL library under certain conditions as described in each | ||
2706 | 19 | # individual source file, and distribute linked combinations | ||
2707 | 20 | # including the two. | ||
2708 | 21 | # You must obey the GNU General Public License in all respects | ||
2709 | 22 | # for all of the code used other than OpenSSL. If you modify | ||
2710 | 23 | # file(s) with this exception, you may extend this exception to your | ||
2711 | 24 | # version of the file(s), but you are not obligated to do so. If you | ||
2712 | 25 | # do not wish to do so, delete this exception statement from your | ||
2713 | 26 | # version. If you delete this exception statement from all source | ||
2714 | 27 | # files in the program, then also delete it here. | ||
2715 | 28 | |||
2716 | 29 | """A tx based web server.""" | ||
2717 | 30 | |||
2718 | 31 | from __future__ import unicode_literals | ||
2719 | 32 | |||
2720 | 33 | from twisted.internet import defer, reactor, ssl | ||
2721 | 34 | from twisted.protocols.policies import WrappingFactory | ||
2722 | 35 | from twisted.web import server | ||
2723 | 36 | |||
2724 | 37 | from ubuntuone.devtools.testcases.txsocketserver import server_protocol_factory | ||
2725 | 38 | |||
2726 | 39 | # no init method + twisted common warnings | ||
2727 | 40 | # pylint: disable=W0232, C0103, E1101 | ||
2728 | 41 | |||
2729 | 42 | |||
2730 | 43 | class BaseWebServer(object): | ||
2731 | 44 | """Webserver used to perform requests in tests.""" | ||
2732 | 45 | |||
2733 | 46 | def __init__(self, root_resource, scheme): | ||
2734 | 47 | """Create and start the instance. | ||
2735 | 48 | |||
2736 | 49 | The ssl_settings parameter contains a dictionary with the key and cert | ||
2737 | 50 | that will be used to perform ssl connections. The root_resource | ||
2738 | 51 | contains the resource with all its childre. | ||
2739 | 52 | """ | ||
2740 | 53 | self.root = root_resource | ||
2741 | 54 | self.scheme = scheme | ||
2742 | 55 | self.port = None | ||
2743 | 56 | # use an http.HTTPFactory that was modified to ensure that we have | ||
2744 | 57 | # clean close connections | ||
2745 | 58 | self.site = server.Site(self.root, timeout=None) | ||
2746 | 59 | self.wrapper = WrappingFactory(self.site) | ||
2747 | 60 | self.wrapper.testserver_on_connection_lost = defer.Deferred() | ||
2748 | 61 | self.wrapper.protocol = server_protocol_factory(self.wrapper.protocol) | ||
2749 | 62 | self.wrapper._disconnecting = False | ||
2750 | 63 | |||
2751 | 64 | def listen(self, site): | ||
2752 | 65 | """Listen a port to allow the tests.""" | ||
2753 | 66 | raise NotImplementedError('Base abstract class.') | ||
2754 | 67 | |||
2755 | 68 | def get_iri(self): | ||
2756 | 69 | """Build the iri for this mock server.""" | ||
2757 | 70 | return "{scheme}://127.0.0.1:{port}/".format(scheme=self.scheme, | ||
2758 | 71 | port=self.get_port()) | ||
2759 | 72 | |||
2760 | 73 | def get_port(self): | ||
2761 | 74 | """Return the port where we are listening.""" | ||
2762 | 75 | return self.port.getHost().port | ||
2763 | 76 | |||
2764 | 77 | def start(self): | ||
2765 | 78 | """Start the service.""" | ||
2766 | 79 | self.port = self.listen(self.wrapper) | ||
2767 | 80 | |||
2768 | 81 | def stop(self): | ||
2769 | 82 | """Shut it down.""" | ||
2770 | 83 | if self.port: | ||
2771 | 84 | self.wrapper._disconnecting = True | ||
2772 | 85 | connected = self.wrapper.protocols.keys() | ||
2773 | 86 | if connected: | ||
2774 | 87 | for con in connected: | ||
2775 | 88 | con.transport.loseConnection() | ||
2776 | 89 | else: | ||
2777 | 90 | self.wrapper.testserver_on_connection_lost = \ | ||
2778 | 91 | defer.succeed(None) | ||
2779 | 92 | d = defer.maybeDeferred(self.port.stopListening) | ||
2780 | 93 | return defer.gatherResults( | ||
2781 | 94 | [d, | ||
2782 | 95 | self.wrapper.testserver_on_connection_lost]) | ||
2783 | 96 | return defer.succeed(None) | ||
2784 | 97 | |||
2785 | 98 | |||
2786 | 99 | class HTTPWebServer(BaseWebServer): | ||
2787 | 100 | """A Webserver that listens to http connections.""" | ||
2788 | 101 | |||
2789 | 102 | def __init__(self, root_resource): | ||
2790 | 103 | """Create a new instance.""" | ||
2791 | 104 | super(HTTPWebServer, self).__init__(root_resource, 'http') | ||
2792 | 105 | |||
2793 | 106 | def listen(self, site): | ||
2794 | 107 | """Listen a port to allow the tests.""" | ||
2795 | 108 | return reactor.listenTCP(0, site) | ||
2796 | 109 | |||
2797 | 110 | |||
2798 | 111 | class HTTPSWebServer(BaseWebServer): | ||
2799 | 112 | """A WebServer that listens to https connections.""" | ||
2800 | 113 | |||
2801 | 114 | def __init__(self, root_resource, ssl_settings=None): | ||
2802 | 115 | """Create a new instance.""" | ||
2803 | 116 | super(HTTPSWebServer, self).__init__(root_resource, 'https') | ||
2804 | 117 | self.ssl_settings = ssl_settings | ||
2805 | 118 | |||
2806 | 119 | def listen(self, site): | ||
2807 | 120 | """Listen a port to allow the tests.""" | ||
2808 | 121 | ssl_context = ssl.DefaultOpenSSLContextFactory( | ||
2809 | 122 | self.ssl_settings['key'], self.ssl_settings['cert']) | ||
2810 | 123 | |||
2811 | 124 | return reactor.listenSSL(0, site, ssl_context) | ||
2812 | 0 | 125 | ||
2813 | === added file 'ubuntuone/devtools/utils.py' | |||
2814 | --- ubuntuone/devtools/utils.py 1970-01-01 00:00:00 +0000 | |||
2815 | +++ ubuntuone/devtools/utils.py 2018-05-30 21:37:37 +0000 | |||
2816 | @@ -0,0 +1,180 @@ | |||
2817 | 1 | # Copyright 2009-2012 Canonical Ltd. | ||
2818 | 2 | # | ||
2819 | 3 | # This program is free software: you can redistribute it and/or modify it | ||
2820 | 4 | # under the terms of the GNU General Public License version 3, as published | ||
2821 | 5 | # by the Free Software Foundation. | ||
2822 | 6 | # | ||
2823 | 7 | # This program is distributed in the hope that it will be useful, but | ||
2824 | 8 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
2825 | 9 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
2826 | 10 | # PURPOSE. See the GNU General Public License for more details. | ||
2827 | 11 | # | ||
2828 | 12 | # You should have received a copy of the GNU General Public License along | ||
2829 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2830 | 14 | # | ||
2831 | 15 | # In addition, as a special exception, the copyright holders give | ||
2832 | 16 | # permission to link the code of portions of this program with the | ||
2833 | 17 | # OpenSSL library under certain conditions as described in each | ||
2834 | 18 | # individual source file, and distribute linked combinations | ||
2835 | 19 | # including the two. | ||
2836 | 20 | # You must obey the GNU General Public License in all respects | ||
2837 | 21 | # for all of the code used other than OpenSSL. If you modify | ||
2838 | 22 | # file(s) with this exception, you may extend this exception to your | ||
2839 | 23 | # version of the file(s), but you are not obligated to do so. If you | ||
2840 | 24 | # do not wish to do so, delete this exception statement from your | ||
2841 | 25 | # version. If you delete this exception statement from all source | ||
2842 | 26 | # files in the program, then also delete it here. | ||
2843 | 27 | """Utilities for Ubuntu One developer tools.""" | ||
2844 | 28 | |||
2845 | 29 | from __future__ import print_function, unicode_literals | ||
2846 | 30 | |||
2847 | 31 | import getopt | ||
2848 | 32 | import sys | ||
2849 | 33 | |||
2850 | 34 | from ubuntuone.devtools.errors import UsageError | ||
2851 | 35 | __all__ = ['OptionParser'] | ||
2852 | 36 | |||
2853 | 37 | |||
2854 | 38 | def accumulate_list_attr(class_obj, attr, list_obj, base_class=None): | ||
2855 | 39 | """Get all of the list attributes of attr from the class hierarchy, | ||
2856 | 40 | and return a list of the lists.""" | ||
2857 | 41 | for base in class_obj.__bases__: | ||
2858 | 42 | accumulate_list_attr(base, attr, list_obj) | ||
2859 | 43 | if base_class is None or base_class in class_obj.__bases__: | ||
2860 | 44 | list_obj.extend(class_obj.__dict__.get(attr, [])) | ||
2861 | 45 | |||
2862 | 46 | |||
2863 | 47 | def unpack_padded(length, sequence, default=None): | ||
2864 | 48 | """Pads a sequence to length with value of default. | ||
2865 | 49 | |||
2866 | 50 | Returns a list containing the original and padded values. | ||
2867 | 51 | """ | ||
2868 | 52 | newlist = [default] * length | ||
2869 | 53 | newlist[:len(sequence)] = list(sequence) | ||
2870 | 54 | return newlist | ||
2871 | 55 | |||
2872 | 56 | |||
2873 | 57 | class OptionParser(dict): | ||
2874 | 58 | """Base options for our test runner.""" | ||
2875 | 59 | |||
2876 | 60 | def __init__(self, *args, **kwargs): | ||
2877 | 61 | super(OptionParser, self).__init__(*args, **kwargs) | ||
2878 | 62 | |||
2879 | 63 | # Store info about the options and defaults | ||
2880 | 64 | self.long_opts = [] | ||
2881 | 65 | self.short_opts = '' | ||
2882 | 66 | self.docs = {} | ||
2883 | 67 | self.defaults = {} | ||
2884 | 68 | self.synonyms = {} | ||
2885 | 69 | self.dispatch = {} | ||
2886 | 70 | |||
2887 | 71 | # Get the options and defaults | ||
2888 | 72 | for _get in [self._get_flags, self._get_params]: | ||
2889 | 73 | # We don't use variable 'syns' here. It's just to pad the result. | ||
2890 | 74 | # pylint: disable=W0612 | ||
2891 | 75 | (long_opts, short_opts, docs, defaults, syns, dispatch) = _get() | ||
2892 | 76 | # pylint: enable=W0612 | ||
2893 | 77 | self.long_opts.extend(long_opts) | ||
2894 | 78 | self.short_opts = self.short_opts + short_opts | ||
2895 | 79 | self.docs.update(docs) | ||
2896 | 80 | self.update(defaults) | ||
2897 | 81 | self.defaults.update(defaults) | ||
2898 | 82 | self.synonyms.update(syns) | ||
2899 | 83 | self.dispatch.update(dispatch) | ||
2900 | 84 | |||
2901 | 85 | # We use some camelcase names for trial compatibility here. | ||
2902 | 86 | # pylint: disable=C0103 | ||
2903 | 87 | def parseOptions(self, options=None): | ||
2904 | 88 | """Parse the options.""" | ||
2905 | 89 | if options is None: | ||
2906 | 90 | options = sys.argv[1:] | ||
2907 | 91 | |||
2908 | 92 | try: | ||
2909 | 93 | opts, args = getopt.getopt(options, | ||
2910 | 94 | self.short_opts, self.long_opts) | ||
2911 | 95 | except getopt.error as e: | ||
2912 | 96 | raise UsageError(e) | ||
2913 | 97 | |||
2914 | 98 | for opt, arg in opts: | ||
2915 | 99 | if opt[1] == '-': | ||
2916 | 100 | opt = opt[2:] | ||
2917 | 101 | else: | ||
2918 | 102 | opt = opt[1:] | ||
2919 | 103 | |||
2920 | 104 | if (opt not in self.synonyms.keys()): | ||
2921 | 105 | raise UsageError('No such options: "%s"' % opt) | ||
2922 | 106 | |||
2923 | 107 | opt = self.synonyms[opt] | ||
2924 | 108 | if self.defaults[opt] is False: | ||
2925 | 109 | self[opt] = True | ||
2926 | 110 | else: | ||
2927 | 111 | self.dispatch[opt](arg) | ||
2928 | 112 | |||
2929 | 113 | try: | ||
2930 | 114 | self.parseArgs(*args) | ||
2931 | 115 | except TypeError: | ||
2932 | 116 | raise UsageError('Wrong number of arguments.') | ||
2933 | 117 | |||
2934 | 118 | self.postOptions() | ||
2935 | 119 | |||
2936 | 120 | def postOptions(self): | ||
2937 | 121 | """Called after options are parsed.""" | ||
2938 | 122 | |||
2939 | 123 | def parseArgs(self, *args): | ||
2940 | 124 | """Override to handle extra arguments specially.""" | ||
2941 | 125 | # pylint: enable=C0103 | ||
2942 | 126 | |||
2943 | 127 | def _parse_arguments(self, arg_type=None, has_default=False): | ||
2944 | 128 | """Parse the arguments as either flags or parameters.""" | ||
2945 | 129 | long_opts, short_opts = [], '' | ||
2946 | 130 | docs, defaults, syns, dispatch = {}, {}, {}, {} | ||
2947 | 131 | |||
2948 | 132 | _args = [] | ||
2949 | 133 | accumulate_list_attr(self.__class__, arg_type, _args) | ||
2950 | 134 | |||
2951 | 135 | for _arg in _args: | ||
2952 | 136 | try: | ||
2953 | 137 | if has_default: | ||
2954 | 138 | l_opt, s_opt, default, doc, _ = unpack_padded(5, _arg) | ||
2955 | 139 | else: | ||
2956 | 140 | default = False | ||
2957 | 141 | l_opt, s_opt, doc, _ = unpack_padded(4, _arg) | ||
2958 | 142 | except ValueError: | ||
2959 | 143 | raise ValueError('Failed to parse argument: %s' % _arg) | ||
2960 | 144 | if not l_opt: | ||
2961 | 145 | raise ValueError('An option must have a long name.') | ||
2962 | 146 | |||
2963 | 147 | opt_m_name = 'opt_' + l_opt.replace('-', '_') | ||
2964 | 148 | opt_method = getattr(self, opt_m_name, None) | ||
2965 | 149 | if opt_method is not None: | ||
2966 | 150 | docs[l_opt] = getattr(opt_method, '__doc__', None) | ||
2967 | 151 | dispatch[l_opt] = opt_method | ||
2968 | 152 | if docs[l_opt] is None: | ||
2969 | 153 | docs[l_opt] = doc | ||
2970 | 154 | else: | ||
2971 | 155 | docs[l_opt] = doc | ||
2972 | 156 | dispatch[l_opt] = lambda arg: True | ||
2973 | 157 | |||
2974 | 158 | defaults[l_opt] = default | ||
2975 | 159 | if has_default: | ||
2976 | 160 | long_opts.append(l_opt + '=') | ||
2977 | 161 | else: | ||
2978 | 162 | long_opts.append(l_opt) | ||
2979 | 163 | |||
2980 | 164 | syns[l_opt] = l_opt | ||
2981 | 165 | if s_opt is not None: | ||
2982 | 166 | short_opts = short_opts + s_opt | ||
2983 | 167 | if has_default: | ||
2984 | 168 | short_opts = short_opts + ':' | ||
2985 | 169 | syns[s_opt] = l_opt | ||
2986 | 170 | |||
2987 | 171 | return long_opts, short_opts, docs, defaults, syns, dispatch | ||
2988 | 172 | |||
2989 | 173 | def _get_flags(self): | ||
2990 | 174 | """Get the flag options.""" | ||
2991 | 175 | return self._parse_arguments(arg_type='optFlags', has_default=False) | ||
2992 | 176 | |||
2993 | 177 | def _get_params(self): | ||
2994 | 178 | """Get the parameters options.""" | ||
2995 | 179 | return self._parse_arguments(arg_type='optParameters', | ||
2996 | 180 | has_default=True) |