]> granicus.if.org Git - zziplib/commitdiff
test: specify subprocess encoding to be UTF-8
authorPatrick Steinhardt <ps@pks.im>
Wed, 22 May 2019 19:52:52 +0000 (21:52 +0200)
committerPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2019 06:35:33 +0000 (08:35 +0200)
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

index 9e814bf9c0b2b1b6c9f07d5431943c5ab9c0ce62..b065b61a53579316a9707fe32abf753f143f202d 100644 (file)
@@ -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")