Skip to content

Commit c4992f4

Browse files
authored
gh-113903: Fix an IDLE configdialog test (#113973)
test_configdialog.HighPageTest.test_highlight_target_text_mouse fails if a line of the Highlight tab text sample is not visible. If so, bbox() in click_char() returns None and the unpacking iteration fails. This occurred on a Devuan Linux system. Fix by moving the 'see character' call inside click_char, just before the bbox call. Also, reduce the click_char calls to just one per tag name and replace the other nested function with a dict comprehension.
1 parent efa738e commit c4992f4

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Lib/idlelib/News3.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Released on 2024-10-xx
44
=========================
55

66

7+
gh-113903: Fix rare failure of test.test_idle, in test_configdialog.
8+
79
gh-113729: Fix the "Help -> IDLE Doc" menu bug in 3.11.7 and 3.12.1.
810

911
gh-57795: Enter selected text into the Find box when opening

Lib/idlelib/idle_test/test_configdialog.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -420,38 +420,35 @@ def test_highlight_target_text_mouse(self):
420420
# Set highlight_target through clicking highlight_sample.
421421
eq = self.assertEqual
422422
d = self.page
423-
424-
elem = {}
425-
count = 0
426423
hs = d.highlight_sample
427424
hs.focus_force()
428-
hs.see(1.0)
429-
hs.update_idletasks()
430425

431-
def tag_to_element(elem):
432-
for element, tag in d.theme_elements.items():
433-
elem[tag] = element
434-
435-
def click_it(start):
436-
x, y, dx, dy = hs.bbox(start)
426+
def click_char(index):
427+
"Simulate click on character at *index*."
428+
hs.see(index)
429+
hs.update_idletasks()
430+
x, y, dx, dy = hs.bbox(index)
437431
x += dx // 2
438432
y += dy // 2
439433
hs.event_generate('<Enter>', x=0, y=0)
440434
hs.event_generate('<Motion>', x=x, y=y)
441435
hs.event_generate('<ButtonPress-1>', x=x, y=y)
442436
hs.event_generate('<ButtonRelease-1>', x=x, y=y)
443437

444-
# Flip theme_elements to make the tag the key.
445-
tag_to_element(elem)
438+
# Reverse theme_elements to make the tag the key.
439+
elem = {tag: element for element, tag in d.theme_elements.items()}
446440

447441
# If highlight_sample has a tag that isn't in theme_elements, there
448442
# will be a KeyError in the test run.
443+
count = 0
449444
for tag in hs.tag_names():
450-
for start_index in hs.tag_ranges(tag)[0::2]:
451-
count += 1
452-
click_it(start_index)
445+
try:
446+
click_char(hs.tag_nextrange(tag, "1.0")[0])
453447
eq(d.highlight_target.get(), elem[tag])
448+
count += 1
454449
eq(d.set_highlight_target.called, count)
450+
except IndexError:
451+
pass # Skip unused theme_elements tag, like 'sel'.
455452

456453
def test_highlight_sample_double_click(self):
457454
# Test double click on highlight_sample.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix rare failure of test.test_idle, in test_configdialog.

0 commit comments

Comments
 (0)