on xenial help sign in
MR comment changes, docstrings, order of imports and copyright header.
commitc7b13539bb219554a858862b81f0b92ac1754d53 authorChristopher Lee <chris.lee@canonical.com> dateWed 16 Oct 2013, 16:53 (13 years ago) parent6f1473a
1 file changed+33−6
tests/autopilot/unity8/shell/emulators/unlock.py+33−6
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+#
219
320from autopilot.introspection import (
421 get_proxy_object_for_existing_process,
522 ProcessSearchError,
623)
7−from unity8.shell.emulators.main_window import MainWindow
24+import subprocess
825from unity8.shell.emulators import UnityEmulatorBase
26+from unity8.shell.emulators.main_window import MainWindow
927
1028
1129class CannotAccessUnity(Exception):
@@ -40,15 +58,24 @@ def unlock_unity():
4058 except ProcessSearchError as e:
4159 raise CannotAccessUnity(
4260 "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)
4465 )
4566
4667
4768def 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+ """
4875 status = _get_unity_status()
4976 if "start/" in status:
5077 try:
51− print "Stopping unity."
78+ print("Stopping unity.")
5279 subprocess.check_call([
5380 'initctl',
5481 'stop',
@@ -59,7 +86,7 @@ def restart_unity_with_testability():
5986 raise
6087
6188 try:
62− print "Stopping unity with testability."
89+ print("Starting unity with testability.")
6390 subprocess.check_call([
6491 'initctl',
6592 'start',
@@ -79,7 +106,7 @@ def _get_unity_status():
79106 'unity8'
80107 ])
81108 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))
83110
84111
85112def _get_unity_pid():