blob: 8713d346719747f81cdce7ba1e180155656d86ca [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
Benjamin Petersone549ead2009-03-28 21:42:05 +00004from test.support import run_unittest
Guido van Rossuma0f7e852000-07-01 01:13:31 +00005
Thomas Wouters89f507f2006-12-13 04:49:30 +00006if not hasattr(os, "openpty"):
Brett Cannoncd8efa32012-11-14 15:16:53 -05007 raise unittest.SkipTest("os.openpty() not available.")
Guido van Rossuma0f7e852000-07-01 01:13:31 +00008
Guido van Rossuma0f7e852000-07-01 01:13:31 +00009
Thomas Wouters89f507f2006-12-13 04:49:30 +000010class OpenptyTest(unittest.TestCase):
11 def test(self):
12 master, slave = os.openpty()
13 if not os.isatty(slave):
14 self.fail("Slave-end of pty is not a terminal.")
15
Guido van Rossumdc089b62007-05-30 00:58:53 +000016 os.write(slave, b'Ping!')
17 self.assertEqual(os.read(master, 1024), b'Ping!')
Thomas Wouters89f507f2006-12-13 04:49:30 +000018
19def test_main():
20 run_unittest(OpenptyTest)
21
22if __name__ == '__main__':
23 test_main()