1# Test to see if openpty works. (But don't worry if it isn't available.) 2 3import os, unittest 4 5if not hasattr(os, "openpty"): 6 raise unittest.SkipTest("os.openpty() not available.") 7 8 9class OpenptyTest(unittest.TestCase): 10 def test(self): 11 master, slave = os.openpty() 12 self.addCleanup(os.close, master) 13 self.addCleanup(os.close, slave) 14 if not os.isatty(slave): 15 self.fail("Slave-end of pty is not a terminal.") 16 17 os.write(slave, b'Ping!') 18 self.assertEqual(os.read(master, 1024), b'Ping!') 19 20if __name__ == '__main__': 21 unittest.main() 22