on xenial help sign in
Ship python3 autopilot modules.
commit278fdb08f72d1fadff4012f83812e369527150ab authorDimitri John Ledkov <dimitri.ledkov@canonical.com> dateFri 28 Feb 2014, 10:46 (13 years ago) parent13dafc3f3b2acb
11 files changed+76−27
cmake/modules/autopilot.cmake+10−1 debian/control+8−1 debian/rules+2−2 tests/autopilot/unity8/__init__.py+5−2 tests/autopilot/unity8/process_helpers.py+1−1 tests/autopilot/unity8/shell/emulators/create_interactive_notification.py+2−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+8−1 tests/autopilot/unity8/shell/tests/test_upstart.py+6−1
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+8−1
@@ -28,7 +28,8 @@ Build-Depends: cmake,
2828 pkg-config,
2929 python:any (>= 2.7),
3030 python-setuptools,
31− python3:any,
31+ python3-all:any,
32+ python3-setuptools,
3233 qt5-default,
3334 qtbase5-dev,
3435 qtbase5-dev-tools,
@@ -107,16 +108,22 @@ Depends: gir1.2-glib-2.0,
107108 libautopilot-qt (>= 1.4),
108109 libqt5test5,
109110 libqt5widgets5,
111+ python-autopilot,
110112 python-evdev,
111113 python-fixtures,
112114 python-gi,
113115 python-mock,
116+ python3-autopilot,
117+ python3-evdev,
118+ python3-fixtures,
119+ python3-gi,
114120 ubuntu-ui-toolkit-autopilot,
115121 unity8 (>= ${source:Version}),
116122 unity8-fake-env (>= ${source:Version}),
117123 url-dispatcher-tools,
118124 ${misc:Depends},
119125 ${python:Depends},
126+ ${python3:Depends},
120127 ${shlibs:Depends},
121128Description: Test package for Unity 8 shell
122129 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+5−2
@@ -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
@@ -128,7 +131,7 @@ def _get_xdg_upstart_env():
128131 "get-env",
129132 "--global",
130133 "XDG_DATA_DIRS"
131− ]).rstrip()
134+ ], universal_newlines=True).rstrip()
132135 except subprocess.CalledProcessError:
133136 return None
134137
tests/autopilot/unity8/process_helpers.py+1−1
@@ -142,7 +142,7 @@ def _get_unity_status():
142142 '/sbin/initctl',
143143 'status',
144144 'unity8'
145− ])
145+ ], universal_newlines=True)
146146 except subprocess.CalledProcessError as e:
147147 raise CannotAccessUnity("Unable to get unity's status: %s" % str(e))
148148
tests/autopilot/unity8/shell/emulators/create_interactive_notification.py+2−1
@@ -1,4 +1,5 @@
11#!/usr/bin/env python
2+from __future__ import print_function
23
34# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
45#
@@ -25,7 +26,7 @@ import signal
2526
2627
2728def action_callback(notification, action_id, data):
28− print action_id
29+ print(action_id)
2930
3031
3132def quit_callback(notification):
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+8−1
@@ -33,9 +33,15 @@ import os
3333import logging
3434import signal
3535import subprocess
36+import sys
3637
3738logger = logging.getLogger(__name__)
3839
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+
3945
4046class NotificationsBase(UnityTestCase):
4147 """Base class for all notification tests that provides helper methods."""
@@ -261,6 +267,7 @@ class InteractiveNotificationBase(NotificationsBase):
261267 stdout=subprocess.PIPE,
262268 stderr=subprocess.PIPE,
263269 close_fds=True,
270+ universal_newlines=True,
264271 )
265272
266273 self.addCleanup(self._tidy_up_script_process)
@@ -298,7 +305,7 @@ class InteractiveNotificationBase(NotificationsBase):
298305 if self._notify_proc is None:
299306 raise AssertionError("No interactive notification was created.")
300307
301− for i in xrange(timeout):
308+ for i in range(timeout):
302309 self._notify_proc.poll()
303310 if self._notify_proc.returncode is not None:
304311 output = self._notify_proc.communicate()
tests/autopilot/unity8/shell/tests/test_upstart.py+6−1
@@ -36,6 +36,11 @@ import logging
3636
3737logger = logging.getLogger(__name__)
3838
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
3944
4045class UpstartIntegrationTests(UnityTestCase):
4146
@@ -52,7 +57,7 @@ class UpstartIntegrationTests(UnityTestCase):
5257 self.process = subprocess.Popen([get_binary_path()] + self.unity_geometry_args)
5358 def ensure_stopped():
5459 self.process.terminate()
55− for i in xrange(10):
60+ for i in range(10):
5661 try:
5762 self._get_status()
5863 except OSError: