test_openpty.py 681 B

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