[PATCH 1 of 6] py3: decode bytes before logging in run-tests.py

Denis Laxalde denis at laxalde.org
Mon Oct 21 06:00:53 EDT 2019


# HG changeset patch
# User Denis Laxalde <denis at laxalde.org>
# Date 1571650001 -7200
#      Mon Oct 21 11:26:41 2019 +0200
# Node ID f6d36e1d008ac5eaaccfaeb2a598cdbdf1d36391
# Parent  d0f89e8c615aca23f169c228a86f4f77fa4dbb67
py3: decode bytes before logging in run-tests.py

Avoids messages like "Found prerequisite b'diff' at b'/usr/bin/diff'"
under Python 3.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1504,7 +1504,7 @@ class PythonTest(Test):
         py3switch = self._py3warnings and b' -3' or b''
         # Quote the python(3) executable for Windows
         cmd = b'"%s"%s "%s"' % (PYTHON, py3switch, self.path)
-        vlog("# Running", cmd)
+        vlog("# Running", cmd.decode("utf-8"))
         normalizenewlines = os.name == 'nt'
         result = self._runcommand(cmd, env, normalizenewlines=normalizenewlines)
         if self._aborted:
@@ -1589,7 +1589,7 @@ class TTest(Test):
                 f.write(l)
 
         cmd = b'%s "%s"' % (self._shell, fname)
-        vlog("# Running", cmd)
+        vlog("# Running", cmd.decode("utf-8"))
 
         exitcode, output = self._runcommand(cmd, env)
 
@@ -3111,12 +3111,16 @@ class TestRunner(object):
                 'extensions.logexceptions=%s' % logexceptions.decode('utf-8')
             )
 
-        vlog("# Using TESTDIR", self._testdir)
-        vlog("# Using RUNTESTDIR", osenvironb[b'RUNTESTDIR'])
-        vlog("# Using HGTMP", self._hgtmp)
+        vlog("# Using TESTDIR", self._testdir.decode("utf-8"))
+        vlog("# Using RUNTESTDIR", osenvironb[b'RUNTESTDIR'].decode("utf-8"))
+        vlog("# Using HGTMP", self._hgtmp.decode("utf-8"))
         vlog("# Using PATH", os.environ["PATH"])
-        vlog("# Using", IMPL_PATH, osenvironb[IMPL_PATH])
-        vlog("# Writing to directory", self._outputdir)
+        vlog(
+            "# Using",
+            IMPL_PATH.decode("utf-8"),
+            osenvironb[IMPL_PATH].decode("utf-8"),
+        )
+        vlog("# Writing to directory", self._outputdir.decode("utf-8"))
 
         try:
             return self._runtests(testdescs) or 0
@@ -3357,7 +3361,7 @@ class TestRunner(object):
         if self.options.keep_tmpdir:
             return
 
-        vlog("# Cleaning up HGTMP", self._hgtmp)
+        vlog("# Cleaning up HGTMP", self._hgtmp.decode("utf-8"))
         shutil.rmtree(self._hgtmp, True)
         for f in self._createdfiles:
             try:
@@ -3468,7 +3472,7 @@ class TestRunner(object):
         makedirs(self._pythondir)
         makedirs(self._bindir)
 
-        vlog("# Running", cmd)
+        vlog("# Running", cmd.decode("utf-8"))
         if subprocess.call(_strpath(cmd), shell=True) == 0:
             if not self.options.verbose:
                 try:
@@ -3643,13 +3647,11 @@ class TestRunner(object):
             if os.name == 'nt' and not p.endswith(b'.exe'):
                 p += b'.exe'
             found = self._findprogram(p)
+            p = p.decode("utf-8")
             if found:
-                vlog("# Found prerequisite", p, "at", found)
+                vlog("# Found prerequisite", p, "at", found.decode("utf-8"))
             else:
-                print(
-                    "WARNING: Did not find prerequisite tool: %s "
-                    % p.decode("utf-8")
-                )
+                print("WARNING: Did not find prerequisite tool: %s " % p)
 
 
 def aggregateexceptions(path):



More information about the Mercurial-devel mailing list