changeset 25162:153b9c5235c2

run-tests: replace open-coded .decode()s on paths with a helper (issue4667) This also cleans up the mkdtemp code mentioned in the previous patch. At this point, the remaining callsites of .{en,de)code() are in the following categories: Handling escaped lines in .t files ----------------------------------- It seems eminently reasonable to me for us to declare that .t files are valid utf-8, and that any escape sequences we see in .t files should be valid unicode_escape sequences. Making error text safe for cdata blocks for xml error reports ------------------------------------------------------------- This is a point where we're already basically screwed, and we're simply trying to do something "good enough" that the xml output will be vaguely useful to the user. Punting here seems fine, and we should probably stick to the same encoding here that we used in the previous section.
author Augie Fackler <augie@google.com>
date Sun, 17 May 2015 21:47:18 -0400
parents 4d30467d944e
children 3139900f31b1
files tests/run-tests.py
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Sun May 17 21:40:12 2015 -0400
+++ b/tests/run-tests.py	Sun May 17 21:47:18 2015 -0400
@@ -83,15 +83,26 @@
     xrange = range # we use xrange in one place, and we'd rather not use range
     def _bytespath(p):
         return p.encode('utf-8')
+
+    def _strpath(p):
+        return p.decode('utf-8')
+
 elif sys.version_info >= (3, 0, 0):
     print('%s is only supported on Python 3.5+ and 2.6-2.7, not %s' %
           (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3])))
     sys.exit(70) # EX_SOFTWARE from `man 3 sysexit`
 else:
     PYTHON3 = False
+
+    # In python 2.x, path operations are generally done using
+    # bytestrings by default, so we don't have to do any extra
+    # fiddling there. We define the wrapper functions anyway just to
+    # help keep code consistent between platforms.
     def _bytespath(p):
         return p
 
+    _strpath = _bytespath
+
 def checkportisavailable(port):
     """return true if a port seems free to bind on localhost"""
     try:
@@ -443,7 +454,7 @@
         """
         self.path = path
         self.bname = os.path.basename(path)
-        self.name = self.bname.decode('utf-8')
+        self.name = _strpath(self.bname)
         self._testdir = os.path.dirname(path)
         self.errpath = os.path.join(self._testdir, b'%s.err' % self.bname)
 
@@ -1734,8 +1745,8 @@
                 # in all lowercase, which causes troubles with paths (issue3490)
                 d = osenvironb.get(b'TMP', None)
             # FILE BUG: mkdtemp works only on unicode in Python 3
-            tmpdir = tempfile.mkdtemp('', 'hgtests.',
-                                      d and d.decode('utf-8')).encode('utf-8')
+            tmpdir = tempfile.mkdtemp('', 'hgtests.', d and _strpath(d))
+            tmpdir = _bytespath(tmpdir)
 
         self._hgtmp = osenvironb[b'HGTMP'] = (
             os.path.realpath(tmpdir))
@@ -2126,7 +2137,7 @@
         cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"'
         cmd = cmd % PYTHON
         if PYTHON3:
-            cmd = cmd.decode('utf-8')
+            cmd = _strpath(cmd)
         pipe = os.popen(cmd)
         try:
             self._hgpath = _bytespath(pipe.read().strip())