ihrasko: open stdout and stderr in text mode and avoid type errors in
Python 3 during tests
This commit is contained in:
parent
8587b26d0e
commit
d12cc0ac80
15
test/test.py
15
test/test.py
@ -46,9 +46,22 @@ def fetch_url(src, dst):
|
||||
|
||||
|
||||
def exe(command):
|
||||
"""
|
||||
Executes command and returns string representations of stdout and stderr captured from the console.
|
||||
When universal_newlines=True stdout and stderr are opened in text mode.
|
||||
Otherwise, they are opened in binary mode. In that case captured stdout and stderr
|
||||
are not strings and Python 3 throws type error when compared against strings later in tests.
|
||||
|
||||
Note:
|
||||
This feature is only available if Python is built with universal newline support (the default).
|
||||
Also, the newlines attribute of the file objects stdout, stdin and stderr are not updated by the
|
||||
communicate() method.
|
||||
See https://docs.python.org/2/library/subprocess.html
|
||||
"""
|
||||
stdout, stderr = subprocess.Popen(shlex.split(command),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE).communicate()
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True).communicate()
|
||||
return stdout, stderr
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user