Merge lp:~veebers/unity8/update_ap_tests_ready_for_py3 into lp:unity8

Proposed by Christopher Lee
Status: Rejected
Rejected by: Albert Astals Cid
Proposed branch: lp:~veebers/unity8/update_ap_tests_ready_for_py3
Merge into: lp:unity8
Diff against target: 192 lines (+68/-17)
6 files modified
.bzrignore (+3/-0)
tests/autopilot/tox.ini (+25/-0)
tests/autopilot/unity8/__init__.py (+4/-1)
tests/autopilot/unity8/shell/tests/__init__.py (+12/-13)
tests/autopilot/unity8/shell/tests/test_lock_screen.py (+18/-3)
tests/autopilot/unity8/shell/tests/test_notifications.py (+6/-0)
To merge this branch: bzr merge lp:~veebers/unity8/update_ap_tests_ready_for_py3
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Disapprove
Christopher Lee (community) Needs Fixing
PS Jenkins bot (community) continuous-integration Needs Fixing
Michał Sawicz Needs Fixing
Martin Pitt Approve
Review via email: mp+194655@code.launchpad.net

Commit message

Update the autopilot tests (and emulators) to make them compatible with python 3.

Description of the change

Update the autopilot tests (and emulators) to make them compatible with python 3.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

61 - data_path = "/usr/share/unity8/mocks/data"
62 + data_path = u"/usr/share/unity8/mocks/data"

Why are these kinds of changes necessary? "foo" is already a string in Python 3, and Python 2 mostly doesn't care (and obviously the tests currently work with intermixing bytes and strings). The u"" form is deprecated in Python 3, and in fact got removed entirely in 3.0 to 3.2 before it was reintroduced in 3.3 for backwards compat support.

145 - if not isinstance(code, basestring):
147 + if not isinstance(code, str):

Is there a chance that you'll get an unicode object in the tests when running with Python 2? I suppose you ran the py2 tests with this branch and it worked, but just making double-sure.

LGTM otherwise, thanks!

review: Needs Information
Revision history for this message
Christopher Lee (veebers) wrote :

Hi Martin,

I've updated the code addressing the issues highlighted in your review.
(the str/basestring change I took from the autopilot py3 update).

I ran the tests with both py2 && py3 using tox (that is also introduced in this MR).

Revision history for this message
Martin Pitt (pitti) wrote :

I can't speak about the new tox file (I never used that, and it seems a little redundant to me), but the actual porting looks good now, thank you!

review: Approve
Revision history for this message
Christopher Lee (veebers) wrote :

The intention with the tox integration is to make it easy for people to run any tests they create or modify and ensure they run under py2 && py3. At least until we are py3 only then it should be removed.

Perhaps there is a better way to do so? I'm open to suggestions.

Revision history for this message
Martin Pitt (pitti) wrote :

Don't get me wrong, I'm not saying it's bad. Just that I haven't used it so far and thus I don't know it. I usually just call the tests directly with python2/python3 in debian/tests/, debian/rules, "do-release" scripts, or wherever appropriate.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:524
http://jenkins.qa.ubuntu.com/job/unity8-ci/1643/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/734
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/722/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/245
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/166
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/167
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/167/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/166
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/671
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/734
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/734/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/722
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/722/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/3351/console
    SUCCESS: http://s-jenkins:8080/job/touch-flash-device/1440

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity8-ci/1643/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Tox executes:

autopilot run unity8.tests

But that matches 0 tests.

review: Needs Fixing
525. By Christopher Lee

Merge Trunk

526. By Christopher Lee

Fix typo in args string

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:526
http://jenkins.qa.ubuntu.com/job/unity8-ci/1675/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/879
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty-touch/867
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/308/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/198
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/199
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/199/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/198
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/790
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/879
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/879/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/867
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/867/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/3468
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/1557

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/1675/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Christopher Lee (veebers) wrote :

This will need a packaging change too that will install a python3 version as well (otherwise the py3 changes are useless at this stage).

review: Needs Fixing
Revision history for this message
Martin Pitt (pitti) wrote :

I thought we wanted land this first, as we *will* cause failures during CI test running if we pull in python3-autopilot at this point. Francis wanted some package to experiment with to teach the CI infrastructure about using "autopilot" vs. "autopilot-py3" according to the dependencies, but that's not there yet.

Revision history for this message
Michał Sawicz (saviq) wrote :

I thought that was the idea, too - that's why we're doing it so that it works with py2 and py3? So that we can easily flip the switch later?

