diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2023-10-10 14:27:22 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-10 14:27:22 (GMT) |
| commit | 3788c48d1227a9a6176e461c1bf6975c60afe5cf (patch) | |
| tree | 2cb4575b38f027c75d913b934d2edcf79fec4f56 | |
| parent | f72b18d146739e4a358499e621ef41f50fa2680a (diff) | |
| download | cpython-3788c48d1227a9a6176e461c1bf6975c60afe5cf.zip cpython-3788c48d1227a9a6176e461c1bf6975c60afe5cf.tar.gz cpython-3788c48d1227a9a6176e461c1bf6975c60afe5cf.tar.bz2 | |
[3.11] gh-110388: Add tests for tty (GH-110394) (GH-110634)
(cherry picked from commit 7f702b2)
| -rw-r--r-- | Lib/test/test_tty.py | 60 | ||||
| -rw-r--r-- | Misc/NEWS.d/next/Tests/2023-10-05-14-22-48.gh-issue-110388.1-HQJO.rst | 1 |
2 files changed, 61 insertions, 0 deletions
diff --git a/Lib/test/test_tty.py b/Lib/test/test_tty.py new file mode 100644 index 0000000..ec1f340 --- /dev/null +++ b/Lib/test/test_tty.py @@ -0,0 +1,60 @@ +import os +import unittest +from test.support.import_helper import import_module + +termios = import_module('termios') +tty = import_module('tty') + + +@unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()") +class TestTty(unittest.TestCase): + + def setUp(self): + master_fd, self.fd = os.openpty() + self.addCleanup(os.close, master_fd) + self.stream = self.enterContext(open(self.fd, 'wb', buffering=0)) + self.fd = self.stream.fileno() + self.mode = termios.tcgetattr(self.fd) + self.addCleanup(termios.tcsetattr, self.fd, termios.TCSANOW, self.mode) + self.addCleanup(termios.tcsetattr, self.fd, termios.TCSAFLUSH, self.mode) + + def check_cbreak(self, mode): + self.assertEqual(mode[3] & termios.ECHO, 0) + self.assertEqual(mode[3] & termios.ICANON, 0) + self.assertEqual(mode[6][termios.VMIN], 1) + self.assertEqual(mode[6][termios.VTIME], 0) + + def check_raw(self, mode): + self.assertEqual(mode[0] & termios.ICRNL, 0) + self.check_cbreak(mode) + self.assertEqual(mode[0] & termios.ISTRIP, 0) + self.assertEqual(mode[0] & termios.ICRNL, 0) + self.assertEqual(mode[1] & termios.OPOST, 0) + self.assertEqual(mode[2] & termios.PARENB, termios.CS8 & termios.PARENB) + self.assertEqual(mode[2] & termios.CSIZE, termios.CS8 & termios.CSIZE) + self.assertEqual(mode[2] & termios.CS8, termios.CS8) + self.assertEqual(mode[3] & termios.ECHO, 0) + self.assertEqual(mode[3] & termios.ICANON, 0) + self.assertEqual(mode[3] & termios.ISIG, 0) + self.assertEqual(mode[6][termios.VMIN], 1) + self.assertEqual(mode[6][termios.VTIME], 0) + + def test_setraw(self): + tty.setraw(self.fd) + mode = termios.tcgetattr(self.fd) + self.check_raw(mode) + tty.setraw(self.fd, termios.TCSANOW) + tty.setraw(self.stream) + tty.setraw(fd=self.fd, when=termios.TCSANOW) + + def test_setcbreak(self): + tty.setcbreak(self.fd) + mode = termios.tcgetattr(self.fd) + self.check_cbreak(mode) + tty.setcbreak(self.fd, termios.TCSANOW) + tty.setcbreak(self.stream) + tty.setcbreak(fd=self.fd, when=termios.TCSANOW) + + +if __name__ == '__main__': + unittest.main() diff --git a/Misc/NEWS.d/next/Tests/2023-10-05-14-22-48.gh-issue-110388.1-HQJO.rst b/Misc/NEWS.d/next/Tests/2023-10-05-14-22-48.gh-issue-110388.1-HQJO.rst new file mode 100644 index 0000000..caac41f --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-10-05-14-22-48.gh-issue-110388.1-HQJO.rst @@ -0,0 +1 @@ +Add tests for :mod:`tty`. |
