blob: 3f46a604025de24c4b9026a5c99d3a33754e3b63 [file] [log] [blame]
Guido van Rossuma0f7e852000-07-01 01:13:31 +00001# Test to see if openpty works. (But don't worry if it isn't available.)
2
Thomas Wouters89f507f2006-12-13 04:49:30 +00003import os, unittest
Guido van Rossuma0f7e852000-07-01 01:13:31 +00004
Thomas Wouters89f507f2006-12-13 04:49:30 +00005if not hasattr(os, "openpty"):
Brett Cannoncd8efa32012-11-14 15:16:53 -05006 raise unittest.SkipTest("os.openpty() not available.")
Guido van Rossuma0f7e852000-07-01 01:13:31 +00007
Guido van Rossuma0f7e852000-07-01 01:13:31 +00008
Thomas Wouters89f507f2006-12-13 04:49:30 +00009class OpenptyTest(unittest.TestCase):
10 def test(self):
11 master, slave = os.openpty()
Richard Oudkerk0e547b62013-06-10 16:29:19 +010012 self.addCleanup(os.close, master)
13 self.addCleanup(os.close, slave)
Thomas Wouters89f507f2006-12-13 04:49:30 +000014 if not os.isatty(slave):
15 self.fail("Slave-end of pty is not a terminal.")
16
Guido van Rossumdc089b62007-05-30 00:58:53 +000017 os.write(slave, b'Ping!')
18 self.assertEqual(os.read(master, 1024), b'Ping!')
Thomas Wouters89f507f2006-12-13 04:49:30 +000019
Thomas Wouters89f507f2006-12-13 04:49:30 +000020if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050021 unittest.main()