8000 bpo-42142: Try to fix timeouts in ttk tests by serhiy-storchaka · Pull Request #23474 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42142: Try to fix timeouts in ttk tests #23474

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-42142: Fix timeouts in ttk tests
Check whether the widget is already visible before waiting a <VisibilityNotify> event.
  • Loading branch information
serhiy-storchaka committed Nov 23, 2020
commit 3eb4d8e9ed3ceae4223fd996515a8b6b92baaa10
4 changes: 4 additions & 0 deletions Lib/tkinter/test/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ def widget_eq(actual, expected):
if isinstance(expected, (str, tkinter.Widget)):
return str(actual) == str(expected)
return False

def show(widget):
if not widget.winfo_ismapped():
widget.wait_visibility()
14 changes: 7 additions & 7 deletions Lib/tkinter/test/test_ttk/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tkinter
from tkinter import ttk
from test.support import requires, run_unittest, swap_attr
from tkinter.test.support import AbstractTkTest, destroy_default_root
from tkinter.test.support import AbstractTkTest, destroy_default_root, show

requires('gui')

Expand Down Expand Up @@ -114,7 +114,7 @@ def check_positions(scale, scale_pos, label, label_pos):
def test_horizontal_range(self):
lscale = ttk.LabeledScale(self.root, from_=0, to=10)
lscale.pack()
lscale.wait_visibility()
show(lscale)
lscale.update()

linfo_1 = lscale.label.place_info()
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_horizontal_range(self):
def test_variable_change(self):
x = ttk.LabeledScale(self.root)
x.pack()
x.wait_visibility()
show(x)
x.update()

curr_xcoord = x.scale.coords()[0]
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_variable_change(self):
def test_resize(self):
x = ttk.LabeledScale(self.root)
x.pack(expand=True, fill='both')
x.wait_visibility()
show(x)
x.update()

width, height = x.master.winfo_width(), x.master.winfo_height()
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_menu(self):

# check that variable is updated correctly
optmenu.pack()
optmenu.wait_visibility()
show(optmenu)
optmenu['menu'].invoke(0)
self.assertEqual(optmenu._variable.get(), items[0])

Expand Down Expand Up @@ -299,9 +299,9 @@ def test_unique_radiobuttons(self):
textvar2 = tkinter.StringVar(self.root)
optmenu2 = ttk.OptionMenu(self.root, textvar2, default, *items)
optmenu.pack()
optmenu.wait_visibility()
show(optmenu)
optmenu2.pack()
optmenu2.wait_visibility()
show(optmenu2)
optmenu['menu'].invoke(1)
optmenu2['menu'].invoke(2)
optmenu_stringvar_name = optmenu['menu'].entrycget(0, 'variable')
Expand Down
24 changes: 12 additions & 12 deletions Lib/tkinter/test/test_ttk/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from tkinter.test.test_ttk.test_functions import MockTclObj
from tkinter.test.support import (AbstractTkTest, tcl_version, get_tk_patchlevel,
simulate_mouse_click)
simulate_mouse_click, show)
from tkinter.test.widget_tests import (add_standard_options, noconv,
AbstractWidgetTest, StandardOptionsTests, IntegerSizeTests, PixelSizeTests,
setUpModule)
Expand Down Expand Up @@ -60,7 +60,7 @@ def setUp(self):
super().setUp()
self.widget = ttk.Button(self.root, width=0, text="Text")
self.widget.pack()
self.widget.wait_visibility()
show(self.widget)


def test_identify(self):
Expand Down Expand Up @@ -326,7 +326,7 @@ def test_bbox(self):

def test_identify(self):
self.entry.pack()
self.entry.wait_visibility()
show(self.entry)
self.entry.update_idletasks()

# bpo-27313: macOS Cocoa widget differs from X, allow either
Expand Down Expand Up @@ -449,7 +449,7 @@ def test_virtual_event(self):
self.combo.bind('<<ComboboxSelected>>',
lambda evt: success.append(True))
self.combo.pack()
self.combo.wait_visibility()
show(self.combo)

height = self.combo.winfo_height()
self._show_drop_down_listbox()
Expand All @@ -465,7 +465,7 @@ def test_postcommand(self):

self.combo['postcommand'] = lambda: success.append(True)
self.combo.pack()
self.combo.wait_visibility()
show(self.combo)

self._show_drop_down_listbox()
self.assertTrue(success)
Expand Down Expand Up @@ -665,7 +665,7 @@ def test_sashpos(self):
self.assertRaises(tkinter.TclError, self.paned.sashpos, 1)

self.paned.pack(expand=True, fill='both')
self.paned.wait_visibility()
show(self.paned)

curr_pos = self.paned.sashpos(0)
self.paned.sashpos(0, 1000)
Expand Down Expand Up @@ -933,7 +933,7 @@ def test_tab_identifiers(self):
self.nb.add(self.child1, text='a')

self.nb.pack()
self.nb.wait_visibility()
show(self.nb)
if sys.platform == 'darwin':
tb_idx = "@20,5"
else:
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def test_insert(self):

def test_select(self):
self.nb.pack()
self.nb.wait_visibility()
show(self.nb)

success = []
tab_changed = []
Expand Down Expand Up @@ -1084,7 +1084,7 @@ def test_tabs(self):

def test_traversal(self):
self.nb.pack()
self.nb.wait_visibility()
show(self.nb)

self.nb.select(0)

Expand Down Expand Up @@ -1342,7 +1342,7 @@ def test_show(self):
def test_bbox(self):
self.tv.pack()
self.assertEqual(self.tv.bbox(''), '')
self.tv.wait_visibility()
show(self.tv)
self.tv.update()

item_id = self.tv.insert('', 'end')
Expand Down Expand Up @@ -1536,7 +1536,7 @@ def simulate_heading_click(x, y):
success = [] # no success for now

self.tv.pack()
self.tv.wait_visibility()
show(self.tv)
self.tv.heading('#0', command=lambda: success.append(True))
self.tv.column('#0', width=100)
self.tv.update()
Expand Down Expand Up @@ -1784,7 +1784,7 @@ def test_tag_bind(self):
lambda evt: events.append(2))

self.tv.pack()
self.tv.wait_visibility()
show(self.tv)
self.tv.update()

pos_y = set()
Expand Down
0