on xenial help sign in
Ship python3 autopilot modules.
commitc6369c154001d261900f3f6532d86d06f7a4f187 authorDimitri John Ledkov <dimitri.ledkov@canonical.com> dateSat 22 Feb 2014, 00:12 (13 years ago) parent1dcb2dd3252018
8 files changed+61−21
cmake/modules/autopilot.cmake+10−1 debian/control+5 debian/rules+2−2 tests/autopilot/unity8/__init__.py+4−1 tests/autopilot/unity8/shell/tests/__init__.py+12−13 tests/autopilot/unity8/shell/tests/test_emulators.py+4−1 tests/autopilot/unity8/shell/tests/test_lock_screen.py+18−3 tests/autopilot/unity8/shell/tests/test_notifications.py+6
cmake/modules/autopilot.cmake+10−1
@@ -2,7 +2,7 @@ add_custom_target(autopilot)
22
33function(declare_autopilot_test TEST_NAME TEST_SUITE WORKING_DIR)
44 add_custom_target(autopilot-${TEST_NAME}
5− COMMAND LANG=C UBUNTU_ICON_THEME=ubuntu-mobile QML2_IMPORT_PATH=${SHELL_INSTALL_QML}/mocks autopilot run ${TEST_SUITE}
5+ COMMAND LANG=C UBUNTU_ICON_THEME=ubuntu-mobile QML2_IMPORT_PATH=${SHELL_INSTALL_QML}/mocks python3 -m autopilot.run run ${TEST_SUITE}
66 WORKING_DIRECTORY ${WORKING_DIR}
77 DEPENDS fake_install
88 )
@@ -12,4 +12,13 @@ function(declare_autopilot_test TEST_NAME TEST_SUITE WORKING_DIR)
1212 )
1313
1414 add_dependencies(autopilot autopilot-${TEST_NAME})
15+
16+ add_custom_target(autopilot2-${TEST_NAME}
17+ COMMAND LANG=C UBUNTU_ICON_THEME=ubuntu-mobile QML2_IMPORT_PATH=${SHELL_INSTALL_QML}/mocks python2 -m autopilot.run run ${TEST_SUITE}
18+ WORKING_DIRECTORY ${WORKING_DIR}
19+ DEPENDS fake_install
20+ )
21+
22+ add_dependencies(autopilot autopilot2-${TEST_NAME})
23+
1524endfunction()
debian/control+5
@@ -29,6 +29,7 @@ Build-Depends: cmake,
2929 python:any (>= 2.7),
3030 python-setuptools,
3131 python3:any,
32+ python3-setuptools,
3233 qt5-default,
3334 qtbase5-dev,
3435 qtbase5-dev-tools,
@@ -111,12 +112,16 @@ Depends: gir1.2-glib-2.0,
111112 python-fixtures,
112113 python-gi,
113114 python-mock,
115+ python3-evdev,
116+ python3-fixtures,
117+ python3-gi,
114118 ubuntu-ui-toolkit-autopilot,
115119 unity8 (>= ${source:Version}),
116120 unity8-fake-env (>= ${source:Version}),
117121 url-dispatcher-tools,
118122 ${misc:Depends},
119123 ${python:Depends},
124+ ${python3:Depends},
120125 ${shlibs:Depends},
121126Description: Test package for Unity 8 shell
122127 Autopilot tests for the unity8 package
debian/rules+2−2
@@ -10,7 +10,7 @@ SCOPES_RECOMMENDS := $(shell perl debian/scopes-recommends-generator /usr/share/
1010
1111.PHONY: build
1212build %:
13− dh $@ --parallel --fail-missing --with python2
13+ dh $@ --parallel --fail-missing --with python2,python3
1414
1515override_dh_auto_clean:
1616 dh_auto_clean
@@ -28,7 +28,7 @@ override_dh_auto_build:
2828override_dh_install:
2929 # install autopilot tests
3030 cd tests/autopilot; \
31− set -ex; for python in $(shell pyversions -r); do \
31+ set -ex; for python in $(shell pyversions -r) $(shell py3versions -r); do \
3232 $$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
3333 done; \
3434 cd $(CURDIR)
tests/autopilot/unity8/__init__.py+4−1
@@ -82,7 +82,10 @@ def get_binary_path(binary="unity8"):
8282 )
8383 if not os.path.exists(binary_path):
8484 try:
85− binary_path = subprocess.check_output(['which', binary]).strip()
85+ binary_path = subprocess.check_output(
86+ ['which', binary],
87+ universal_newlines=True,
88+ ).strip()
8689 except subprocess.CalledProcessError as e:
8790 raise RuntimeError("Unable to locate %s binary: %r" % (binary, e))
8891 return binary_path
tests/autopilot/unity8/shell/tests/__init__.py+12−13
@@ -85,12 +85,12 @@ class UnityTestCase(AutopilotTestCase):
8585 @classmethod
8686 def setUpClass(cls):
8787 try:
88− output = subprocess.check_output([
89− "/sbin/initctl",
90− "status",
91− "unity8"
92− ], stderr=subprocess.STDOUT)
93− except subprocess.CalledProcessError, e:
88+ output = subprocess.check_output(
89+ ["/sbin/initctl", "status", "unity8"],
90+ stderr=subprocess.STDOUT,
91+ universal_newlines=True,
92+ )
93+ except subprocess.CalledProcessError as e:
9494 sys.stderr.write(
9595 "Error: `initctl status unity8` failed, most probably the "
9696 "unity8 session could not be found:\n\n"
@@ -218,12 +218,11 @@ class UnityTestCase(AutopilotTestCase):
218218 def _patch_environment(self, key, value):
219219 """Wrapper for patching env for upstart environment."""
220220 try:
221− current_value = subprocess.check_output([
222− "/sbin/initctl",
223− "get-env",
224− "--global",
225− key
226− ], stderr=subprocess.STDOUT).rstrip()
221+ current_value = subprocess.check_output(
222+ ["/sbin/initctl", "get-env", "--global", key],
223+ stderr=subprocess.STDOUT,
224+ universal_newlines=True,
225+ ).rstrip()
227226 except subprocess.CalledProcessError:
228227 current_value = None
229228
@@ -305,7 +304,7 @@ class UnityTestCase(AutopilotTestCase):
305304
306305 binary_arg = "BINARY=%s" % binary_path
307306 extra_args = "ARGS=%s" % " ".join(args)
308− env_args = ["%s=%s" % (k, v) for k, v in self._environment.iteritems()]
307+ env_args = ["%s=%s" % (k, v) for k, v in self._environment.items()]
309308 all_args = [binary_arg, extra_args] + env_args
310309
311310 self.addCleanup(self._cleanup_launching_upstart_unity)
tests/autopilot/unity8/shell/tests/test_emulators.py+4−1
@@ -27,7 +27,10 @@ don't break them for those external projects.
2727
2828"""
2929
30−import mock
30+try:
31+ from unittest import mock
32+except ImportError:
33+ import mock
3134
3235from testtools.matchers import Contains, HasLength
3336
tests/autopilot/unity8/shell/tests/test_lock_screen.py+18−3
@@ -26,12 +26,18 @@ from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2626
2727from autopilot.matchers import Eventually
2828from autopilot.platform import model
29+import sys
2930from testtools import skipUnless
3031from testtools.matchers import Equals
3132import logging
3233
3334logger = logging.getLogger(__name__)
3435
36+# py2 compatible alias for py3
37+if sys.version >= '3':
38+ basestring = str
39+
40+
3541class TestLockscreen(UnityTestCase):
3642
3743 """Tests for the lock screen."""
@@ -125,7 +131,10 @@ class TestLockscreen(UnityTestCase):
125131 """
126132
127133 if not isinstance(code, basestring):
128− raise TypeError("'code' parameter must be a string.")
134+ raise TypeError(
135+ "'code' parameter must be a string, not %r."
136+ % type(passphrase)
137+ )
129138 for num in code:
130139 if not num.isdigit():
131140 raise ValueError(
@@ -142,7 +151,10 @@ class TestLockscreen(UnityTestCase):
142151
143152 """
144153 if not isinstance(passphrase, basestring):
145− raise TypeError("'passphrase' parameter must be a string.")
154+ raise TypeError(
155+ "'passphrase' parameter must be a string, not %r."
156+ % type(passphrase)
157+ )
146158
147159 pinentryField = self.main_window.get_pinentryField()
148160 self.touch.tap_object(pinentryField)
@@ -161,7 +173,10 @@ class TestLockscreen(UnityTestCase):
161173
162174 """
163175 if not isinstance(passphrase, basestring):
164− raise TypeError("'passphrase' parameter must be a string.")
176+ raise TypeError(
177+ "'passphrase' parameter must be a string, not %r."
178+ % type(passphrase)
179+ )
165180
166181 prompt = self.main_window.get_greeter().get_prompt()
167182 self.touch.tap_object(prompt)
tests/autopilot/unity8/shell/tests/test_notifications.py+6
@@ -33,9 +33,14 @@ import os
3333import logging
3434import signal
3535import subprocess
36+import sys
3637
3738logger = logging.getLogger(__name__)
3839
40+# backwards compatible alias for Python 3
41+if sys.version > '3':
42+ xrange = range
43+
3944
4045class NotificationsBase(UnityTestCase):
4146 """Base class for all notification tests that provides helper methods."""
@@ -261,6 +266,7 @@ class InteractiveNotificationBase(NotificationsBase):
261266 stdout=subprocess.PIPE,
262267 stderr=subprocess.PIPE,
263268 close_fds=True,
269+ universal_newlines=True,
264270 )
265271
266272 self.addCleanup(self._tidy_up_script_process)