# HG changeset patch # User Manuel Jacob # Date 2020-03-06 09:52:44 # Node ID ff72bd52d56a5a6517603803b09a7c9138012761 # Parent 55c443fcb4fcacecf9f70c3b9e462d611060a449 tests: avoid implicit conversion of str to unicode On Python 2, str.encode('utf-8') implicitly converts the string to unicode and then back to str. Using _sys2bytes() ensures that opt is only encoded on Python 3, where opt is unicode. Although contrived, before this change, a UnicodeDecodeError could be triggered on Python 2 when passing non-ascii values to --extra-config-opt. diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1331,7 +1331,7 @@ class Test(unittest.TestCase): extraextensions = [] for opt in self._extraconfigopts: - section, key = opt.encode('utf-8').split(b'.', 1) + section, key = _sys2bytes(opt).split(b'.', 1) if section != 'extensions': continue name = key.split(b'=', 1)[0] @@ -1432,7 +1432,7 @@ class Test(unittest.TestCase): hgrc.write(b'server-header = testing stub value\n') for opt in self._extraconfigopts: - section, key = opt.encode('utf-8').split(b'.', 1) + section, key = _sys2bytes(opt).split(b'.', 1) assert b'=' in key, ( 'extra config opt %s must ' 'have an = for assignment' % opt )