Fix encoding environment variables for subprocess.Popen in Python helpers tests

It turned out six.b is intended only as a substitute for b'' literals,
it doesn't encode unicode values in Python 2. Moreover, on Python 3
subprocess requires all env values to be unicode, so it also broke
tests for Python 3.

GitOrigin-RevId: 4243a9436f4aa88eb53d2da8bfa18d9b21a22262
This commit is contained in:
Mikhail Golubev
2022-06-23 18:13:15 +03:00
committed by intellij-monorepo-bot
parent fca0fdd85d
commit 48e7bade83

View File

@@ -152,8 +152,15 @@ class FunctionalGeneratorTestCase(GeneratorTestCase):
def run_process(self, args, input=None, env=None):
# Remove possible (NAME: None) pairs and make sure that environment content is
# encoded (critical for Python 2.x on Windows)
env = {six.b(k): six.b(v) for k, v in env.items() if v is not None}
# all str (critical for Python 2.x on Windows)
def as_str(s):
if isinstance(s, str):
return s
elif six.PY2:
return s.encode(encoding='latin-1')
else:
return s.decode(encoding='latin-1')
env = {as_str(k): as_str(v) for k, v in env.items() if v is not None}
process = subprocess.Popen(args,
env=env,
stdin=subprocess.PIPE,