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 | |
Georg Brandl | cd97208 | 2006-10-29 20:31:17 +0000 | [diff] [blame] | 3 | import os, unittest |
Benjamin Peterson | bec087f | 2009-03-26 21:10:30 +0000 | [diff] [blame] | 4 | from test.test_support import run_unittest |
Guido van Rossum | a0f7e85 | 2000-07-01 01:13:31 +0000 | [diff] [blame] | 5 | |
Georg Brandl | 7d00099 | 2006-10-29 21:54:18 +0000 | [diff] [blame] | 6 | if not hasattr(os, "openpty"): |
Benjamin Peterson | bec087f | 2009-03-26 21:10:30 +0000 | [diff] [blame] | 7 | raise unittest.SkipTest, "No openpty() available." |
Georg Brandl | 7d00099 | 2006-10-29 21:54:18 +0000 | [diff] [blame] | 8 | |
| 9 | |
Georg Brandl | cd97208 | 2006-10-29 20:31:17 +0000 | [diff] [blame] | 10 | class OpenptyTest(unittest.TestCase): |
| 11 | def test(self): |
Georg Brandl | 7d00099 | 2006-10-29 21:54:18 +0000 | [diff] [blame] | 12 | master, slave = os.openpty() |
Richard Oudkerk | 045e457 | 2013-06-10 16:27:45 +0100 | [diff] [blame^] | 13 | self.addCleanup(os.close, master) |
| 14 | self.addCleanup(os.close, slave) |
Georg Brandl | cd97208 | 2006-10-29 20:31:17 +0000 | [diff] [blame] | 15 | if not os.isatty(slave): |
| 16 | self.fail("Slave-end of pty is not a terminal.") |
Guido van Rossum | a0f7e85 | 2000-07-01 01:13:31 +0000 | [diff] [blame] | 17 | |
Georg Brandl | cd97208 | 2006-10-29 20:31:17 +0000 | [diff] [blame] | 18 | os.write(slave, 'Ping!') |
| 19 | self.assertEqual(os.read(master, 1024), 'Ping!') |
| 20 | |
| 21 | def test_main(): |
| 22 | run_unittest(OpenptyTest) |
| 23 | |
| 24 | if __name__ == '__main__': |
| 25 | test_main() |