Use universal newlines in test_bin.py

Change run_cmd() implementation in test_bin.py to use universal newlines (text mode) for Windows compatibility.
This commit is contained in:
gilch 2017-06-17 16:36:48 -06:00
parent 3a7618806e
commit aa08149712

View File

@ -23,9 +23,10 @@ def run_cmd(cmd, stdin_data=None, expect=0):
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True,
shell=True) shell=True)
if stdin_data is not None: if stdin_data is not None:
p.stdin.write(stdin_data.encode('ASCII')) p.stdin.write(stdin_data)
p.stdin.flush() p.stdin.flush()
p.stdin.close() p.stdin.close()
# Read stdout and stderr otherwise if the PIPE buffer is full, we might # Read stdout and stderr otherwise if the PIPE buffer is full, we might
@ -33,8 +34,8 @@ def run_cmd(cmd, stdin_data=None, expect=0):
stdout = "" stdout = ""
stderr = "" stderr = ""
while p.poll() is None: while p.poll() is None:
stdout += p.stdout.read().decode('utf-8') stdout += p.stdout.read()
stderr += p.stderr.read().decode('utf-8') stderr += p.stderr.read()
assert p.returncode == expect assert p.returncode == expect
return stdout, stderr return stdout, stderr