Skip to content

Commit 0d190e9

Browse files
[3.15] gh-159127: Fix tests depending on the layout of unmapped text widgets (GH-159128) (GH-159133)
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 5564790) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 5f2be7a commit 0d190e9

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎Lib/idlelib/idle_test/test_codecontext.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def setUpClass(cls):
6060
frame = cls.frame = Frame(root)
6161
text = cls.text = Text(frame)
6262
text.insert('1.0', code_sample)
63+
# Make the text longer than the visible height, so that it can scroll.
64+
text.insert('end', '\n' * (int(text['height']) + 2))
6365
# Need to pack for creation of code context text widget.
6466
frame.pack(side='left', fill='both', expand=1)
6567
text.grid(row=1, column=1, sticky=NSEW)

‎Lib/idlelib/idle_test/test_sidebar.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ def test_drag_selection_up(self):
317317
self.assertEqual(self.get_selection(), ('2.0', '5.0'))
318318

319319
def test_scroll(self):
320+
# Synchronized scrolling needs the geometry of mapped widgets.
321+
self.root.deiconify()
322+
self.addCleanup(self.root.withdraw)
323+
320324
self.linenumber.show_sidebar()
321325
self.text.insert('1.0', 'line\n' * 100)
322326
self.root.update()

‎Lib/test/test_tkinter/test_text.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,16 @@ def test_count(self):
727727
self.assertRaises(TclError, text.count, '1.0', 'end', 'spam')
728728
self.assertRaises(TclError, text.count, '1.0', 'end', '-lines')
729729

730-
self.assertIsInstance(text.count('1.3', '1.5', 'ypixels', return_ints=True), int)
731-
self.assertIsInstance(text.count('1.3', '1.5', 'ypixels'), tuple)
732-
self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels', return_ints=True), int)
733-
self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels'), int)
730+
# The ypixels counts depend on the widget geometry.
731+
text.update()
732+
733+
# Indices on the same display line have zero vertical distance.
734+
self.assertEqual(text.count('1.3', '1.5', 'ypixels', return_ints=True), 0)
735+
self.assertIsNone(text.count('1.3', '1.5', 'ypixels'))
736+
self.assertIsInstance(text.count('1.3', '2.5', 'ypixels', return_ints=True), int)
737+
self.assertIsInstance(text.count('1.3', '2.5', 'ypixels'), tuple)
738+
self.assertIsInstance(text.count('1.3', '2.5', 'update', 'ypixels', return_ints=True), int)
739+
self.assertIsInstance(text.count('1.3', '2.5', 'update', 'ypixels'), int)
734740
self.assertEqual(text.count('1.3', '1.3', 'update', 'ypixels', return_ints=True), 0)
735741
self.assertEqual(text.count('1.3', '1.3', 'update', 'ypixels'), None)
736742
self.assertEqual(text.count('1.3', '1.5', 'update', 'indices', return_ints=True), 2)

0 commit comments

Comments
 (0)