-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
bpo-35771: IDLE: Fix and optimize flaky tool-tip hover delay tests #15634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
terryjreedy
merged 6 commits into
python:master
from
taleinat:bpo-35771/idle-tooltip-hover-delay-tests
Sep 3, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
498ef1b
refactor common check into a method
taleinat 5fa0323
refactor hover tests with a delay into a single test
taleinat bea1fd0
increase hover delay and sleep duration for robustness
taleinat fd15e05
minor: whitespace and import ordering
taleinat 79c800f
add a NEWS entry
taleinat 39dae8c
Minor revision for style and test coverage.
terryjreedy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| """Test tooltip, coverage 100%. | ||
|
|
||
| Coverage is 100% after excluding 6 lines with "# pragma: no cover". | ||
| They involve TclErrors that either should or should not happen in a | ||
| particular situation, and which are 'pass'ed if they do. | ||
| """ | ||
|
|
||
| from idlelib.tooltip import TooltipBase, Hovertip | ||
| from test.support import requires | ||
| requires('gui') | ||
|
|
@@ -12,16 +19,13 @@ def setUpModule(): | |
| global root | ||
| root = Tk() | ||
|
|
||
| def root_update(): | ||
| global root | ||
| root.update() | ||
|
|
||
| def tearDownModule(): | ||
| global root | ||
| root.update_idletasks() | ||
| root.destroy() | ||
| del root | ||
|
|
||
|
|
||
| def add_call_counting(func): | ||
| @wraps(func) | ||
| def wrapped_func(*args, **kwargs): | ||
|
|
@@ -65,82 +69,93 @@ class HovertipTest(unittest.TestCase): | |
| def setUp(self): | ||
| self.top, self.button = _make_top_and_button(self) | ||
|
|
||
| def is_tipwindow_shown(self, tooltip): | ||
| return tooltip.tipwindow and tooltip.tipwindow.winfo_viewable() | ||
|
|
||
| def test_showtip(self): | ||
| tooltip = Hovertip(self.button, 'ToolTip text') | ||
| self.addCleanup(tooltip.hidetip) | ||
| self.assertFalse(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| self.assertFalse(self.is_tipwindow_shown(tooltip)) | ||
| tooltip.showtip() | ||
| self.assertTrue(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| self.assertTrue(self.is_tipwindow_shown(tooltip)) | ||
|
|
||
| def test_showtip_twice(self): | ||
| tooltip = Hovertip(self.button, 'ToolTip text') | ||
| self.addCleanup(tooltip.hidetip) | ||
| self.assertFalse(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| self.assertFalse(self.is_tipwindow_shown(tooltip)) | ||
| tooltip.showtip() | ||
| self.assertTrue(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| self.assertTrue(self.is_tipwindow_shown(tooltip)) | ||
| orig_tipwindow = tooltip.tipwindow | ||
| tooltip.showtip() | ||
| self.assertTrue(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| self.assertTrue(self.is_tipwindow_shown(tooltip)) | ||
| self.assertIs(tooltip.tipwindow, orig_tipwindow) | ||
|
|
||
| def test_hidetip(self): | ||
| tooltip = Hovertip(self.button, 'ToolTip text') | ||
| self.addCleanup(tooltip.hidetip) | ||
| tooltip.showtip() | ||
| tooltip.hidetip() | ||
| self.assertFalse(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| self.assertFalse(self.is_tipwindow_shown(tooltip)) | ||
|
|
||
| def test_showtip_on_mouse_enter_no_delay(self): | ||
| tooltip = Hovertip(self.button, 'ToolTip text', hover_delay=None) | ||
| self.addCleanup(tooltip.hidetip) | ||
| tooltip.showtip = add_call_counting(tooltip.showtip) | ||
| root_update() | ||
| self.assertFalse(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| root.update() | ||
| self.assertFalse(self.is_tipwindow_shown(tooltip)) | ||
| self.button.event_generate('<Enter>', x=0, y=0) | ||
| root_update() | ||
| self.assertTrue(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| root.update() | ||
| self.assertTrue(self.is_tipwindow_shown(tooltip)) | ||
| self.assertGreater(len(tooltip.showtip.call_args_list), 0) | ||
|
|
||
| def test_showtip_on_mouse_enter_hover_delay(self): | ||
| tooltip = Hovertip(self.button, 'ToolTip text', hover_delay=50) | ||
| self.addCleanup(tooltip.hidetip) | ||
| tooltip.showtip = add_call_counting(tooltip.showtip) | ||
| root_update() | ||
| self.assertFalse(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| def test_hover_with_delay(self): | ||
| # Run multiple tests requiring an actual delay simultaneously. | ||
|
|
||
| # Test #1: A hover tip with a non-zero delay appears after the delay. | ||
| tooltip1 = Hovertip(self.button, 'ToolTip text', hover_delay=100) | ||
| self.addCleanup(tooltip1.hidetip) | ||
| tooltip1.showtip = add_call_counting(tooltip1.showtip) | ||
| root.update() | ||
| self.assertFalse(self.is_tipwindow_shown(tooltip1)) | ||
| self.button.event_generate('<Enter>', x=0, y=0) | ||
| root_update() | ||
| self.assertFalse(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| time.sleep(0.1) | ||
| root_update() | ||
| self.assertTrue(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| self.assertGreater(len(tooltip.showtip.call_args_list), 0) | ||
| root.update() | ||
| self.assertFalse(self.is_tipwindow_shown(tooltip1)) | ||
|
|
||
| # Test #2: A hover tip with a non-zero delay doesn't appear when | ||
| # the mouse stops hovering over the base widget before the delay | ||
| # expires. | ||
| tooltip2 = Hovertip(self.button, 'ToolTip text', hover_delay=100) | ||
| self.addCleanup(tooltip2.hidetip) | ||
| tooltip2.showtip = add_call_counting(tooltip2.showtip) | ||
| root.update() | ||
| self.button.event_generate('<Enter>', x=0, y=0) | ||
| root.update() | ||
| self.button.event_generate('<Leave>', x=0, y=0) | ||
| root.update() | ||
|
|
||
| time.sleep(0.15) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One sleep of .15 (to Windows accuracy of around .017) is faster than 2 sleeps of .10 (ditto). |
||
| root.update() | ||
|
|
||
| # Test #1 assertions. | ||
| self.assertTrue(self.is_tipwindow_shown(tooltip1)) | ||
| self.assertGreater(len(tooltip1.showtip.call_args_list), 0) | ||
|
|
||
| # Test #2 assertions. | ||
| self.assertFalse(self.is_tipwindow_shown(tooltip2)) | ||
| self.assertEqual(tooltip2.showtip.call_args_list, []) | ||
|
|
||
| def test_hidetip_on_mouse_leave(self): | ||
| tooltip = Hovertip(self.button, 'ToolTip text', hover_delay=None) | ||
| self.addCleanup(tooltip.hidetip) | ||
| tooltip.showtip = add_call_counting(tooltip.showtip) | ||
| root_update() | ||
| root.update() | ||
| self.button.event_generate('<Enter>', x=0, y=0) | ||
| root_update() | ||
| root.update() | ||
| self.button.event_generate('<Leave>', x=0, y=0) | ||
| root_update() | ||
| self.assertFalse(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| root.update() | ||
| self.assertFalse(self.is_tipwindow_shown(tooltip)) | ||
| self.assertGreater(len(tooltip.showtip.call_args_list), 0) | ||
|
|
||
| def test_dont_show_on_mouse_leave_before_delay(self): | ||
| tooltip = Hovertip(self.button, 'ToolTip text', hover_delay=50) | ||
| self.addCleanup(tooltip.hidetip) | ||
| tooltip.showtip = add_call_counting(tooltip.showtip) | ||
| root_update() | ||
| self.button.event_generate('<Enter>', x=0, y=0) | ||
| root_update() | ||
| self.button.event_generate('<Leave>', x=0, y=0) | ||
| root_update() | ||
| time.sleep(0.1) | ||
| root_update() | ||
| self.assertFalse(tooltip.tipwindow and tooltip.tipwindow.winfo_viewable()) | ||
| self.assertEqual(tooltip.showtip.call_args_list, []) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main(verbosity=2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/IDLE/2019-09-01-10-22-55.bpo-35771.tdbmbP.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| To avoid occasional spurious test_idle failures on slower machines, | ||
| increase the ``hover_delay`` in test_tooltip. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have used an even shorten name ('tip_shown'), but even as is, this is a definite improvement in readability.