Skip to content

Commit

Permalink
bpo-27313: Fix ttk_guionly tests failing on Framework builds on macOS (
Browse files Browse the repository at this point in the history
  • Loading branch information
ambv authored Nov 5, 2021
1 parent 54d1e3f commit e52f9be
Showing 1 changed file with 20 additions and 46 deletions.
66 changes: 20 additions & 46 deletions Lib/tkinter/test/test_ttk/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def setUp(self):
self.widget = ttk.Button(self.root, width=0, text="Text")
self.widget.pack()


def test_identify(self):
self.widget.update()
self.assertEqual(self.widget.identify(
Expand All @@ -74,7 +73,6 @@ def test_identify(self):
self.assertRaises(tkinter.TclError, self.widget.identify, 5, None)
self.assertRaises(tkinter.TclError, self.widget.identify, 5, '')


def test_widget_state(self):
# XXX not sure about the portability of all these tests
self.assertEqual(self.widget.state(), ())
Expand Down Expand Up @@ -287,6 +285,7 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
'show', 'state', 'style', 'takefocus', 'textvariable',
'validate', 'validatecommand', 'width', 'xscrollcommand',
)
IDENTIFY_AS = 'Entry.field' if sys.platform == 'darwin' else 'textarea'

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -319,30 +318,23 @@ def test_configure_validatecommand(self):
widget = self.create()
self.checkCommandParam(widget, 'validatecommand')


def test_bbox(self):
self.assertIsBoundingBox(self.entry.bbox(0))
self.assertRaises(tkinter.TclError, self.entry.bbox, 'noindex')
self.assertRaises(tkinter.TclError, self.entry.bbox, None)


def test_identify(self):
self.entry.pack()
self.entry.update()

# bpo-27313: macOS Cocoa widget differs from X, allow either
if sys.platform == 'darwin':
self.assertIn(self.entry.identify(5, 5),
("textarea", "Combobox.button") )
else:
self.assertEqual(self.entry.identify(5, 5), "textarea")
self.assertEqual(self.entry.identify(5, 5), self.IDENTIFY_AS)
self.assertEqual(self.entry.identify(-1, -1), "")

self.assertRaises(tkinter.TclError, self.entry.identify, None, 5)
self.assertRaises(tkinter.TclError, self.entry.identify, 5, None)
self.assertRaises(tkinter.TclError, self.entry.identify, 5, '')


def test_validation_options(self):
success = []
test_invalid = lambda: success.append(True)
Expand Down Expand Up @@ -370,7 +362,6 @@ def test_validation_options(self):
self.entry['validatecommand'] = True
self.assertRaises(tkinter.TclError, self.entry.validate)


def test_validation(self):
validation = []
def validate(to_insert):
Expand All @@ -388,7 +379,6 @@ def validate(to_insert):
self.assertEqual(validation, [False, True])
self.assertEqual(self.entry.get(), 'a')


def test_revalidation(self):
def validate(content):
for letter in content:
Expand Down Expand Up @@ -424,6 +414,7 @@ class ComboboxTest(EntryTest, unittest.TestCase):
'validate', 'validatecommand', 'values',
'width', 'xscrollcommand',
)
IDENTIFY_AS = 'Combobox.button' if sys.platform == 'darwin' else 'textarea'

def setUp(self):
super().setUp()
Expand All @@ -439,7 +430,8 @@ def test_configure_height(self):
def _show_drop_down_listbox(self):
width = self.combo.winfo_width()
x, y = width - 5, 5
self.assertRegex(self.combo.identify(x, y), r'.*downarrow\Z')
if sys.platform != 'darwin': # there's no down arrow on macOS
self.assertRegex(self.combo.identify(x, y), r'.*downarrow\Z')
self.combo.event_generate('<ButtonPress-1>', x=x, y=y)
self.combo.event_generate('<ButtonRelease-1>', x=x, y=y)
self.combo.update_idletasks()
Expand All @@ -461,7 +453,6 @@ def test_virtual_event(self):

self.assertTrue(success)


def test_configure_postcommand(self):
success = []

Expand All @@ -477,7 +468,6 @@ def test_configure_postcommand(self):
self._show_drop_down_listbox()
self.assertEqual(len(success), 1)


def test_configure_values(self):
def check_get_current(getval, currval):
self.assertEqual(self.combo.get(), getval)
Expand Down Expand Up @@ -592,7 +582,6 @@ def test_add(self):
other_child.destroy()
self.assertRaises(tkinter.TclError, self.paned.pane, 0)


def test_forget(self):
self.assertRaises(tkinter.TclError, self.paned.forget, None)
self.assertRaises(tkinter.TclError, self.paned.forget, 0)
Expand All @@ -601,7 +590,6 @@ def test_forget(self):
self.paned.forget(0)
self.assertRaises(tkinter.TclError, self.paned.forget, 0)


def test_insert(self):
self.assertRaises(tkinter.TclError, self.paned.insert, None, 0)
self.assertRaises(tkinter.TclError, self.paned.insert, 0, None)
Expand Down Expand Up @@ -636,7 +624,6 @@ def test_insert(self):
self.assertEqual(self.paned.panes(),
(str(child3), str(child2), str(child)))


def test_pane(self):
self.assertRaises(tkinter.TclError, self.paned.pane, 0)

Expand All @@ -653,7 +640,6 @@ def test_pane(self):
self.assertRaises(tkinter.TclError, self.paned.pane, 0,
badoption='somevalue')


def test_sashpos(self):
self.assertRaises(tkinter.TclError, self.paned.sashpos, None)
self.assertRaises(tkinter.TclError, self.paned.sashpos, '')
Expand Down Expand Up @@ -801,7 +787,6 @@ def test_custom_event(self):

self.assertFalse(failure)


def test_get(self):
if self.wantobjects:
conv = lambda x: x
Expand All @@ -819,7 +804,6 @@ def test_get(self):
self.assertRaises(tkinter.TclError, self.scale.get, '', 0)
self.assertRaises(tkinter.TclError, self.scale.get, 0, '')


def test_set(self):
if self.wantobjects:
conv = lambda x: x
Expand Down Expand Up @@ -952,7 +936,6 @@ def test_tab_identifiers(self):
else:
self.fail("Tab with text 'a' not found")


def test_add_and_hidden(self):
self.assertRaises(tkinter.TclError, self.nb.hide, -1)
self.assertRaises(tkinter.TclError, self.nb.hide, 'hi')
Expand Down Expand Up @@ -981,7 +964,6 @@ def test_add_and_hidden(self):
# but the tab next to it (not hidden) is the one selected now
self.assertEqual(self.nb.index('current'), curr + 1)


def test_forget(self):
self.assertRaises(tkinter.TclError, self.nb.forget, -1)
self.assertRaises(tkinter.TclError, self.nb.forget, 'hi')
Expand All @@ -997,7 +979,6 @@ def test_forget(self):
self.assertEqual(self.nb.index(self.child1), 1)
self.assertNotEqual(child1_index, self.nb.index(self.child1))


def test_index(self):
self.assertRaises(tkinter.TclError, self.nb.index, -1)
self.assertRaises(tkinter.TclError, self.nb.index, None)
Expand All @@ -1007,7 +988,6 @@ def test_index(self):
self.assertEqual(self.nb.index(self.child2), 1)
self.assertEqual(self.nb.index('end'), 2)


def test_insert(self):
# moving tabs
tabs = self.nb.tabs()
Expand Down Expand Up @@ -1040,7 +1020,6 @@ def test_insert(self):
self.assertRaises(tkinter.TclError, self.nb.insert, None, 0)
self.assertRaises(tkinter.TclError, self.nb.insert, None, None)


def test_select(self):
self.nb.pack()
self.nb.update()
Expand All @@ -1060,7 +1039,6 @@ def test_select(self):
self.nb.update()
self.assertTrue(tab_changed)


def test_tab(self):
self.assertRaises(tkinter.TclError, self.nb.tab, -1)
self.assertRaises(tkinter.TclError, self.nb.tab, 'notab')
Expand All @@ -1074,7 +1052,6 @@ def test_tab(self):
self.assertEqual(self.nb.tab(self.child1, text=None), 'abc')
self.assertEqual(self.nb.tab(self.child1, 'text'), 'abc')


def test_configure_tabs(self):
self.assertEqual(len(self.nb.tabs()), 2)

Expand All @@ -1083,14 +1060,14 @@ def test_configure_tabs(self):

self.assertEqual(self.nb.tabs(), ())


def test_traversal(self):
self.nb.pack()
self.nb.update()

self.nb.select(0)

self.assertEqual(self.nb.identify(5, 5), 'focus')
focus_identify_as = 'focus' if sys.platform != 'darwin' else ''
self.assertEqual(self.nb.identify(5, 5), focus_identify_as)
simulate_mouse_click(self.nb, 5, 5)
self.nb.focus_force()
self.nb.event_generate('<Control-Tab>')
Expand All @@ -1103,15 +1080,24 @@ def test_traversal(self):
self.assertEqual(self.nb.select(), str(self.child2))

self.nb.tab(self.child1, text='a', underline=0)
self.nb.tab(self.child2, text='e', underline=0)
self.nb.enable_traversal()
self.nb.focus_force()
self.assertEqual(self.nb.identify(5, 5), 'focus')
self.assertEqual(self.nb.identify(5, 5), focus_identify_as)
simulate_mouse_click(self.nb, 5, 5)
# on macOS Emacs-style keyboard shortcuts are region-dependent;
# let's use the regular arrow keys instead
if sys.platform == 'darwin':
self.nb.event_generate('<Option-a>')
begin = '<Left>'
end = '<Right>'
else:
self.nb.event_generate('<Alt-a>')
begin = '<Alt-a>'
end = '<Alt-e>'
self.nb.event_generate(begin)
self.assertEqual(self.nb.select(), str(self.child1))
self.nb.event_generate(end)
self.assertEqual(self.nb.select(), str(self.child2))


@add_standard_options(IntegerSizeTests, StandardTtkOptionsTests)
class SpinboxTest(EntryTest, unittest.TestCase):
Expand All @@ -1122,6 +1108,7 @@ class SpinboxTest(EntryTest, unittest.TestCase):
'takefocus', 'textvariable', 'to', 'validate', 'validatecommand',
'values', 'width', 'wrap', 'xscrollcommand',
)
IDENTIFY_AS = 'Spinbox.field' if sys.platform == 'darwin' else 'textarea'

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -1370,7 +1357,6 @@ def test_bbox(self):
child1 = self.tv.insert(item_id, 'end')
self.assertEqual(self.tv.bbox(child1), '')


