FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.13] gh-151678: Add tests for tkinter widget virtual events (GH-151793) by miss-islington · Pull Request #151807 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
17 changes: 17 additions & 0 deletions Lib/test/test_tkinter/test_widgets.py
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
Expand Up @@ -1837,6 +1837,23 @@ def test_selection(self):
self.assertRaisesRegex(TclError, 'bad listbox index "spam"',
lb.selection_includes, 'spam')

def test_selection_event(self):
# Keyboard navigation changes the selection and fires the
# <<ListboxSelect>> virtual event.
lb = self.create(selectmode='browse', exportselection=False)
lb.insert(0, *('el%d' % i for i in range(5)))
lb.pack()
lb.update()
events = []
lb.bind('<<ListboxSelect>>', lambda e: events.append(lb.curselection()))
lb.focus_force()
lb.activate(0)
lb.event_generate('<Down>')
lb.event_generate('<Down>')
lb.update()
self.assertEqual(events, [(1,), (2,)])
self.assertEqual(lb.curselection(), (2,))


@add_standard_options(PixelSizeTests, StandardOptionsTests)
class ScaleTest(AbstractWidgetTest, unittest.TestCase):
Expand Down
44 changes: 44 additions & 0 deletions Lib/test/test_ttk/test_widgets.py
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
Expand Up @@ -1276,6 +1276,19 @@ def test_configure_command(self):
self.spin.update()
self.assertEqual(len(success), 2)

def test_increment_decrement_events(self):
# Clicking the arrows fires the <<Increment>> and <<Decrement>>
# virtual events.
events = []
self.spin.bind('<<Increment>>', lambda e: events.append('increment'))
self.spin.bind('<<Decrement>>', lambda e: events.append('decrement'))
self.spin.update()
self._click_increment_arrow()
self.spin.update()
self._click_decrement_arrow()
self.spin.update()
self.assertEqual(events, ['increment', 'decrement'])

def test_configure_to(self):
self.spin['from'] = 0
self.spin['to'] = 5
Expand Down Expand Up @@ -1910,6 +1923,37 @@ def test_selection(self):
self.tv.selection_toggle((c1, c3))
self.assertEqual(self.tv.selection(), (c3, item2))

def test_virtual_events(self):
# Keyboard navigation fires the <<TreeviewSelect>>, <<TreeviewOpen>>
# and <<TreeviewClose>> virtual events.
parent = self.tv.insert('', 'end')
self.tv.insert(parent, 'end')
item2 = self.tv.insert('', 'end')
self.tv.pack()
self.tv.update()
selects, opens, closes = [], [], []
self.tv.bind('<<TreeviewSelect>>',
lambda e: selects.append(self.tv.selection()))
self.tv.bind('<<TreeviewOpen>>', lambda e: opens.append(self.tv.focus()))
self.tv.bind('<<TreeviewClose>>', lambda e: closes.append(self.tv.focus()))
self.tv.focus_force()
self.tv.focus(parent)
self.tv.selection_set(parent)
self.tv.update()

self.tv.event_generate('<Right>') # Open the focused parent.
self.tv.update()
self.assertEqual(opens, [parent])

self.tv.event_generate('<Left>') # Close it again.
self.tv.update()
self.assertEqual(closes, [parent])

self.tv.event_generate('<Down>') # Move the selection.
self.tv.update()
self.assertEqual(self.tv.selection(), (item2,))
self.assertIn((item2,), selects)

def test_set(self):
self.tv['columns'] = ['A', 'B']
item = self.tv.insert('', 'end', values=['a', 'b'])
Expand Down
Loading

Back | FazBrowse Home | New Git URL