https://github.com/python/cpython/commit/0f2eb5a36280fc88cb031ebaa441e5b717660eb8
commit: 0f2eb5a36280fc88cb031ebaa441e5b717660eb8
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-10-18T18:51:35+03:00
summary:

gh-159394: Fix test_curses when $LINES or $COLUMNS is set (GH-159665)

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) <[email protected]>

files:
M Lib/test/test_curses.py

diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py
index 7fce9ab8646821..ec64ce52dd9e8c 100644
--- a/Lib/test/test_curses.py
+++ b/Lib/test/test_curses.py
@@ -3275,6 +3275,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(os_helper.EnvironmentVarGuard())
+        env['LINES'] = '24'
+        env['COLUMNS'] = '80'
 
     def tearDown(self):
         # Leave visual mode and reclaim the test's screens while their
@@ -3341,6 +3346,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 os_helper.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()

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to