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