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): ...@@ -386,3 +386,12 @@ def captured_fd(stream=2, encoding=None):
t.join() t.join()
finally: finally:
os.close(orig_stream) 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): ...@@ -867,7 +867,7 @@ class CythonCompileTestCase(unittest.TestCase):
so_path = None so_path = None
if not self.cython_only: if not self.cython_only:
from Cython.Utils import captured_fd from Cython.Utils import captured_fd, print_bytes
get_stderr = None get_stderr = None
try: try:
with captured_fd(2) as get_stderr: with captured_fd(2) as get_stderr:
...@@ -878,15 +878,10 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -878,15 +878,10 @@ class CythonCompileTestCase(unittest.TestCase):
else: else:
raise raise
else: else:
c_compiler_stderr = get_stderr() c_compiler_stderr = get_stderr().strip()
if c_compiler_stderr: if c_compiler_stderr:
print("\n=== C/C++ compiler error output: ===") print("\n=== C/C++ compiler error output: ===")
sys.stdout.flush() print_bytes(c_compiler_stderr)
try:
out = sys.stdout.buffer # Py3
except AttributeError:
out = sys.stdout # Py2
out.write(c_compiler_stderr)
if expected_errors == '_FAIL_C_COMPILE': if expected_errors == '_FAIL_C_COMPILE':
# must raise this outside the try block # must raise this outside the try block
raise RuntimeError('should have failed C compile') 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