/Lib/test/test_openpty.py

http://unladen-swallow.googlecode.com/ · Python · 23 lines · 15 code · 7 blank · 1 comment · 3 complexity · 2f93d2c9c468b99c84c5d3cdef1a37ea MD5 · raw file

  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, TestSkipped
  4. if not hasattr(os, "openpty"):
  5. raise TestSkipped, "No openpty() available."
  6. class OpenptyTest(unittest.TestCase):
  7. def test(self):
  8. master, slave = os.openpty()
  9. if not os.isatty(slave):
  10. self.fail("Slave-end of pty is not a terminal.")
  11. os.write(slave, 'Ping!')
  12. self.assertEqual(os.read(master, 1024), 'Ping!')
  13. def test_main():
  14. run_unittest(OpenptyTest)
  15. if __name__ == '__main__':
  16. test_main()