]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154525: Skip ncurses find_pair()/alloc_pair() reuse checks before 6.3 (GH-154543)
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 23 Jul 2026 15:37:43 +0000 (18:37 +0300)
committerGitHub <noreply@github.com>
Thu, 23 Jul 2026 15:37:43 +0000 (15:37 +0000)
find_pair() and reuse in alloc_pair() were fixed in ncurses 6.3 (patch
20200411).  On earlier versions find_pair() returns -1 and alloc_pair()
allocates a fresh pair instead of reusing an equal one, so
test_dynamic_color_pairs failed on ncurses 6.1 and 6.2.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Lib/test/test_curses.py

index 4ca5dd73f55afee78c8411a4de18976f2030362f..8aecb1e3a7a42d5b5982e11d907195cd78bcaf50 100644 (file)
@@ -1997,12 +1997,15 @@ class TestCurses(unittest.TestCase):
         pair = curses.alloc_pair(fg, bg)
         self.assertGreater(pair, 0)
         self.assertEqual(curses.pair_content(pair), (fg, bg))
-        # The same combination of colors reuses the same pair.
-        self.assertEqual(curses.alloc_pair(fg, bg), pair)
-        self.assertEqual(curses.find_pair(fg, bg), pair)
-        # Once freed, the pair is no longer found.
-        self.assertIsNone(curses.free_pair(pair))
-        self.assertEqual(curses.find_pair(fg, bg), -1)
+        if getattr(curses, 'ncurses_version', (6, 3)) >= (6, 3):
+            # The same combination of colors reuses the same pair.
+            self.assertEqual(curses.alloc_pair(fg, bg), pair)
+            self.assertEqual(curses.find_pair(fg, bg), pair)
+            # Once freed, the pair is no longer found.
+            self.assertIsNone(curses.free_pair(pair))
+            self.assertEqual(curses.find_pair(fg, bg), -1)
+        else:
+            self.assertIsNone(curses.free_pair(pair))
 
         # Error paths.
         for color in self.bad_colors2():