Skip to content

Commit c60c854

Browse files
gh-159127: Fix tests depending on the layout of unmapped text widgets
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.
1 parent 565f76f commit c60c854

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
@@ -774,10 +774,16 @@ def test_count(self):
774774
self.assertRaises(TclError, text.count, '1.0', 'end', 'spam')
775775
self.assertRaises(TclError, text.count, '1.0', 'end', '-lines')
776776

777-
self.assertIsInstance(text.count('1.3', '1.5', 'ypixels', return_ints=True), int)
778-
self.assertIsInstance(text.count('1.3', '1.5', 'ypixels'), tuple)
779-
self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels', return_ints=True), int)
780-
self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels'), int)
777+
# The ypixels counts depend on the widget geometry.
778+
text.update()
779+
780+
# Indices on the same display line have zero vertical distance.
781+
self.assertEqual(text.count('1.3', '1.5', 'ypixels', return_ints=True), 0)
782+
self.assertIsNone(text.count('1.3', '1.5', 'ypixels'))
783+
self.assertIsInstance(text.count('1.3', '2.5', 'ypixels', return_ints=True), int)
784+
self.assertIsInstance(text.count('1.3', '2.5', 'ypixels'), tuple)
785+
self.assertIsInstance(text.count('1.3', '2.5', 'update', 'ypixels', return_ints=True), int)
786+
self.assertIsInstance(text.count('1.3', '2.5', 'update', 'ypixels'), int)
781787
self.assertEqual(text.count('1.3', '1.3', 'update', 'ypixels', return_ints=True), 0)
782788
self.assertEqual(text.count('1.3', '1.3', 'update', 'ypixels'), None)
783789
self.assertEqual(text.count('1.3', '1.5', 'update', 'indices', return_ints=True), 2)

0 commit comments

Comments
 (0)