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

3
import os, unittest
Benjamin Peterson's avatar
Benjamin Peterson committed
4
from test.support import run_unittest
5

6
if not hasattr(os, "openpty"):
Benjamin Peterson's avatar
Benjamin Peterson committed
7
    raise unittest.SkipTest("No openpty() available.")
8 9


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

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

def test_main():
    run_unittest(OpenptyTest)

if __name__ == '__main__':
    test_main()