From bf61794fd2c293d79a81f3578fd3fc3f96dd341c Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 26 Jun 2026 18:50:30 +0300 Subject: [PATCH] gh-151776: Fix test_state_getters on terminals without insert/delete capability (GH-152304) idcok() and idlok() take effect only when the terminal can insert or delete characters or lines, so check their getters against the terminal's capabilities instead of asserting an unconditional round-trip. Co-authored-by: Claude Opus 4.8 --- Lib/test/test_curses.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index deadafc93074..ba259ae0d1ce 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -1359,8 +1359,6 @@ class TestCurses(unittest.TestCase): # Each is_*() getter returns the value set by the matching setter. for setter, getter in [ ('clearok', 'is_cleared'), - ('idcok', 'is_idcok'), - ('idlok', 'is_idlok'), ('keypad', 'is_keypad'), ('leaveok', 'is_leaveok'), ('nodelay', 'is_nodelay'), @@ -1371,6 +1369,19 @@ class TestCurses(unittest.TestCase): self.assertIs(getattr(stdscr, getter)(), True) getattr(stdscr, setter)(False) self.assertIs(getattr(stdscr, getter)(), False) + + # idcok()/idlok() only take effect if the terminal can insert/delete + # characters/lines, so the getter reflects that capability. + stdscr.idcok(True) + self.assertIs(stdscr.is_idcok(), curses.has_ic()) + stdscr.idcok(False) + self.assertIs(stdscr.is_idcok(), False) + + stdscr.idlok(True) + self.assertIs(stdscr.is_idlok(), + curses.has_il() or curses.tigetstr('csr') is not None) + stdscr.idlok(False) + self.assertIs(stdscr.is_idlok(), False) if hasattr(stdscr, 'immedok'): stdscr.immedok(True) self.assertIs(stdscr.is_immedok(), True) -- 2.47.3