Commit 3343a2e5 authored by Stefan Behnel's avatar Stefan Behnel

add helper for passing collected bytes output through to sys.stdout

parent f54826aa
......@@ -386,3 +386,12 @@ def captured_fd(stream=2, encoding=None):
t.join()
finally:
os.close(orig_stream)
def print_bytes(s, stream=sys.stdout):
stream.flush()
try:
out = stream.buffer # Py3
except AttributeError:
out = stream # Py2
out.write(s)
......@@ -867,7 +867,7 @@ class CythonCompileTestCase(unittest.TestCase):
so_path = None
if not self.cython_only:
from Cython.Utils import captured_fd
from Cython.Utils import captured_fd, print_bytes
get_stderr = None
try:
with captured_fd(2) as get_stderr:
......@@ -878,15 +878,10 @@ class CythonCompileTestCase(unittest.TestCase):
else:
raise
else:
c_compiler_stderr = get_stderr()
c_compiler_stderr = get_stderr().strip()
if c_compiler_stderr:
print("\n=== C/C++ compiler error output: ===")
sys.stdout.flush()
try:
out = sys.stdout.buffer # Py3
except AttributeError:
out = sys.stdout # Py2
out.write(c_compiler_stderr)
print_bytes(c_compiler_stderr)
if expected_errors == '_FAIL_C_COMPILE':
# must raise this outside the try block
raise RuntimeError('should have failed C compile')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment