test_openpty.py 600 Bytes
Newer Older
1 2
# Test to see if openpty works. (But don't worry if it isn't available.)

3
import os, unittest
4

5
if not hasattr(os, "openpty"):
6
    raise unittest.SkipTest("os.openpty() not available.")
7 8


9 10 11
class OpenptyTest(unittest.TestCase):
    def test(self):
        master, slave = os.openpty()
12 13
        self.addCleanup(os.close, master)
        self.addCleanup(os.close, slave)
14 15 16
        if not os.isatty(slave):
            self.fail("Slave-end of pty is not a terminal.")

Guido van Rossum's avatar
Guido van Rossum committed
17 18
        os.write(slave, b'Ping!')
        self.assertEqual(os.read(master, 1024), b'Ping!')
19 20

if __name__ == '__main__':
21
    unittest.main()