def test_children(self):
# no children yet, should get an empty tuple
self.assertEqual(self.tv.get_children(), ())
Expand Down Expand Up @@ -1398,7 +1384,6 @@ def test_children(self):
self.tv.set_children('')
self.assertEqual(self.tv.get_children(), ())


def test_column(self):
# return a dict with all options/values
self.assertIsInstance(self.tv.column('#0'), dict)
Expand All @@ -1424,7 +1409,6 @@ def test_column(self):
self.assertRaises(tkinter.TclError, self.tv.column, '#0',
**kw)


def test_delete(self):
self.assertRaises(tkinter.TclError, self.tv.delete, '#0')

Expand All @@ -1448,7 +1432,6 @@ def test_delete(self):
self.tv.delete(item1, item2)
self.assertFalse(self.tv.get_children())


def test_detach_reattach(self):
item_id = self.tv.insert('', 'end')
item2 = self.tv.insert(item_id, 'end')
Expand Down Expand Up @@ -1490,7 +1473,6 @@ def test_detach_reattach(self):
self.assertEqual(self.tv.get_children(), ())
self.assertEqual(self.tv.get_children(item_id), ())


def test_exists(self):
self.assertEqual(self.tv.exists('something'), False)
self.assertEqual(self.tv.exists(''), True)
Expand All @@ -1501,7 +1483,6 @@ def test_exists(self):
# in the tcl interpreter since tk requires an item.
self.assertRaises(tkinter.TclError, self.tv.exists, None)


