https://github.com/python/cpython/commit/c4992f4106aa509375f5beca8dc044a7f6c36a72
commit: c4992f4106aa509375f5beca8dc044a7f6c36a72
branch: main
author: Terry Jan Reedy <[email protected]>
committer: terryjreedy <[email protected]>
date: 2024-01-11T22:10:00-05:00
summary:

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.

files:
A Misc/NEWS.d/next/IDLE/2024-01-11-21-26-58.gh-issue-113903.__GLlQ.rst
M Lib/idlelib/News3.txt
M Lib/idlelib/idle_test/test_configdialog.py

diff --git a/Lib/idlelib/News3.txt b/Lib/idlelib/News3.txt
index 84484571a49cf7..f6ddbca0e64b06 100644
--- a/Lib/idlelib/News3.txt
+++ b/Lib/idlelib/News3.txt
@@ -4,6 +4,8 @@ Released on 2024-10-xx
 =========================
 
 
+gh-113903: Fix rare failure of test.test_idle, in test_configdialog.
+
 gh-113729: Fix the "Help -> IDLE Doc" menu bug in 3.11.7 and 3.12.1.
 
 gh-57795: Enter selected text into the Find box when opening
diff --git a/Lib/idlelib/idle_test/test_configdialog.py 
b/Lib/idlelib/idle_test/test_configdialog.py
index 6f8518a9bb19d0..5099d093382445 100644
--- a/Lib/idlelib/idle_test/test_configdialog.py
+++ b/Lib/idlelib/idle_test/test_configdialog.py
@@ -420,20 +420,14 @@ def test_highlight_target_text_mouse(self):
         # Set highlight_target through clicking highlight_sample.
         eq = self.assertEqual
         d = self.page
-
-        elem = {}
-        count = 0
         hs = d.highlight_sample
         hs.focus_force()
-        hs.see(1.0)
-        hs.update_idletasks()
 
-        def tag_to_element(elem):
-            for element, tag in d.theme_elements.items():
-                elem[tag] = element
-
-        def click_it(start):
-            x, y, dx, dy = hs.bbox(start)
+        def click_char(index):
+            "Simulate click on character at *index*."
+            hs.see(index)
+            hs.update_idletasks()
+            x, y, dx, dy = hs.bbox(index)
             x += dx // 2
             y += dy // 2
             hs.event_generate('<Enter>', x=0, y=0)
@@ -441,17 +435,20 @@ def click_it(start):
             hs.event_generate('<ButtonPress-1>', x=x, y=y)
             hs.event_generate('<ButtonRelease-1>', x=x, y=y)
 
-        # Flip theme_elements to make the tag the key.
-        tag_to_element(elem)
+        # Reverse theme_elements to make the tag the key.
+        elem = {tag: element for element, tag in d.theme_elements.items()}
 
         # If highlight_sample has a tag that isn't in theme_elements, there
         # will be a KeyError in the test run.
+        count = 0
         for tag in hs.tag_names():
-            for start_index in hs.tag_ranges(tag)[0::2]:
-                count += 1
-                click_it(start_index)
+            try:
+                click_char(hs.tag_nextrange(tag, "1.0")[0])
                 eq(d.highlight_target.get(), elem[tag])
+                count += 1
                 eq(d.set_highlight_target.called, count)
+            except IndexError:
+                pass  # Skip unused theme_elements tag, like 'sel'.
 
     def test_highlight_sample_double_click(self):
         # Test double click on highlight_sample.
diff --git 
a/Misc/NEWS.d/next/IDLE/2024-01-11-21-26-58.gh-issue-113903.__GLlQ.rst 
b/Misc/NEWS.d/next/IDLE/2024-01-11-21-26-58.gh-issue-113903.__GLlQ.rst
new file mode 100644
index 00000000000000..b60c5ac1dd4cd0
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2024-01-11-21-26-58.gh-issue-113903.__GLlQ.rst
@@ -0,0 +1 @@
+Fix rare failure of test.test_idle, in test_configdialog.

_______________________________________________
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