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

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 21, 2019, 10 a.m.
Message ID <f6d36e1d008ac5eaaccf.1571652053@marimba>
Download mbox | patch
Permalink /patch/42510/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 21, 2019, 10 a.m.
# HG changeset patch
# User Denis Laxalde <denis@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.
Yuya Nishihara - Oct. 21, 2019, 1:40 p.m.
On Mon, 21 Oct 2019 12:00:53 +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis@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

> @@ -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"))

Maybe better to use _strpath() for paths.
Augie Fackler - Oct. 21, 2019, 7:57 p.m.
On Mon, Oct 21, 2019 at 10:40:24PM +0900, Yuya Nishihara wrote:
> On Mon, 21 Oct 2019 12:00:53 +0200, Denis Laxalde wrote:
> > # HG changeset patch
> > # User Denis Laxalde <denis@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
>
> > @@ -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"))
>
> Maybe better to use _strpath() for paths.

I agree. Denis, can we get a v2 with that changed?

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

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):