https://github.com/python/cpython/commit/f37ebb26939f675f9a2413c9ef452e51020c0da2
commit: f37ebb26939f675f9a2413c9ef452e51020c0da2
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-10-10T23:01:19+03:00
summary:

[3.14] gh-159127: Fix tests depending on the layout of unmapped text widgets 
(GH-159128) (GH-159134)

A text widget which has not been mapped yet had size 1x1 and its content
was laid out in that area, putting every character on its own display
line.  Tk no longer does this.
(cherry picked from commit 5564790598b8bcc58c00df31a62ca56745961911)

Co-authored-by: Serhiy Storchaka <[email protected]>

files:
M Lib/idlelib/idle_test/test_codecontext.py
M Lib/idlelib/idle_test/test_sidebar.py
M Lib/test/test_tkinter/test_text.py

diff --git a/Lib/idlelib/idle_test/test_codecontext.py 
b/Lib/idlelib/idle_test/test_codecontext.py
index 3f070da022384ec..13465d5c98c4872 100644
--- a/Lib/idlelib/idle_test/test_codecontext.py
+++ b/Lib/idlelib/idle_test/test_codecontext.py
@@ -60,6 +60,8 @@ def setUpClass(cls):
         frame = cls.frame = Frame(root)
         text = cls.text = Text(frame)
         text.insert('1.0', code_sample)
+        # Make the text longer than the visible height, so that it can scroll.
+        text.insert('end', '\n' * (int(text['height']) + 2))
         # Need to pack for creation of code context text widget.
         frame.pack(side='left', fill='both', expand=1)
         text.grid(row=1, column=1, sticky=NSEW)
diff --git a/Lib/idlelib/idle_test/test_sidebar.py 
b/Lib/idlelib/idle_test/test_sidebar.py
index 848f12a5d7c1850..6901413c416afda 100644
--- a/Lib/idlelib/idle_test/test_sidebar.py
+++ b/Lib/idlelib/idle_test/test_sidebar.py
@@ -317,6 +317,10 @@ def test_drag_selection_up(self):
         self.assertEqual(self.get_selection(), ('2.0', '5.0'))
 
     def test_scroll(self):
+        # Synchronized scrolling needs the geometry of mapped widgets.
+        self.root.deiconify()
+        self.addCleanup(self.root.withdraw)
+
         self.linenumber.show_sidebar()
         self.text.insert('1.0', 'line\n' * 100)
         self.root.update()
diff --git a/Lib/test/test_tkinter/test_text.py 
b/Lib/test/test_tkinter/test_text.py
index acbee1acad633e4..d562547e6e9328b 100644
--- a/Lib/test/test_tkinter/test_text.py
+++ b/Lib/test/test_tkinter/test_text.py
@@ -656,10 +656,16 @@ def test_count(self):
         self.assertRaises(TclError, text.count, '1.0', 'end', 'spam')
         self.assertRaises(TclError, text.count, '1.0', 'end', '-lines')
 
-        self.assertIsInstance(text.count('1.3', '1.5', 'ypixels', 
return_ints=True), int)
-        self.assertIsInstance(text.count('1.3', '1.5', 'ypixels'), tuple)
-        self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels', 
return_ints=True), int)
-        self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels'), 
int)
+        # The ypixels counts depend on the widget geometry.
+        text.update()
+
+        # Indices on the same display line have zero vertical distance.
+        self.assertEqual(text.count('1.3', '1.5', 'ypixels', 
return_ints=True), 0)
+        self.assertIsNone(text.count('1.3', '1.5', 'ypixels'))
+        self.assertIsInstance(text.count('1.3', '2.5', 'ypixels', 
return_ints=True), int)
+        self.assertIsInstance(text.count('1.3', '2.5', 'ypixels'), tuple)
+        self.assertIsInstance(text.count('1.3', '2.5', 'update', 'ypixels', 
return_ints=True), int)
+        self.assertIsInstance(text.count('1.3', '2.5', 'update', 'ypixels'), 
int)
         self.assertEqual(text.count('1.3', '1.3', 'update', 'ypixels', 
return_ints=True), 0)
         self.assertEqual(text.count('1.3', '1.3', 'update', 'ypixels'), None)
         self.assertEqual(text.count('1.3', '1.5', 'update', 'indices', 
return_ints=True), 2)

_______________________________________________
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