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