py3: ensure run-tests.osenvironb is actually bytes
authorMatt Harbison <matt_harbison@yahoo.com>
Fri, 14 Sep 2018 22:57:35 -0400
changeset 39645 13179f97f697
parent 39644 3b421154d2ca
child 39646 f3d1229555d9
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.
tests/run-tests.py
--- a/tests/run-tests.py	Thu Sep 13 22:07:00 2018 -0400
+++ b/tests/run-tests.py	Fri Sep 14 22:57:35 2018 -0400
@@ -86,8 +86,6 @@
     except NameError:
         pass
 
-origenviron = os.environ.copy()
-osenvironb = getattr(os, 'environb', os.environ)
 processlock = threading.Lock()
 
 pygmentspresent = False
@@ -141,6 +139,8 @@
     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 @@
             return p
         return p.decode('utf-8')
 
+    osenvironb = getattr(os, 'environb', None)
+    if osenvironb is 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 @@
         return p
 
     _strpath = _bytespath
+    osenvironb = os.environ
 
 # For Windows support
 wifexited = getattr(os, "WIFEXITED", lambda x: False)