From e2e4f44534a73ed6ee658aa8b1ccd76cbf5ec437 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Fri, 16 Apr 2021 17:15:09 -0400 Subject: [PATCH] Add test_openpty from CPython 3.8 --- Lib/test/test_openpty.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Lib/test/test_openpty.py diff --git a/Lib/test/test_openpty.py b/Lib/test/test_openpty.py new file mode 100644 index 000000000..3f46a6040 --- /dev/null +++ b/Lib/test/test_openpty.py @@ -0,0 +1,21 @@ +# Test to see if openpty works. (But don't worry if it isn't available.) + +import os, unittest + +if not hasattr(os, "openpty"): + raise unittest.SkipTest("os.openpty() not available.") + + +class OpenptyTest(unittest.TestCase): + def test(self): + master, slave = os.openpty() + self.addCleanup(os.close, master) + self.addCleanup(os.close, slave) + if not os.isatty(slave): + self.fail("Slave-end of pty is not a terminal.") + + os.write(slave, b'Ping!') + self.assertEqual(os.read(master, 1024), b'Ping!') + +if __name__ == '__main__': + unittest.main()