Patchwork [1,of,3] py3: ensure run-tests.osenvironb is actually bytes

login
register
mail settings
Submitter Matt Harbison
Date Sept. 15, 2018, 4:31 a.m.
Message ID <bae09abf6ea2f721c78f.1536985895@Envy>
Download mbox | patch
Permalink /patch/34687/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 15, 2018, 4:31 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1536980255 14400
#      Fri Sep 14 22:57:35 2018 -0400
# Node ID bae09abf6ea2f721c78f11a21dd8db9cc8198378
# Parent  bafe274973423eaa7a49f2f2003366fddbdaca61
py3: ensure run-tests.osenvironb is actually bytes

Windows doesn't have os.environb, so it was falling back to the Unicode form,
and all of the accesses are trying to use bytes.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -86,8 +86,6 @@  if os.environ.get('RTUNICODEPEDANTRY', F
     except NameError:
         pass
 
-origenviron = os.environ.copy()
-osenvironb = getattr(os, 'environb', os.environ)
 processlock = threading.Lock()
 
 pygmentspresent = False
@@ -141,6 +139,8 @@  if pygmentspresent:
     runnerformatter = formatters.Terminal256Formatter(style=TestRunnerStyle)
     runnerlexer = TestRunnerLexer()
 
+origenviron = os.environ.copy()
+
 if sys.version_info > (3, 5, 0):
     PYTHON3 = True
     xrange = range # we use xrange in one place, and we'd rather not use range
@@ -154,6 +154,13 @@  if sys.version_info > (3, 5, 0):
             return p
         return p.decode('utf-8')
 
+    osenvironb = getattr(os, 'environb', None)
+    if osenvironb == None:
+        # Windows lacks os.environb, for instance.
+        osenvironb = {
+            _bytespath(k) : _bytespath(v) for k, v in os.environ.items()
+        }
+
 elif sys.version_info >= (3, 0, 0):
     print('%s is only supported on Python 3.5+ and 2.7, not %s' %
           (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3])))
@@ -169,6 +176,7 @@  else:
         return p
 
     _strpath = _bytespath
+    osenvironb = os.environ
 
 # For Windows support
 wifexited = getattr(os, "WIFEXITED", lambda x: False)