def test_focus(self):
# nothing is focused right now
self.assertEqual(self.tv.focus(), '')
Expand All @@ -1516,7 +1497,6 @@ def test_focus(self):
# try focusing inexistent item
self.assertRaises(tkinter.TclError, self.tv.focus, 'hi')


def test_heading(self):
# check a dict is returned
self.assertIsInstance(self.tv.heading('#0'), dict)
Expand Down Expand Up @@ -1568,7 +1548,6 @@ def simulate_heading_click(x, y):
#self.tv.heading('#0', command='I dont exist')
#simulate_heading_click(5, 5)


def test_index(self):
# item 'what' doesn't exist
self.assertRaises(tkinter.TclError, self.tv.index, 'what')
Expand Down Expand Up @@ -1599,7 +1578,6 @@ def test_index(self):
self.tv.delete(item1)
self.assertRaises(tkinter.TclError, self.tv.index, c2)


def test_insert_item(self):
# parent 'none' doesn't exist
self.assertRaises(tkinter.TclError, self.tv.insert, 'none', 'end')
Expand Down Expand Up @@ -1676,7 +1654,6 @@ def test_insert_item(self):
self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end', False)
self.assertRaises(tkinter.TclError, self.tv.insert, '', 'end', '')


def test_selection(self):
self.assertRaises(TypeError, self.tv.selection, 'spam')
# item 'none' doesn't exist
Expand Down Expand Up @@ -1747,7 +1724,6 @@ def test_selection(self):
self.tv.selection_toggle((c1, c3))
self.assertEqual(self.tv.selection(), (c3, item2))


def test_set(self):
self.tv['columns'] = ['A', 'B']
item = self.tv.insert('', 'end', values=['a', 'b'])
Expand Down Expand Up @@ -1780,7 +1756,6 @@ def test_set(self):
# inexistent item
self.assertRaises(tkinter.TclError, self.tv.set, 'notme')


def test_tag_bind(self):
events = []
item1 = self.tv.insert('', 'end', tags=['call'])
Expand Down Expand Up @@ -1813,7 +1788,6 @@ def test_tag_bind(self):
for evt in zip(events[::2], events[1::2]):
self.assertEqual(evt, (1, 2))


def test_tag_configure(self):
# Just testing parameter passing for now
self.assertRaises(TypeError, self.tv.tag_configure)
Expand Down

0 comments on commit e52f9be

Please sign in to comment.