blob: 4b34b3a3c779702fcbcae7462a88efd05dbc55b6 [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
Georg Brandlcd972082006-10-29 20:31:17 +00003import os, unittest
Benjamin Petersonbec087f2009-03-26 21:10:30 +00004from test.test_support import run_unittest
Guido van Rossuma0f7e852000-07-01 01:13:31 +00005
Georg Brandl7d000992006-10-29 21:54:18 +00006if not hasattr(os, "openpty"):
Benjamin Petersonbec087f2009-03-26 21:10:30 +00007 raise unittest.SkipTest, "No openpty() available."
Georg Brandl7d000992006-10-29 21:54:18 +00008
9
Georg Brandlcd972082006-10-29 20:31:17 +000010class OpenptyTest(unittest.TestCase):
11 def test(self):
Georg Brandl7d000992006-10-29 21:54:18 +000012 master, slave = os.openpty()
Richard Oudkerk045e4572013-06-10 16:27:45 +010013 self.addCleanup(os.close, master)
14 self.addCleanup(os.close, slave)
Georg Brandlcd972082006-10-29 20:31:17 +000015 if not os.isatty(slave):
16 self.fail("Slave-end of pty is not a terminal.")
Guido van Rossuma0f7e852000-07-01 01:13:31 +000017
Georg Brandlcd972082006-10-29 20:31:17 +000018 os.write(slave, 'Ping!')
19 self.assertEqual(os.read(master, 1024), 'Ping!')
20
21def test_main():
22 run_unittest(OpenptyTest)
23
24if __name__ == '__main__':
25 test_main()