Skip to content

Commit 64fab74

Browse files
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). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 93b9e76 commit 64fab74

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
@@ -377,10 +377,12 @@ def test_pad(self):
377377
pad.addstr(0, 0, 'PADTEXT')
378378
self.assertEqual(pad.instr(0, 0, 7), b'PADTEXT')
379379

380-
# subpad() shares the parent pad's character cells.
380+
# subpad() creates a pad within the parent pad. Cell sharing with
381+
# the parent is implementation-defined, so write to the subpad itself.
381382
sub = pad.subpad(3, 5, 0, 0)
382383
self.assertEqual(sub.getmaxyx(), (3, 5))
383-
self.assertEqual(sub.instr(0, 0, 5), b'PADTE')
384+
sub.addstr(1, 0, 'sub')
385+
self.assertEqual(sub.instr(1, 0, 3), b'sub')
384386

385387
# A pad is refreshed onto an explicit screen rectangle; the
386388
# 6-argument form is required (and rejected for ordinary windows).
@@ -414,7 +416,8 @@ def test_coordinate_errors(self):
414416
self.assertRaises(curses.error, win.move, -1, -1)
415417
self.assertRaises(curses.error, win.addch, 100, 100, ord('x'))
416418
self.assertRaises(curses.error, win.inch, 100, 100)
417-
self.assertRaises(curses.error, win.chgat, 100, 0, curses.A_BOLD)
419+
if hasattr(win, 'chgat'): # chgat() requires wchgat()
420+
self.assertRaises(curses.error, win.chgat, 100, 0, curses.A_BOLD)
418421

419422
def test_argument_errors(self):
420423
win = curses.newwin(5, 10, 0, 0)

0 commit comments

Comments
 (0)