test_openpty.py 600 B

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