Patchwork [resend] run-tests: write out scripts in binary mode

login
register
mail settings
Submitter Augie Fackler
Date July 18, 2014, 2:23 a.m.
Message ID <5774c2a87bf00e635a33.1405650196@130.17.16.172.in-addr.arpa>
Download mbox | patch
Permalink /patch/5183/
State Accepted
Commit 792ebd7dc5f64095d172f93e33eb1c9172ebbd6d
Headers show

Comments

Augie Fackler - July 18, 2014, 2:23 a.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1383680855 18000
#      Tue Nov 05 14:47:35 2013 -0500
# Node ID 5774c2a87bf00e635a33caa458871f50a976f236
# Parent  08dcb572a45668599ba82bdaf1940d373660b562
run-tests: write out scripts in binary mode

Caught because Python 3 refuses to write bytes to a non-binary fd.
Matt Mackall - July 18, 2014, 5:15 p.m.
On Thu, 2014-07-17 at 22:23 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1383680855 18000
> #      Tue Nov 05 14:47:35 2013 -0500
> # Node ID 5774c2a87bf00e635a33caa458871f50a976f236
> # Parent  08dcb572a45668599ba82bdaf1940d373660b562
> run-tests: write out scripts in binary mode
> 
> Caught because Python 3 refuses to write bytes to a non-binary fd.

Queued for default, thanks.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -112,7 +112,7 @@ 
     for filename in files:
         try:
             path = os.path.expanduser(os.path.expandvars(filename))
-            f = open(path, "r")
+            f = open(path, "rb")
         except IOError, err:
             if err.errno != errno.ENOENT:
                 raise
@@ -402,7 +402,7 @@ 
         if debug:
             self._refout = None # to match "out is None"
         elif os.path.exists(self.refpath):
-            f = open(self.refpath, 'r')
+            f = open(self.refpath, 'rb')
             self._refout = f.read().splitlines(True)
             f.close()
         else:
@@ -644,7 +644,7 @@ 
 
     def _createhgrc(self, path):
         """Create an hgrc file for this test."""
-        hgrc = open(path, 'w')
+        hgrc = open(path, 'wb')
         hgrc.write('[ui]\n')
         hgrc.write('slash = True\n')
         hgrc.write('interactive = False\n')
@@ -701,7 +701,7 @@ 
         return os.path.join(self._testdir, self.name)
 
     def _run(self, replacements, env):
-        f = open(self.path)
+        f = open(self.path, 'rb')
         lines = f.readlines()
         f.close()
 
@@ -709,7 +709,7 @@ 
 
         # Write out the generated script.
         fname = '%s.sh' % self._testtmp
-        f = open(fname, 'w')
+        f = open(fname, 'wb')
         for l in script:
             f.write(l)
         f.close()
@@ -1237,7 +1237,7 @@ 
                     continue
 
                 if self._keywords:
-                    f = open(test.path)
+                    f = open(test.path, 'rb')
                     t = f.read().lower() + test.name.lower()
                     f.close()
                     ignored = False
@@ -1697,7 +1697,7 @@ 
             if not self.options.verbose:
                 os.remove(installerrs)
         else:
-            f = open(installerrs)
+            f = open(installerrs, 'rb')
             for line in f:
                 print line,
             f.close()
@@ -1708,11 +1708,11 @@ 
 
         if self.options.py3k_warnings and not self.options.anycoverage:
             vlog("# Updating hg command to enable Py3k Warnings switch")
-            f = open(os.path.join(self._bindir, 'hg'), 'r')
+            f = open(os.path.join(self._bindir, 'hg'), 'rb')
             lines = [line.rstrip() for line in f]
             lines[0] += ' -3'
             f.close()
-            f = open(os.path.join(self._bindir, 'hg'), 'w')
+            f = open(os.path.join(self._bindir, 'hg'), 'wb')
             for line in lines:
                 f.write(line + '\n')
             f.close()