From 1dbdb4691a9fc1286ca7811685d864615121a827 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 26 Jun 2026 18:21:44 +0300 Subject: [PATCH] gh-151776: Fix test_state_getters on terminals without insert/delete capability 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 27a64532b21fd85..6f8a56f1d0de6bb 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -1330,8 +1330,6 @@ def test_state_getters(self): # 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'), @@ -1342,6 +1340,19 @@ def test_state_getters(self): 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)