From bfe9026258739c1e4268af2014519d611dcc19ef Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 18 Oct 2026 12:56:01 +0300 Subject: [PATCH] gh-159394: Fix test_curses when $LINES or $COLUMNS is set The newterm() tests now set the size of the screen explicitly, instead of depending on the environment. Add a test for $LINES and $COLUMNS. Co-Authored-By: Claude Opus 5.5 (1M context) --- Lib/test/test_curses.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index 5db44ebedd2ee0..0d1457e56b28db 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -14,6 +14,7 @@ check_disallow_instantiation, MISSING_C_DOCSTRINGS, gc_collect, SHORT_TIMEOUT) from test.support.import_helper import import_module +from test.support.os_helper import EnvironmentVarGuard # Optionally test curses module. This currently requires that the # 'curses' resource be given on the regrtest command line using the -u @@ -3271,6 +3272,11 @@ def setUp(self): self.save_signals = SaveSignals() self.save_signals.save() self.addCleanup(self.save_signals.restore) + # A new pseudo-terminal has no size, so newterm() takes it from + # $LINES and $COLUMNS, or from the terminfo entry if they are unset. + env = self.enterContext(EnvironmentVarGuard()) + env['LINES'] = '24' + env['COLUMNS'] = '80' def tearDown(self): # Leave visual mode and reclaim the test's screens while their @@ -3337,6 +3343,26 @@ def test_newterm(self): win.addstr(0, 0, 'hello') win.refresh() + def test_lines_columns_env(self): + # $LINES and $COLUMNS override the size from the terminfo entry + # (24x80 for xterm). + for lines, columns, size in [('30', '100', (30, 100)), + ('30', None, (30, 80)), + (None, '100', (24, 100)), + (None, None, (24, 80))]: + with self.subTest(lines=lines, columns=columns): + with EnvironmentVarGuard() as env: + for name, value in [('LINES', lines), + ('COLUMNS', columns)]: + if value is None: + env.unset(name) + else: + env[name] = value + s = self.make_pty() + screen = curses.newterm('xterm', s, s) + self.assertEqual(screen.stdscr.getmaxyx(), size) + self.assertEqual((curses.LINES, curses.COLS), size) + def test_newterm_file_object(self): # type=None uses $TERM; the file arguments accept file objects too. s = self.make_pty()