on xenial help sign in
MR comment changes, docstrings, order of imports and copyright header.
c7b1353Christopher Lee
tests/autopilot/unity8/shell/emulators/unlock.py+33−6
@@ -1,11 +1,29 @@
1−import subprocess
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Autopilot Utilities
4+# Copyright (C) 2013 Canonical
5+#
6+# This program is free software: you can redistribute it and/or modify
7+# it under the terms of the GNU General Public License as published by
8+# the Free Software Foundation, either version 3 of the License, or
9+# (at your option) any later version.
10+#
11+# This program is distributed in the hope that it will be useful,
12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+# GNU General Public License for more details.
15+#
16+# You should have received a copy of the GNU General Public License
17+# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+#
2
19
3from autopilot.introspection import (
20from autopilot.introspection import (
4 get_proxy_object_for_existing_process,
21 get_proxy_object_for_existing_process,
5 ProcessSearchError,
22 ProcessSearchError,
6)
23)
7−from unity8.shell.emulators.main_window import MainWindow
24+import subprocess
8from unity8.shell.emulators import UnityEmulatorBase
25from unity8.shell.emulators import UnityEmulatorBase
26+from unity8.shell.emulators.main_window import MainWindow
9
27
10
28
11class CannotAccessUnity(Exception):
29class CannotAccessUnity(Exception):
@@ -40,15 +58,24 @@ def unlock_unity():
40 except ProcessSearchError as e:
58 except ProcessSearchError as e:
41 raise CannotAccessUnity(
59 raise CannotAccessUnity(
42 "Cannot introspect unity, make sure that it has been started "
60 "Cannot introspect unity, make sure that it has been started "
43− "with 'testability' (%s)" % e.message
61+ "with testability. Perhaps use the function "
62+ "'restart_unity_with_testability' this module provides."
63+ "(%s)"
64+ % str(e)
44 )
65 )
45
66
46
67
47def restart_unity_with_testability():
68def restart_unity_with_testability():
69+ """Restarts (or just starts) unity8 with the testability driver loaded
70+
71+ :raises: subprocess.CalledProcessError if unable to stop or start the
72+ unity8 upstart job.
73+
74+ """
48 status = _get_unity_status()
75 status = _get_unity_status()
49 if "start/" in status:
76 if "start/" in status:
50 try:
77 try:
51− print "Stopping unity."
78+ print("Stopping unity.")
52 subprocess.check_call([
79 subprocess.check_call([
53 'initctl',
80 'initctl',
54 'stop',
81 'stop',
@@ -59,7 +86,7 @@ def restart_unity_with_testability():
59 raise
86 raise
60
87
61 try:
88 try:
62− print "Stopping unity with testability."
89+ print("Starting unity with testability.")
63 subprocess.check_call([
90 subprocess.check_call([
64 'initctl',
91 'initctl',
65 'start',
92 'start',
@@ -79,7 +106,7 @@ def _get_unity_status():
79 'unity8'
106 'unity8'
80 ])
107 ])
81 except subprocess.CalledProcessError as e:
108 except subprocess.CalledProcessError as e:
82− raise CannotAccessUnity("Unable to get unity's status: %s" % e.message)
109+ raise CannotAccessUnity("Unable to get unity's status: %s" % str(e))
83
110
84
111
85def _get_unity_pid():
112def _get_unity_pid():