Merge ~cjwatson/launchpad:py3-scripts-test-case into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: a525f3a1b0df5b68f55aa01a2b92a6ed02be28c2
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-scripts-test-case
Merge into: launchpad:master
Diff against target: 43 lines (+5/-3)
2 files modified
lib/lp/services/scripts/tests/test_all_scripts.py (+1/-1)
lib/lp/testing/__init__.py (+4/-2)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+392389@code.launchpad.net

Commit message

Fix ScriptsTestCase for Python 3

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/services/scripts/tests/test_all_scripts.py b/lib/lp/services/scripts/tests/test_all_scripts.py
2index 9e69804..60efb8c 100644
3--- a/lib/lp/services/scripts/tests/test_all_scripts.py
4+++ b/lib/lp/services/scripts/tests/test_all_scripts.py
5@@ -35,7 +35,7 @@ class ScriptsTestCase(WithScenarios, TestCase):
6 def test_script(self):
7 # Run self.script_path with '-h' to make sure it runs cleanly.
8 cmd_line = self.script_path + " -h"
9- out, err, returncode = run_script(cmd_line)
10+ out, err, returncode = run_script(cmd_line, universal_newlines=True)
11 self.assertThat(err, DocTestMatches('', doctest.REPORT_NDIFF))
12 self.assertEqual('', err)
13 self.assertEqual(os.EX_OK, returncode)
14diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
15index 1fa039a..2b4882b 100644
16--- a/lib/lp/testing/__init__.py
17+++ b/lib/lp/testing/__init__.py
18@@ -1348,7 +1348,7 @@ def time_counter(origin=None, delta=timedelta(seconds=5)):
19 now += delta
20
21
22-def run_script(cmd_line, env=None, cwd=None):
23+def run_script(cmd_line, env=None, cwd=None, universal_newlines=False):
24 """Run the given command line as a subprocess.
25
26 :param cmd_line: A command line suitable for passing to
27@@ -1357,6 +1357,7 @@ def run_script(cmd_line, env=None, cwd=None):
28 script will get a copy of your present environment. Either way,
29 PYTHONPATH will be removed from it because it will break the
30 script.
31+ :param universal_newlines: If True, return stdout and stderr as text.
32 :return: A 3-tuple of stdout, stderr, and the process' return code.
33 """
34 if env is None:
35@@ -1364,7 +1365,8 @@ def run_script(cmd_line, env=None, cwd=None):
36 env.pop('PYTHONPATH', None)
37 process = subprocess.Popen(
38 cmd_line, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
39- stderr=subprocess.PIPE, env=env, cwd=cwd)
40+ stderr=subprocess.PIPE, env=env, cwd=cwd,
41+ universal_newlines=universal_newlines)
42 (out, err) = process.communicate()
43 return out, err, process.returncode
44

Subscribers

People subscribed via source and target branches

to status/vote changes: