From 1da4cc357d37e2284f20e5b1c82d84f3b2903483 Mon Sep 17 00:00:00 2001 From: Omri Bahumi Date: Mon, 4 May 2015 14:24:37 +0300 Subject: [PATCH 1/2] Add test_stdout_file --- test.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test.py b/test.py index f5dc23be..069787ee 100644 --- a/test.py +++ b/test.py @@ -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 From 75bbf90db2e65e3f138af5504b46b3d8a69d3ed7 Mon Sep 17 00:00:00 2001 From: Omri Bahumi Date: Mon, 4 May 2015 14:26:16 +0300 Subject: [PATCH 2/2] Fix test_stdout_file --- sh.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sh.py b/sh.py index fb0f5fe7..06c34357 100644 --- a/sh.py +++ b/sh.py @@ -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):