From 10b38fe6b4433e7695a2e2ab5d67fd814221126a Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 22 May 2019 21:52:52 +0200 Subject: [PATCH] test: specify subprocess encoding to be UTF-8 One of the most important and user-visible changes in Python 3 was that when reading strings from some , one always needs to specify the encoding lest the dreaded UnicodeException would occur if there were any characters outside of the ASCII range. In the test suite, we're using a subprocess taht communicates with the shell, but we do not specify the encoding of both its stdout and stderr previous to reading them. Explicitly decode both their output and error streams to UTF-8 to avoid any exceptions raised by Python 3. --- test/zziptests.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/zziptests.py b/test/zziptests.py index 9e814bf..b065b61 100644 --- a/test/zziptests.py +++ b/test/zziptests.py @@ -79,7 +79,9 @@ def shell(command, shell=True, calls=False, cwd=None, env=None, lang=None, retur stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=None, env=env) if run.returncode: logg.warning("EXIT %s: %s", run.returncode, command) - output, errors = run.communicate() # run.wait() + output, errors = run.communicate() + output = output.decode('utf-8') + errors = errors.decode('utf-8') except: logg.error("*E*: %s", sh_command) for line in output.split("\n"): @@ -150,7 +152,7 @@ def download(base_url, filename, into, style = ""): def output(cmd, shell=True): run = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE) out, err = run.communicate() - return out + return out.decode('utf-8') def grep(pattern, lines): if isinstance(lines, basestring): lines = lines.split("\n") -- 2.40.0