mirror of
https://github.com/python/cpython.git
synced 2025-11-01 22:21:35 +00:00
Issue #19602: Use specific asserts in tkinter tests.
This commit is contained in:
parent
78ee078405
commit
e3b5a76540
3 changed files with 26 additions and 26 deletions
|
|
@ -45,7 +45,7 @@ def test_widget_destroy(self):
|
||||||
# it tries calling instance attributes not yet defined.
|
# it tries calling instance attributes not yet defined.
|
||||||
ttk.LabeledScale(variable=myvar)
|
ttk.LabeledScale(variable=myvar)
|
||||||
if hasattr(sys, 'last_type'):
|
if hasattr(sys, 'last_type'):
|
||||||
self.assertFalse(sys.last_type == tkinter.TclError)
|
self.assertNotEqual(sys.last_type, tkinter.TclError)
|
||||||
|
|
||||||
|
|
||||||
def test_initialization(self):
|
def test_initialization(self):
|
||||||
|
|
@ -120,14 +120,14 @@ def test_horizontal_range(self):
|
||||||
# at the same time this shouldn't affect test outcome
|
# at the same time this shouldn't affect test outcome
|
||||||
lscale.update()
|
lscale.update()
|
||||||
curr_xcoord = lscale.scale.coords()[0]
|
curr_xcoord = lscale.scale.coords()[0]
|
||||||
self.assertTrue(prev_xcoord != curr_xcoord)
|
self.assertNotEqual(prev_xcoord, curr_xcoord)
|
||||||
# the label widget should have been repositioned too
|
# the label widget should have been repositioned too
|
||||||
linfo_2 = lscale.label.place_info()
|
linfo_2 = lscale.label.place_info()
|
||||||
self.assertEqual(lscale.label['text'], 0)
|
self.assertEqual(lscale.label['text'], 0)
|
||||||
self.assertEqual(curr_xcoord, int(linfo_2['x']))
|
self.assertEqual(curr_xcoord, int(linfo_2['x']))
|
||||||
# change the range back
|
# change the range back
|
||||||
lscale.scale.configure(from_=0, to=10)
|
lscale.scale.configure(from_=0, to=10)
|
||||||
self.assertTrue(prev_xcoord != curr_xcoord)
|
self.assertNotEqual(prev_xcoord, curr_xcoord)
|
||||||
self.assertEqual(prev_xcoord, int(linfo_1['x']))
|
self.assertEqual(prev_xcoord, int(linfo_1['x']))
|
||||||
|
|
||||||
lscale.destroy()
|
lscale.destroy()
|
||||||
|
|
@ -146,7 +146,7 @@ def test_variable_change(self):
|
||||||
# at the same time this shouldn't affect test outcome
|
# at the same time this shouldn't affect test outcome
|
||||||
x.update()
|
x.update()
|
||||||
self.assertEqual(x.label['text'], newval)
|
self.assertEqual(x.label['text'], newval)
|
||||||
self.assertTrue(x.scale.coords()[0] > curr_xcoord)
|
self.assertGreater(x.scale.coords()[0], curr_xcoord)
|
||||||
self.assertEqual(x.scale.coords()[0],
|
self.assertEqual(x.scale.coords()[0],
|
||||||
int(x.label.place_info()['x']))
|
int(x.label.place_info()['x']))
|
||||||
|
|
||||||
|
|
@ -238,7 +238,7 @@ def test_menu(self):
|
||||||
if last == curr:
|
if last == curr:
|
||||||
# no more menu entries
|
# no more menu entries
|
||||||
break
|
break
|
||||||
self.assertFalse(curr == default)
|
self.assertNotEqual(curr, default)
|
||||||
i += 1
|
i += 1
|
||||||
self.assertEqual(i, len(items))
|
self.assertEqual(i, len(items))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ def test_configure(self):
|
||||||
style.configure('TButton', background='yellow')
|
style.configure('TButton', background='yellow')
|
||||||
self.assertEqual(style.configure('TButton', 'background'),
|
self.assertEqual(style.configure('TButton', 'background'),
|
||||||
'yellow')
|
'yellow')
|
||||||
self.assertTrue(isinstance(style.configure('TButton'), dict))
|
self.assertIsInstance(style.configure('TButton'), dict)
|
||||||
|
|
||||||
|
|
||||||
def test_map(self):
|
def test_map(self):
|
||||||
|
|
@ -26,7 +26,7 @@ def test_map(self):
|
||||||
style.map('TButton', background=[('active', 'background', 'blue')])
|
style.map('TButton', background=[('active', 'background', 'blue')])
|
||||||
self.assertEqual(style.map('TButton', 'background'),
|
self.assertEqual(style.map('TButton', 'background'),
|
||||||
[('active', 'background', 'blue')])
|
[('active', 'background', 'blue')])
|
||||||
self.assertTrue(isinstance(style.map('TButton'), dict))
|
self.assertIsInstance(style.map('TButton'), dict)
|
||||||
|
|
||||||
|
|
||||||
def test_lookup(self):
|
def test_lookup(self):
|
||||||
|
|
@ -57,7 +57,7 @@ def test_layout(self):
|
||||||
self.assertEqual(style.layout('Treeview'), tv_style)
|
self.assertEqual(style.layout('Treeview'), tv_style)
|
||||||
|
|
||||||
# should return a list
|
# should return a list
|
||||||
self.assertTrue(isinstance(style.layout('TButton'), list))
|
self.assertIsInstance(style.layout('TButton'), list)
|
||||||
|
|
||||||
# correct layout, but "option" doesn't exist as option
|
# correct layout, but "option" doesn't exist as option
|
||||||
self.assertRaises(tkinter.TclError, style.layout, 'Treeview',
|
self.assertRaises(tkinter.TclError, style.layout, 'Treeview',
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ def cb_test():
|
||||||
cbtn['command'] = ''
|
cbtn['command'] = ''
|
||||||
res = cbtn.invoke()
|
res = cbtn.invoke()
|
||||||
self.assertFalse(str(res))
|
self.assertFalse(str(res))
|
||||||
self.assertFalse(len(success) > 1)
|
self.assertLessEqual(len(success), 1)
|
||||||
self.assertEqual(cbtn['offvalue'],
|
self.assertEqual(cbtn['offvalue'],
|
||||||
cbtn.tk.globalgetvar(cbtn['variable']))
|
cbtn.tk.globalgetvar(cbtn['variable']))
|
||||||
|
|
||||||
|
|
@ -454,7 +454,7 @@ def test_validatecommand(self):
|
||||||
def test_bbox(self):
|
def test_bbox(self):
|
||||||
self.assertEqual(len(self.entry.bbox(0)), 4)
|
self.assertEqual(len(self.entry.bbox(0)), 4)
|
||||||
for item in self.entry.bbox(0):
|
for item in self.entry.bbox(0):
|
||||||
self.assertTrue(isinstance(item, int))
|
self.assertIsInstance(item, int)
|
||||||
|
|
||||||
self.assertRaises(tkinter.TclError, self.entry.bbox, 'noindex')
|
self.assertRaises(tkinter.TclError, self.entry.bbox, 'noindex')
|
||||||
self.assertRaises(tkinter.TclError, self.entry.bbox, None)
|
self.assertRaises(tkinter.TclError, self.entry.bbox, None)
|
||||||
|
|
@ -652,7 +652,7 @@ def test_pane(self):
|
||||||
|
|
||||||
child = ttk.Label()
|
child = ttk.Label()
|
||||||
self.paned.add(child)
|
self.paned.add(child)
|
||||||
self.assertTrue(isinstance(self.paned.pane(0), dict))
|
self.assertIsInstance(self.paned.pane(0), dict)
|
||||||
self.assertEqual(self.paned.pane(0, weight=None), 0)
|
self.assertEqual(self.paned.pane(0, weight=None), 0)
|
||||||
# newer form for querying a single option
|
# newer form for querying a single option
|
||||||
self.assertEqual(self.paned.pane(0, 'weight'), 0)
|
self.assertEqual(self.paned.pane(0, 'weight'), 0)
|
||||||
|
|
@ -679,8 +679,8 @@ def test_sashpos(self):
|
||||||
|
|
||||||
curr_pos = self.paned.sashpos(0)
|
curr_pos = self.paned.sashpos(0)
|
||||||
self.paned.sashpos(0, 1000)
|
self.paned.sashpos(0, 1000)
|
||||||
self.assertTrue(curr_pos != self.paned.sashpos(0))
|
self.assertNotEqual(curr_pos, self.paned.sashpos(0))
|
||||||
self.assertTrue(isinstance(self.paned.sashpos(0), int))
|
self.assertIsInstance(self.paned.sashpos(0), int)
|
||||||
|
|
||||||
|
|
||||||
@add_standard_options(StandardTtkOptionsTests)
|
@add_standard_options(StandardTtkOptionsTests)
|
||||||
|
|
@ -720,7 +720,7 @@ def cb_test():
|
||||||
cbtn2['command'] = ''
|
cbtn2['command'] = ''
|
||||||
res = cbtn2.invoke()
|
res = cbtn2.invoke()
|
||||||
self.assertEqual(str(res), '')
|
self.assertEqual(str(res), '')
|
||||||
self.assertFalse(len(success) > 1)
|
self.assertLessEqual(len(success), 1)
|
||||||
self.assertEqual(cbtn2['value'], myvar.get())
|
self.assertEqual(cbtn2['value'], myvar.get())
|
||||||
self.assertEqual(myvar.get(),
|
self.assertEqual(myvar.get(),
|
||||||
cbtn.tk.globalgetvar(cbtn['variable']))
|
cbtn.tk.globalgetvar(cbtn['variable']))
|
||||||
|
|
@ -982,7 +982,7 @@ def test_add_and_hidden(self):
|
||||||
self.nb.add(self.child2)
|
self.nb.add(self.child2)
|
||||||
self.assertEqual(self.nb.tabs(), tabs)
|
self.assertEqual(self.nb.tabs(), tabs)
|
||||||
self.assertEqual(self.nb.index(self.child2), child2_index)
|
self.assertEqual(self.nb.index(self.child2), child2_index)
|
||||||
self.assertTrue(str(self.child2) == self.nb.tabs()[child2_index])
|
self.assertEqual(str(self.child2), self.nb.tabs()[child2_index])
|
||||||
# but the tab next to it (not hidden) is the one selected now
|
# but the tab next to it (not hidden) is the one selected now
|
||||||
self.assertEqual(self.nb.index('current'), curr + 1)
|
self.assertEqual(self.nb.index('current'), curr + 1)
|
||||||
|
|
||||||
|
|
@ -995,19 +995,19 @@ def test_forget(self):
|
||||||
tabs = self.nb.tabs()
|
tabs = self.nb.tabs()
|
||||||
child1_index = self.nb.index(self.child1)
|
child1_index = self.nb.index(self.child1)
|
||||||
self.nb.forget(self.child1)
|
self.nb.forget(self.child1)
|
||||||
self.assertFalse(str(self.child1) in self.nb.tabs())
|
self.assertNotIn(str(self.child1), self.nb.tabs())
|
||||||
self.assertEqual(len(tabs) - 1, len(self.nb.tabs()))
|
self.assertEqual(len(tabs) - 1, len(self.nb.tabs()))
|
||||||
|
|
||||||
self.nb.add(self.child1)
|
self.nb.add(self.child1)
|
||||||
self.assertEqual(self.nb.index(self.child1), 1)
|
self.assertEqual(self.nb.index(self.child1), 1)
|
||||||
self.assertFalse(child1_index == self.nb.index(self.child1))
|
self.assertNotEqual(child1_index, self.nb.index(self.child1))
|
||||||
|
|
||||||
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
self.assertRaises(tkinter.TclError, self.nb.index, -1)
|
self.assertRaises(tkinter.TclError, self.nb.index, -1)
|
||||||
self.assertRaises(tkinter.TclError, self.nb.index, None)
|
self.assertRaises(tkinter.TclError, self.nb.index, None)
|
||||||
|
|
||||||
self.assertTrue(isinstance(self.nb.index('end'), int))
|
self.assertIsInstance(self.nb.index('end'), int)
|
||||||
self.assertEqual(self.nb.index(self.child1), 0)
|
self.assertEqual(self.nb.index(self.child1), 0)
|
||||||
self.assertEqual(self.nb.index(self.child2), 1)
|
self.assertEqual(self.nb.index(self.child2), 1)
|
||||||
self.assertEqual(self.nb.index('end'), 2)
|
self.assertEqual(self.nb.index('end'), 2)
|
||||||
|
|
@ -1071,7 +1071,7 @@ def test_tab(self):
|
||||||
self.assertRaises(tkinter.TclError, self.nb.tab, 'notab')
|
self.assertRaises(tkinter.TclError, self.nb.tab, 'notab')
|
||||||
self.assertRaises(tkinter.TclError, self.nb.tab, None)
|
self.assertRaises(tkinter.TclError, self.nb.tab, None)
|
||||||
|
|
||||||
self.assertTrue(isinstance(self.nb.tab(self.child1), dict))
|
self.assertIsInstance(self.nb.tab(self.child1), dict)
|
||||||
self.assertEqual(self.nb.tab(self.child1, text=None), 'a')
|
self.assertEqual(self.nb.tab(self.child1, text=None), 'a')
|
||||||
# newer form for querying a single option
|
# newer form for querying a single option
|
||||||
self.assertEqual(self.nb.tab(self.child1, 'text'), 'a')
|
self.assertEqual(self.nb.tab(self.child1, 'text'), 'a')
|
||||||
|
|
@ -1192,7 +1192,7 @@ def test_bbox(self):
|
||||||
|
|
||||||
bbox = self.tv.bbox(children[0])
|
bbox = self.tv.bbox(children[0])
|
||||||
self.assertEqual(len(bbox), 4)
|
self.assertEqual(len(bbox), 4)
|
||||||
self.assertTrue(isinstance(bbox, tuple))
|
self.assertIsInstance(bbox, tuple)
|
||||||
for item in bbox:
|
for item in bbox:
|
||||||
if not isinstance(item, int):
|
if not isinstance(item, int):
|
||||||
self.fail("Invalid bounding box: %s" % bbox)
|
self.fail("Invalid bounding box: %s" % bbox)
|
||||||
|
|
@ -1215,7 +1215,7 @@ def test_children(self):
|
||||||
self.assertEqual(self.tv.get_children(), ())
|
self.assertEqual(self.tv.get_children(), ())
|
||||||
|
|
||||||
item_id = self.tv.insert('', 'end')
|
item_id = self.tv.insert('', 'end')
|
||||||
self.assertTrue(isinstance(self.tv.get_children(), tuple))
|
self.assertIsInstance(self.tv.get_children(), tuple)
|
||||||
self.assertEqual(self.tv.get_children()[0], item_id)
|
self.assertEqual(self.tv.get_children()[0], item_id)
|
||||||
|
|
||||||
# add item_id and child3 as children of child2
|
# add item_id and child3 as children of child2
|
||||||
|
|
@ -1240,9 +1240,9 @@ def test_children(self):
|
||||||
|
|
||||||
def test_column(self):
|
def test_column(self):
|
||||||
# return a dict with all options/values
|
# return a dict with all options/values
|
||||||
self.assertTrue(isinstance(self.tv.column('#0'), dict))
|
self.assertIsInstance(self.tv.column('#0'), dict)
|
||||||
# return a single value of the given option
|
# return a single value of the given option
|
||||||
self.assertTrue(isinstance(self.tv.column('#0', width=None), int))
|
self.assertIsInstance(self.tv.column('#0', width=None), int)
|
||||||
# set a new value for an option
|
# set a new value for an option
|
||||||
self.tv.column('#0', width=10)
|
self.tv.column('#0', width=10)
|
||||||
# testing new way to get option value
|
# testing new way to get option value
|
||||||
|
|
@ -1355,7 +1355,7 @@ def test_focus(self):
|
||||||
|
|
||||||
def test_heading(self):
|
def test_heading(self):
|
||||||
# check a dict is returned
|
# check a dict is returned
|
||||||
self.assertTrue(isinstance(self.tv.heading('#0'), dict))
|
self.assertIsInstance(self.tv.heading('#0'), dict)
|
||||||
|
|
||||||
# check a value is returned
|
# check a value is returned
|
||||||
self.tv.heading('#0', text='hi')
|
self.tv.heading('#0', text='hi')
|
||||||
|
|
@ -1466,7 +1466,7 @@ def test_insert_item(self):
|
||||||
self.tv.item(item, values=list(self.tv.item(item, values=None)))
|
self.tv.item(item, values=list(self.tv.item(item, values=None)))
|
||||||
self.assertEqual(self.tv.item(item, values=None), (value, ))
|
self.assertEqual(self.tv.item(item, values=None), (value, ))
|
||||||
|
|
||||||
self.assertTrue(isinstance(self.tv.item(item), dict))
|
self.assertIsInstance(self.tv.item(item), dict)
|
||||||
|
|
||||||
# erase item values
|
# erase item values
|
||||||
self.tv.item(item, values='')
|
self.tv.item(item, values='')
|
||||||
|
|
@ -1567,7 +1567,7 @@ def test_tag_configure(self):
|
||||||
'blue')
|
'blue')
|
||||||
self.assertEqual(str(self.tv.tag_configure('test', foreground=None)),
|
self.assertEqual(str(self.tv.tag_configure('test', foreground=None)),
|
||||||
'blue')
|
'blue')
|
||||||
self.assertTrue(isinstance(self.tv.tag_configure('test'), dict))
|
self.assertIsInstance(self.tv.tag_configure('test'), dict)
|
||||||
|
|
||||||
|
|
||||||
@add_standard_options(StandardTtkOptionsTests)
|
@add_standard_options(StandardTtkOptionsTests)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue