blob: d128f61eb7764f4751b59987305ac9dc766bf925 [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 Peterson888a39b2009-03-26 20:48:25 +00004from test.test_support import run_unittest, SkipTest
Guido van Rossuma0f7e852000-07-01 01:13:31 +00005
Georg Brandl7d000992006-10-29 21:54:18 +00006if not hasattr(os, "openpty"):
Benjamin Peterson888a39b2009-03-26 20:48:25 +00007 raise 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()
Georg Brandlcd972082006-10-29 20:31:17 +000013 if not os.isatty(slave):
14 self.fail("Slave-end of pty is not a terminal.")
Guido van Rossuma0f7e852000-07-01 01:13:31 +000015
Georg Brandlcd972082006-10-29 20:31:17 +000016 os.write(slave, 'Ping!')
17 self.assertEqual(os.read(master, 1024), 'Ping!')
18
19def test_main():
20 run_unittest(OpenptyTest)
21
22if __name__ == '__main__':
23 test_main()