on xenial help sign in
Ship python3 autopilot modules.
278fdb0Dimitri John Ledkov
cmake/modules/autopilot.cmake+10−1
@@ -2,7 +2,7 @@ add_custom_target(autopilot)
2
2
3function(declare_autopilot_test TEST_NAME TEST_SUITE WORKING_DIR)
3function(declare_autopilot_test TEST_NAME TEST_SUITE WORKING_DIR)
4 add_custom_target(autopilot-${TEST_NAME}
4 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}
6 WORKING_DIRECTORY ${WORKING_DIR}
6 WORKING_DIRECTORY ${WORKING_DIR}
7 DEPENDS fake_install
7 DEPENDS fake_install
8 )
8 )
@@ -12,4 +12,13 @@ function(declare_autopilot_test TEST_NAME TEST_SUITE WORKING_DIR)
12 )
12 )
13
13
14 add_dependencies(autopilot autopilot-${TEST_NAME})
14 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+
15endfunction()
24endfunction()
debian/control+8−1
@@ -28,7 +28,8 @@ Build-Depends: cmake,
28 pkg-config,
28 pkg-config,
29 python:any (>= 2.7),
29 python:any (>= 2.7),
30 python-setuptools,
30 python-setuptools,
31− python3:any,
31+ python3-all:any,
32+ python3-setuptools,
32 qt5-default,
33 qt5-default,
33 qtbase5-dev,
34 qtbase5-dev,
34 qtbase5-dev-tools,
35 qtbase5-dev-tools,
@@ -107,16 +108,22 @@ Depends: gir1.2-glib-2.0,
107 libautopilot-qt (>= 1.4),
108 libautopilot-qt (>= 1.4),
108 libqt5test5,
109 libqt5test5,
109 libqt5widgets5,
110 libqt5widgets5,
111+ python-autopilot,
110 python-evdev,
112 python-evdev,
111 python-fixtures,
113 python-fixtures,
112 python-gi,
114 python-gi,
113 python-mock,
115 python-mock,
116+ python3-autopilot,
117+ python3-evdev,
118+ python3-fixtures,
119+ python3-gi,
114 ubuntu-ui-toolkit-autopilot,
120 ubuntu-ui-toolkit-autopilot,
115 unity8 (>= ${source:Version}),
121 unity8 (>= ${source:Version}),
116 unity8-fake-env (>= ${source:Version}),
122 unity8-fake-env (>= ${source:Version}),
117 url-dispatcher-tools,
123 url-dispatcher-tools,
118 ${misc:Depends},
124 ${misc:Depends},
119 ${python:Depends},
125 ${python:Depends},
126+ ${python3:Depends},
120 ${shlibs:Depends},
127 ${shlibs:Depends},
121Description: Test package for Unity 8 shell
128Description: Test package for Unity 8 shell
122 Autopilot tests for the unity8 package
129 Autopilot tests for the unity8 package
debian/rules+2−2
@@ -10,7 +10,7 @@ SCOPES_RECOMMENDS := $(shell perl debian/scopes-recommends-generator /usr/share/
10
10
11.PHONY: build
11.PHONY: build
12build %:
12build %:
13− dh $@ --parallel --fail-missing --with python2
13+ dh $@ --parallel --fail-missing --with python2,python3
14
14
15override_dh_auto_clean:
15override_dh_auto_clean:
16 dh_auto_clean
16 dh_auto_clean
@@ -28,7 +28,7 @@ override_dh_auto_build:
28override_dh_install:
28override_dh_install:
29 # install autopilot tests
29 # install autopilot tests
30 cd tests/autopilot; \
30 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 \
32 $$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
32 $$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
33 done; \
33 done; \
34 cd $(CURDIR)
34 cd $(CURDIR)
tests/autopilot/unity8/__init__.py+5−2
@@ -82,7 +82,10 @@ def get_binary_path(binary="unity8"):
82 )
82 )
83 if not os.path.exists(binary_path):
83 if not os.path.exists(binary_path):
84 try:
84 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()
86 except subprocess.CalledProcessError as e:
89 except subprocess.CalledProcessError as e:
87 raise RuntimeError("Unable to locate %s binary: %r" % (binary, e))
90 raise RuntimeError("Unable to locate %s binary: %r" % (binary, e))
88 return binary_path
91 return binary_path
@@ -128,7 +131,7 @@ def _get_xdg_upstart_env():
128 "get-env",
131 "get-env",
129 "--global",
132 "--global",
130 "XDG_DATA_DIRS"
133 "XDG_DATA_DIRS"
131− ]).rstrip()
134+ ], universal_newlines=True).rstrip()
132 except subprocess.CalledProcessError:
135 except subprocess.CalledProcessError:
133 return None
136 return None
134
137
tests/autopilot/unity8/process_helpers.py+1−1
@@ -142,7 +142,7 @@ def _get_unity_status():
142 '/sbin/initctl',
142 '/sbin/initctl',
143 'status',
143 'status',
144 'unity8'
144 'unity8'
145− ])
145+ ], universal_newlines=True)
146 except subprocess.CalledProcessError as e:
146 except subprocess.CalledProcessError as e:
147 raise CannotAccessUnity("Unable to get unity's status: %s" % str(e))
147 raise CannotAccessUnity("Unable to get unity's status: %s" % str(e))
148
148
tests/autopilot/unity8/shell/emulators/create_interactive_notification.py+2−1
@@ -1,4 +1,5 @@
1#!/usr/bin/env python
1#!/usr/bin/env python
2+from __future__ import print_function
2
3
3# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4#
5#
@@ -25,7 +26,7 @@ import signal
25
26
26
27
27def action_callback(notification, action_id, data):
28def action_callback(notification, action_id, data):
28− print action_id
29+ print(action_id)
29
30
30
31
31def quit_callback(notification):
32def quit_callback(notification):
tests/autopilot/unity8/shell/tests/__init__.py+12−13
@@ -85,12 +85,12 @@ class UnityTestCase(AutopilotTestCase):
85 @classmethod
85 @classmethod
86 def setUpClass(cls):
86 def setUpClass(cls):
87 try:
87 try:
88− output = subprocess.check_output([
88+ output = subprocess.check_output(
89− "/sbin/initctl",
89+ ["/sbin/initctl", "status", "unity8"],
90− "status",
91− "unity8"
92− ], stderr=subprocess.STDOUT)
90+ stderr=subprocess.STDOUT,
91+ universal_newlines=True,
92+ )
93− except subprocess.CalledProcessError, e:
93+ except subprocess.CalledProcessError as e:
94 sys.stderr.write(
94 sys.stderr.write(
95 "Error: `initctl status unity8` failed, most probably the "
95 "Error: `initctl status unity8` failed, most probably the "
96 "unity8 session could not be found:\n\n"
96 "unity8 session could not be found:\n\n"
@@ -218,12 +218,11 @@ class UnityTestCase(AutopilotTestCase):
218 def _patch_environment(self, key, value):
218 def _patch_environment(self, key, value):
219 """Wrapper for patching env for upstart environment."""
219 """Wrapper for patching env for upstart environment."""
220 try:
220 try:
221− current_value = subprocess.check_output([
221+ current_value = subprocess.check_output(
222− "/sbin/initctl",
222+ ["/sbin/initctl", "get-env", "--global", key],
223− "get-env",
224− "--global",
225− key
226− ], stderr=subprocess.STDOUT).rstrip()
223+ stderr=subprocess.STDOUT,
224+ universal_newlines=True,
225+ ).rstrip()
227 except subprocess.CalledProcessError:
226 except subprocess.CalledProcessError:
228 current_value = None
227 current_value = None
229
228
@@ -305,7 +304,7 @@ class UnityTestCase(AutopilotTestCase):
305
304
306 binary_arg = "BINARY=%s" % binary_path
305 binary_arg = "BINARY=%s" % binary_path
307 extra_args = "ARGS=%s" % " ".join(args)
306 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()]
309 all_args = [binary_arg, extra_args] + env_args
308 all_args = [binary_arg, extra_args] + env_args
310
309
311 self.addCleanup(self._cleanup_launching_upstart_unity)
310 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.
27
27
28"""
28"""
29
29
30+try:
31+ from unittest import mock
32+except ImportError:
30−import mock
33+ import mock
31
34
32from testtools.matchers import Contains, HasLength
35from testtools.matchers import Contains, HasLength
33
36
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
26
26
27from autopilot.matchers import Eventually
27from autopilot.matchers import Eventually
28from autopilot.platform import model
28from autopilot.platform import model
29+import sys
29from testtools import skipUnless
30from testtools import skipUnless
30from testtools.matchers import Equals
31from testtools.matchers import Equals
31import logging
32import logging
32
33
33logger = logging.getLogger(__name__)
34logger = logging.getLogger(__name__)
34
35
36+# py2 compatible alias for py3
37+if sys.version >= '3':
38+ basestring = str
39+
40+
35class TestLockscreen(UnityTestCase):
41class TestLockscreen(UnityTestCase):
36
42
37 """Tests for the lock screen."""
43 """Tests for the lock screen."""
@@ -125,7 +131,10 @@ class TestLockscreen(UnityTestCase):
125 """
131 """
126
132
127 if not isinstance(code, basestring):
133 if not isinstance(code, basestring):
134+ raise TypeError(
128− raise TypeError("'code' parameter must be a string.")
135+ "'code' parameter must be a string, not %r."
136+ % type(passphrase)
137+ )
129 for num in code:
138 for num in code:
130 if not num.isdigit():
139 if not num.isdigit():
131 raise ValueError(
140 raise ValueError(
@@ -142,7 +151,10 @@ class TestLockscreen(UnityTestCase):
142
151
143 """
152 """
144 if not isinstance(passphrase, basestring):
153 if not isinstance(passphrase, basestring):
154+ raise TypeError(
145− raise TypeError("'passphrase' parameter must be a string.")
155+ "'passphrase' parameter must be a string, not %r."
156+ % type(passphrase)
157+ )
146
158
147 pinentryField = self.main_window.get_pinentryField()
159 pinentryField = self.main_window.get_pinentryField()
148 self.touch.tap_object(pinentryField)
160 self.touch.tap_object(pinentryField)
@@ -161,7 +173,10 @@ class TestLockscreen(UnityTestCase):
161
173
162 """
174 """
163 if not isinstance(passphrase, basestring):
175 if not isinstance(passphrase, basestring):
176+ raise TypeError(
164− raise TypeError("'passphrase' parameter must be a string.")
177+ "'passphrase' parameter must be a string, not %r."
178+ % type(passphrase)
179+ )
165
180
166 prompt = self.main_window.get_greeter().get_prompt()
181 prompt = self.main_window.get_greeter().get_prompt()
167 self.touch.tap_object(prompt)
182 self.touch.tap_object(prompt)
tests/autopilot/unity8/shell/tests/test_notifications.py+8−1
@@ -33,9 +33,15 @@ import os
33import logging
33import logging
34import signal
34import signal
35import subprocess
35import subprocess
36+import sys
36
37
37logger = logging.getLogger(__name__)
38logger = logging.getLogger(__name__)
38
39
40+# from __future__ import range
41+# (python3's range, is same as python2's xrange)
42+if sys.version_info < (3,):
43+ range = xrange
44+
39
45
40class NotificationsBase(UnityTestCase):
46class NotificationsBase(UnityTestCase):
41 """Base class for all notification tests that provides helper methods."""
47 """Base class for all notification tests that provides helper methods."""
@@ -261,6 +267,7 @@ class InteractiveNotificationBase(NotificationsBase):
261 stdout=subprocess.PIPE,
267 stdout=subprocess.PIPE,
262 stderr=subprocess.PIPE,
268 stderr=subprocess.PIPE,
263 close_fds=True,
269 close_fds=True,
270+ universal_newlines=True,
264 )
271 )
265
272
266 self.addCleanup(self._tidy_up_script_process)
273 self.addCleanup(self._tidy_up_script_process)
@@ -298,7 +305,7 @@ class InteractiveNotificationBase(NotificationsBase):
298 if self._notify_proc is None:
305 if self._notify_proc is None:
299 raise AssertionError("No interactive notification was created.")
306 raise AssertionError("No interactive notification was created.")
300
307
301− for i in xrange(timeout):
308+ for i in range(timeout):
302 self._notify_proc.poll()
309 self._notify_proc.poll()
303 if self._notify_proc.returncode is not None:
310 if self._notify_proc.returncode is not None:
304 output = self._notify_proc.communicate()
311 output = self._notify_proc.communicate()
tests/autopilot/unity8/shell/tests/test_upstart.py+6−1
@@ -36,6 +36,11 @@ import logging
36
36
37logger = logging.getLogger(__name__)
37logger = logging.getLogger(__name__)
38
38
39+# from __future__ import range
40+# (python3's range, is same as python2's xrange)
41+import sys
42+if sys.version_info < (3,):
43+ range = xrange
39
44
40class UpstartIntegrationTests(UnityTestCase):
45class UpstartIntegrationTests(UnityTestCase):
41
46
@@ -52,7 +57,7 @@ class UpstartIntegrationTests(UnityTestCase):
52 self.process = subprocess.Popen([get_binary_path()] + self.unity_geometry_args)
57 self.process = subprocess.Popen([get_binary_path()] + self.unity_geometry_args)
53 def ensure_stopped():
58 def ensure_stopped():
54 self.process.terminate()
59 self.process.terminate()
55− for i in xrange(10):
60+ for i in range(10):
56 try:
61 try:
57 self._get_status()
62 self._get_status()
58 except OSError:
63 except OSError: