def test_fd_tee_output(capsys): expected_lines = { "captured stdout", "captured stderr", "stdout from C", "and this is from echo" } capture_mode, capture_stdout = get_stdcapturer("fd") output = "" with capsys.disabled(): print('before (stdout)') print('before (stderr)') with capture_stdout() as out: print("captured stdout") print("captured stderr") output += out.get() libc.puts(b'stdout from C') libc.fflush(None) os.system('echo and this is from echo') output += out.get() output += out.get() print('after (stdout)') print('after (stderr)') assert set(output.strip().split("\n")) == expected_lines
def test_fd_tee_output(capsys): expected_lines = { "captured stdout", "captured stderr", "stdout from C", "and this is from echo"} capture_mode, capture_stdout = get_stdcapturer("fd") output = "" with capsys.disabled(): print('before (stdout)') print('before (stderr)') with capture_stdout() as out: print("captured stdout") print("captured stderr", file=sys.stderr) output += out.get() libc.puts(b'stdout from C') libc.fflush(None) os.system('echo and this is from echo') output += out.get() output += out.get() print('after (stdout)') print('after (stderr)') assert set(output.strip().split("\n")) == expected_lines
def test_tee_output(capsys): from sacred.optional import libc expected_lines = { "captured stdout\n", "captured stderr\n", "and this is from echo\n" } if not sys.platform.startswith('win'): # FIXME: this line randomly doesn't show on windows (skip for now) expected_lines.add("stdout from C\n") with capsys.disabled(): try: print('before (stdout)') print('before (stderr)') with tempfile.NamedTemporaryFile(delete=False) as f, tee_output(f): print("captured stdout") print("captured stderr") if not sys.platform.startswith('win'): libc.puts(b'stdout from C') libc.fflush(None) os.system('echo and this is from echo') print('after (stdout)') print('after (stderr)') with open(f.name, 'r') as f: lines = set(f.readlines()) assert lines == expected_lines finally: print('deleting', f.name) os.remove(f.name)
def test_fd_tee_output(capsys): expected_lines = { "captured stdout", "captured stderr", "stdout from C", "and this is from echo", "keep\rcarriage\rreturns", } capture_mode, capture_stdout = get_stdcapturer("fd") output = "" with capsys.disabled(): print("before (stdout)") print("before (stderr)") with capture_stdout() as out: print("captured stdout") print("captured stderr", file=sys.stderr) print("keep\rcarriage\rreturns") output += out.get() libc.puts(b"stdout from C") libc.fflush(None) os.system("echo and this is from echo") output += out.get() output += out.get() print("after (stdout)") print("after (stderr)") assert set(output.strip().split("\n")) == expected_lines
def flush(): """Try to flush all stdio buffers, both from python and from C.""" try: sys.stdout.flush() sys.stderr.flush() except (AttributeError, ValueError, IOError): pass # unsupported try: libc.fflush(None) except (AttributeError, ValueError, IOError): pass # unsupported
def flush(): """Try to flush all stdio buffers, both from python and from C.""" try: sys.stdout.flush() sys.stderr.flush() except (AttributeError, ValueError, IOError): pass # unsupported try: libc.fflush(None) except (AttributeError, ValueError, IOError): pass # unsupported