Skip to content

Commit bfe005e

Browse files
[3.14] gh-151693: Make the curses tests portable to other curses implementations (GH-151729)
Make the curses tests portable to other curses implementations Guard the chgat() check (chgat() needs wchgat()) and stop assuming a subpad shares the parent pad's cells (implementation-defined in X/Open). (cherry picked from commit 64fab74) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 971fd70 commit bfe005e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Lib/test/test_curses.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,12 @@ def test_pad(self):
374374
pad.addstr(0, 0, 'PADTEXT')
375375
self.assertEqual(pad.instr(0, 0, 7), b'PADTEXT')
376376

377-
# subpad() shares the parent pad's character cells.
377+
# subpad() creates a pad within the parent pad. Cell sharing with
378+
# the parent is implementation-defined, so write to the subpad itself.
378379
sub = pad.subpad(3, 5, 0, 0)
379380
self.assertEqual(sub.getmaxyx(), (3, 5))
380-
self.assertEqual(sub.instr(0, 0, 5), b'PADTE')
381+
sub.addstr(1, 0, 'sub')
382+
self.assertEqual(sub.instr(1, 0, 3), b'sub')
381383

382384
# A pad is refreshed onto an explicit screen rectangle; the
383385
# 6-argument form is required (and rejected for ordinary windows).
@@ -410,7 +412,8 @@ def test_coordinate_errors(self):
410412
self.assertRaises(curses.error, win.move, 100, 100)
411413
self.assertRaises(curses.error, win.move, -1, -1)
412414
self.assertRaises(curses.error, win.addch, 100, 100, ord('x'))
413-
self.assertRaises(curses.error, win.chgat, 100, 0, curses.A_BOLD)
415+
if hasattr(win, 'chgat'): # chgat() requires wchgat()
416+
self.assertRaises(curses.error, win.chgat, 100, 0, curses.A_BOLD)
414417

415418
def test_argument_errors(self):
416419
win = curses.newwin(5, 10, 0, 0)

0 commit comments

Comments
 (0)