From 761cd9eaf8e7287afe4dc9d015ef60d6304ceb0f Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 29 Mar 2018 13:03:08 +0545 Subject: [PATCH] tests: import tty_create_child_test.py. --- tests/tty_create_child_test.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/tty_create_child_test.py diff --git a/tests/tty_create_child_test.py b/tests/tty_create_child_test.py new file mode 100644 index 00000000..dca1d375 --- /dev/null +++ b/tests/tty_create_child_test.py @@ -0,0 +1,34 @@ + +import os +import tempfile +import time +import unittest2 + +import mitogen.parent + + +class TtyCreateChildTest(unittest2.TestCase): + func = staticmethod(mitogen.parent.tty_create_child) + + def test_dev_tty_open_succeeds(self): + import logging + logging.basicConfig(level=logging.DEBUG) + tf = tempfile.NamedTemporaryFile() + try: + pid, fd = self.func( + 'bash', '-c', 'exec 2>%s; echo hi > /dev/tty' % (tf.name,) + ) + # TODO: this waitpid hangs on OS X. Installing a SIGCHLD handler + # reveals the parent /is/ notified of the child's death, but + # calling waitpid() from within SIGCHLD yields "No such processes". + # Meanwhile, even inserting a sleep, the following call will hang. + waited_pid, status = os.waitpid(pid, 0) + self.assertEquals(pid, waited_pid) + self.assertEquals(0, status) + self.assertEquals('', tf.read()) + finally: + tf.close() + + +if __name__ == '__main__': + unittest2.main()