Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test_stdout_file #252

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,9 @@ def finish():
if hasattr(handler, "flush"):
handler.flush()

if hasattr(handler, "close"):
handler.close()

return process, finish

def get_callback_chunk_consumer(handler, encoding, decode_errors):
Expand Down
24 changes: 24 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,30 @@ def test_output_equivalence(self):
self.assertEqual(iam1, iam2)


def test_stdout_file(self):
py = create_tmp_test(r"""
import sys

sys.stdout.write("foobar\n")
""")

read_fd, write_fd = os.pipe()
read, write = os.fdopen(read_fd, 'r'), os.fdopen(write_fd, 'w')
p = python(py.name, _out=write, u=True)
p.wait()

def alarm(sig, action):
self.fail("Timeout while reading from pipe")

import signal
signal.signal(signal.SIGALRM, alarm)
signal.alarm(3)

self.assertEqual("foobar\n", read.read(-1))
signal.alarm(0)
signal.signal(signal.SIGALRM, signal.SIG_DFL)


def test_stdout_callback(self):
py = create_tmp_test("""
import sys
Expand Down