From b75d281e980739598befda6ec4e54e744ec9371f Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 11 Jan 2024 20:15:02 -0500 Subject: [PATCH 1/4] gh-113903: Fix an IDLE configdialog test Fix an extremely rare failure in test_highlight_target_text_mouse that happens if a line of the Highlight tab text sample is not visible. If so, bbox() in clich_char() returns None and iteration fails. Call click_char just once per tag name. --- Lib/idlelib/idle_test/test_configdialog.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py index 6f8518a9bb19d0..c00f8ffe60a1ee 100644 --- a/Lib/idlelib/idle_test/test_configdialog.py +++ b/Lib/idlelib/idle_test/test_configdialog.py @@ -425,15 +425,16 @@ def test_highlight_target_text_mouse(self): 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(start_index): + "Simulate click on character." + hs.see(start_index) + hs.update_idletasks() + x, y, dx, dy = hs.bbox(start_index) x += dx // 2 y += dy // 2 hs.event_generate('', x=0, y=0) @@ -449,7 +450,7 @@ def click_it(start): for tag in hs.tag_names(): for start_index in hs.tag_ranges(tag)[0::2]: count += 1 - click_it(start_index) + click_char(start_index) eq(d.highlight_target.get(), elem[tag]) eq(d.set_highlight_target.called, count) From e38e13cd8e4aa74cfd927520dbeaf9724ea19291 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 11 Jan 2024 20:30:24 -0500 Subject: [PATCH 2/4] Text once per tag in sample. --- Lib/idlelib/idle_test/test_configdialog.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py index c00f8ffe60a1ee..db2b7909e7dfe3 100644 --- a/Lib/idlelib/idle_test/test_configdialog.py +++ b/Lib/idlelib/idle_test/test_configdialog.py @@ -430,11 +430,11 @@ def tag_to_element(elem): for element, tag in d.theme_elements.items(): elem[tag] = element - def click_char(start_index): - "Simulate click on character." - hs.see(start_index) + def click_char(index): + "Simulate click on character at *index*." + hs.see(index) hs.update_idletasks() - x, y, dx, dy = hs.bbox(start_index) + x, y, dx, dy = hs.bbox(index) x += dx // 2 y += dy // 2 hs.event_generate('', x=0, y=0) @@ -448,11 +448,13 @@ def click_char(start_index): # If highlight_sample has a tag that isn't in theme_elements, there # will be a KeyError in the test run. for tag in hs.tag_names(): - for start_index in hs.tag_ranges(tag)[0::2]: - count += 1 - click_char(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 tag. def test_highlight_sample_double_click(self): # Test double click on highlight_sample. From d758812e7a901bd750dde98f5ece3b97abe7a5c6 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 11 Jan 2024 21:06:43 -0500 Subject: [PATCH 3/4] Replace nested function with dict comprehension. --- Lib/idlelib/idle_test/test_configdialog.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py index db2b7909e7dfe3..5099d093382445 100644 --- a/Lib/idlelib/idle_test/test_configdialog.py +++ b/Lib/idlelib/idle_test/test_configdialog.py @@ -420,16 +420,9 @@ 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() - def tag_to_element(elem): - for element, tag in d.theme_elements.items(): - elem[tag] = element - def click_char(index): "Simulate click on character at *index*." hs.see(index) @@ -442,11 +435,12 @@ def click_char(index): hs.event_generate('', x=x, y=y) hs.event_generate('', 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(): try: click_char(hs.tag_nextrange(tag, "1.0")[0]) @@ -454,7 +448,7 @@ def click_char(index): count += 1 eq(d.set_highlight_target.called, count) except IndexError: - pass # Skip unused tag. + pass # Skip unused theme_elements tag, like 'sel'. def test_highlight_sample_double_click(self): # Test double click on highlight_sample. From 22a41803b95973cd66793d77b1f45834caa6edd1 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 11 Jan 2024 21:27:52 -0500 Subject: [PATCH 4/4] News. --- Lib/idlelib/News3.txt | 2 ++ .../next/IDLE/2024-01-11-21-26-58.gh-issue-113903.__GLlQ.rst | 1 + 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2024-01-11-21-26-58.gh-issue-113903.__GLlQ.rst 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/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. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy