Guido van Rossum | a0f7e85 | 2000-07-01 01:13:31 +0000 | [diff] [blame] | 1 | # Test to see if openpty works. (But don't worry if it isn't available.) |
| 2 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 3 | import os, unittest |
Guido van Rossum | a0f7e85 | 2000-07-01 01:13:31 +0000 | [diff] [blame] | 4 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 5 | if not hasattr(os, "openpty"): |
Brett Cannon | cd8efa3 | 2012-11-14 15:16:53 -0500 | [diff] [blame] | 6 | raise unittest.SkipTest("os.openpty() not available.") |
Guido van Rossum | a0f7e85 | 2000-07-01 01:13:31 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | a0f7e85 | 2000-07-01 01:13:31 +0000 | [diff] [blame] | 8 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 9 | class OpenptyTest(unittest.TestCase): |
| 10 | def test(self): |
| 11 | master, slave = os.openpty() |
Richard Oudkerk | 0e547b6 | 2013-06-10 16:29:19 +0100 | [diff] [blame] | 12 | self.addCleanup(os.close, master) |
| 13 | self.addCleanup(os.close, slave) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 14 | if not os.isatty(slave): |
| 15 | self.fail("Slave-end of pty is not a terminal.") |
| 16 | |
Guido van Rossum | dc089b6 | 2007-05-30 00:58:53 +0000 | [diff] [blame] | 17 | os.write(slave, b'Ping!') |
| 18 | self.assertEqual(os.read(master, 1024), b'Ping!') |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 19 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 20 | if __name__ == '__main__': |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 21 | unittest.main() |