← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-scripts-test-case into launchpad:master.

Commit message:
Fix ScriptsTestCase for Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/392389
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-scripts-test-case into launchpad:master.
diff --git a/lib/lp/services/scripts/tests/test_all_scripts.py b/lib/lp/services/scripts/tests/test_all_scripts.py
index 9e69804..60efb8c 100644
--- a/lib/lp/services/scripts/tests/test_all_scripts.py
+++ b/lib/lp/services/scripts/tests/test_all_scripts.py
@@ -35,7 +35,7 @@ class ScriptsTestCase(WithScenarios, TestCase):
     def test_script(self):
         # Run self.script_path with '-h' to make sure it runs cleanly.
         cmd_line = self.script_path + " -h"
-        out, err, returncode = run_script(cmd_line)
+        out, err, returncode = run_script(cmd_line, universal_newlines=True)
         self.assertThat(err, DocTestMatches('', doctest.REPORT_NDIFF))
         self.assertEqual('', err)
         self.assertEqual(os.EX_OK, returncode)
diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
index 1fa039a..2b4882b 100644
--- a/lib/lp/testing/__init__.py
+++ b/lib/lp/testing/__init__.py
@@ -1348,7 +1348,7 @@ def time_counter(origin=None, delta=timedelta(seconds=5)):
         now += delta
 
 
-def run_script(cmd_line, env=None, cwd=None):
+def run_script(cmd_line, env=None, cwd=None, universal_newlines=False):
     """Run the given command line as a subprocess.
 
     :param cmd_line: A command line suitable for passing to
@@ -1357,6 +1357,7 @@ def run_script(cmd_line, env=None, cwd=None):
         script will get a copy of your present environment.  Either way,
         PYTHONPATH will be removed from it because it will break the
         script.
+    :param universal_newlines: If True, return stdout and stderr as text.
     :return: A 3-tuple of stdout, stderr, and the process' return code.
     """
     if env is None:
@@ -1364,7 +1365,8 @@ def run_script(cmd_line, env=None, cwd=None):
     env.pop('PYTHONPATH', None)
     process = subprocess.Popen(
         cmd_line, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE, env=env, cwd=cwd)
+        stderr=subprocess.PIPE, env=env, cwd=cwd,
+        universal_newlines=universal_newlines)
     (out, err) = process.communicate()
     return out, err, process.returncode