diff --git a/test/test.py b/test/test.py index 0258c3a..1399995 100644 --- a/test/test.py +++ b/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 # ------------------------------------------------------------------------------