Patchwork tests: avoid implicit conversion of str to unicode

login
register
mail settings
Submitter Manuel Jacob
Date March 6, 2020, 9:36 a.m.
Message ID <b450d641c374112d9c91.1583487389@tmp>
Download mbox | patch
Permalink /patch/45536/
State Accepted
Headers show

Comments

Manuel Jacob - March 6, 2020, 9:36 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1583428761 -3600
#      Thu Mar 05 18:19:21 2020 +0100
# Node ID b450d641c374112d9c9179a9009d15e94d45ed86
# Parent  14e2295705434054ed9c697143bb7207ebd1777d
# EXP-Topic remove-implicit-str-conversions
tests: avoid implicit conversion of str to unicode

On Python 2, str.encode('ascii') implicitly converts the string to unicode and
then back to str.

Since the converted value is a path, _bytespath can be used instead.
Yuya Nishihara - March 6, 2020, 2:46 p.m.
On Fri, 06 Mar 2020 10:36:29 +0100, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1583428761 -3600
> #      Thu Mar 05 18:19:21 2020 +0100
> # Node ID b450d641c374112d9c9179a9009d15e94d45ed86
> # Parent  14e2295705434054ed9c697143bb7207ebd1777d
> # EXP-Topic remove-implicit-str-conversions
> tests: avoid implicit conversion of str to unicode

Queued, thanks.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -3008,7 +3008,7 @@ 
             os.makedirs(self._tmpbindir)
 
             normbin = os.path.normpath(os.path.abspath(whg))
-            normbin = normbin.replace(os.sep.encode('ascii'), b'/')
+            normbin = normbin.replace(_bytespath(os.sep), b'/')
 
             # Other Python scripts in the test harness need to
             # `import mercurial`. If `hg` is a Python script, we assume