Revision history for this message
Christopher Lee (veebers) wrote :

Right, I think I need to clarify what I had intended.

I noticed that the changes made here cannot be consumed by other python3 versions of tests when I started checking the compatibility of the ubuntu-keyboard tests that use the unity8.process_helpers.
This is why I wanted to change the packaging so that the tests, and more importantly the emulators, were installed for python 2 and python 3 (so I could proceed with the u-kb stuff).

This comment made on the ui-toolkit is topical: https://code.launchpad.net/~chris.gagnon/ubuntu-ui-toolkit/autopilot-python3-package/+merge/196358/comments/454927
(effectively either split into 2 packages or insanity of dual-installation).

I get the feeling that at this stage that I should alter what I have so that it is split into 2 packages.

Revision history for this message
Michał Sawicz (saviq) wrote :

Hey Chris, any word on this?

Revision history for this message
Dimitri John Ledkov (xnox) wrote :
Revision history for this message
Albert Astals Cid (aacid) wrote :

Rejecting based on Dimitri's comment

review: Disapprove

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2013-06-28 20:27:17 +0000
+++ .bzrignore 2013-11-19 19:38:26 +0000
@@ -8,3 +8,6 @@
8/.settings8/.settings
9/.pydevproject9/.pydevproject
10message.txt10message.txt
11# tox/python/autopilot
12tests/autopilot/unity.egg-info
13tests/autopilot/.tox
1114
=== added file 'tests/autopilot/tox.ini'
--- tests/autopilot/tox.ini 1970-01-01 00:00:00 +0000
+++ tests/autopilot/tox.ini 2013-11-19 19:38:26 +0000
@@ -0,0 +1,25 @@
1# Tox (http://tox.testrun.org/) is a tool for running tests
2# in multiple virtualenvs. This configuration file will run the
3# test suite on all supported python versions.
4#
5# To use it, install the `tox` python package:
6# "sudo pip install tox" or "sudo apt-get install python-tox"
7# then run "tox" from this directory.
8
9
10[tox]
11envlist = flake8, py27, py33
12
13[flake8]
14exclude = .tox
15
16[testenv]
17sitepackages = True
18commands =
19 autopilot run {posargs:unity8}
20
21[testenv:flake8]
22deps =
23 flake8
24commands =
25 flake8
026
=== modified file 'tests/autopilot/unity8/__init__.py'
--- tests/autopilot/unity8/__init__.py 2013-10-17 09:01:20 +0000
+++ tests/autopilot/unity8/__init__.py 2013-11-19 19:38:26 +0000
@@ -82,7 +82,10 @@
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_path91 return binary_path
8992
=== modified file 'tests/autopilot/unity8/shell/tests/__init__.py'
--- tests/autopilot/unity8/shell/tests/__init__.py 2013-11-01 13:59:50 +0000
+++ tests/autopilot/unity8/shell/tests/__init__.py 2013-11-19 19:38:26 +0000
@@ -86,12 +86,12 @@
86 @classmethod86 @classmethod
87 def setUpClass(cls):87 def setUpClass(cls):
88 try:88 try:
89 output = subprocess.check_output([89 output = subprocess.check_output(
90 "/sbin/initctl",90 ["/sbin/initctl", "status", "unity8"],
91 "status",91 stderr=subprocess.STDOUT,
92 "unity8"92 universal_newlines=True,
93 ], stderr=subprocess.STDOUT)93 )
94 except subprocess.CalledProcessError, e:94 except subprocess.CalledProcessError as e:
95 sys.stderr.write(95 sys.stderr.write(
96 "Error: `initctl status unity8` failed, most probably the "96 "Error: `initctl status unity8` failed, most probably the "
97 "unity8 session could not be found:\n\n"97 "unity8 session could not be found:\n\n"
@@ -219,12 +219,11 @@
219 def _patch_environment(self, key, value):219 def _patch_environment(self, key, value):
220 """Wrapper for patching env for upstart environment."""220 """Wrapper for patching env for upstart environment."""
221 try:221 try:
222 current_value = subprocess.check_output([222 current_value = subprocess.check_output(
223 "/sbin/initctl",223 ["/sbin/initctl", "get-env", "--global", key],
224 "get-env",224 stderr=subprocess.STDOUT,
225 "--global",225 universal_newlines=True,
226 key226 ).rstrip()
227 ], stderr=subprocess.STDOUT).rstrip()
228 except subprocess.CalledProcessError:227 except subprocess.CalledProcessError:
229 current_value = None228 current_value = None
230229
@@ -311,7 +310,7 @@
311 "unity8",310 "unity8",
312 binary_arg,311 binary_arg,
313 extra_args,312 extra_args,
314 ] + ["%s=%s" % (k, v) for k, v in self._environment.iteritems()],313 ] + ["%s=%s" % (k, v) for k, v in self._environment.items()],
315 stderr=subprocess.STDOUT,314 stderr=subprocess.STDOUT,
316 )315 )
317316
318317
=== modified file 'tests/autopilot/unity8/shell/tests/test_lock_screen.py'
--- tests/autopilot/unity8/shell/tests/test_lock_screen.py 2013-08-23 07:38:56 +0000
+++ tests/autopilot/unity8/shell/tests/test_lock_screen.py 2013-11-19 19:38:26 +0000
@@ -25,12 +25,18 @@
2525
26from autopilot.matchers import Eventually26from autopilot.matchers import Eventually
27from autopilot.platform import model27from autopilot.platform import model
28import sys
28from testtools import skipUnless29from testtools import skipUnless
29from testtools.matchers import Equals30from testtools.matchers import Equals
30import logging31import logging
3132
32logger = logging.getLogger(__name__)33logger = logging.getLogger(__name__)
3334
35# py2 compatible alias for py3
36if sys.version >= '3':
37 basestring = str
38
39
34class TestLockscreen(UnityTestCase):40class TestLockscreen(UnityTestCase):
3541
36 """Tests for the lock screen."""42 """Tests for the lock screen."""
@@ -124,7 +130,10 @@
124 """130 """
125131
126 if not isinstance(code, basestring):132 if not isinstance(code, basestring):
127 raise TypeError("'code' parameter must be a string.")133 raise TypeError(
134 "'code' parameter must be a string, not %r."
135 % type(passphrase)
136 )
128 for num in code:137 for num in code:
129 if not num.isdigit():138 if not num.isdigit():
130 raise ValueError(139 raise ValueError(
@@ -141,7 +150,10 @@
141150
142 """151 """
143 if not isinstance(passphrase, basestring):152 if not isinstance(passphrase, basestring):
144 raise TypeError("'passphrase' parameter must be a string.")153 raise TypeError(
154 "'passphrase' parameter must be a string, not %r."
155 % type(passphrase)
156 )
145157
146 pinentryField = self.main_window.get_pinentryField()158 pinentryField = self.main_window.get_pinentryField()
147 self.touch.tap_object(pinentryField)159 self.touch.tap_object(pinentryField)
@@ -160,7 +172,10 @@
160172
161 """173 """
162 if not isinstance(passphrase, basestring):174 if not isinstance(passphrase, basestring):
163 raise TypeError("'passphrase' parameter must be a string.")175 raise TypeError(
176 "'passphrase' parameter must be a string, not %r."
177 % type(passphrase)
178 )
164179
165 prompt = self.main_window.get_greeter().get_prompt()180 prompt = self.main_window.get_greeter().get_prompt()
166 self.touch.tap_object(prompt)181 self.touch.tap_object(prompt)
167182
=== modified file 'tests/autopilot/unity8/shell/tests/test_notifications.py'
--- tests/autopilot/unity8/shell/tests/test_notifications.py 2013-11-01 13:59:50 +0000
+++ tests/autopilot/unity8/shell/tests/test_notifications.py 2013-11-19 19:38:26 +0000
@@ -32,9 +32,14 @@
32import logging32import logging
33import signal33import signal
34import subprocess34import subprocess
35import sys
3536
36logger = logging.getLogger(__name__)37logger = logging.getLogger(__name__)
3738
39# backwards compatible alias for Python 3
40if sys.version > '3':
41 xrange = range
42
3843
39class NotificationsBase(UnityTestCase):44class NotificationsBase(UnityTestCase):
40 """Base class for all notification tests that provides helper methods."""45 """Base class for all notification tests that provides helper methods."""
@@ -266,6 +271,7 @@
266 stdout=subprocess.PIPE,271 stdout=subprocess.PIPE,
267 stderr=subprocess.PIPE,272 stderr=subprocess.PIPE,
268 close_fds=True,273 close_fds=True,
274 universal_newlines=True,
269 )275 )
270276
271 self.addCleanup(self._tidy_up_script_process)277 self.addCleanup(self._tidy_up_script_process)

Subscribers

People subscribed via source and target branches