Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions Lib/test/test_tkinter/test_filedialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_use_classic(self):
self.assertEqual(d.ok_button.winfo_class(), 'Button')
self.assertEqual(d.selection.winfo_class(), 'Entry')
if d.top._windowingsystem == 'x11':
self.assertEqual(str(d.botframe.cget('relief')), 'raised')
self.assertEqual(d.botframe.cget('relief'), 'raised')

def test_background(self):
# The ttk dialog adopts the ttk background, even a customized one, while
Expand All @@ -145,18 +145,19 @@ def test_button_accelerator(self):
# The buttons' "&" accelerators are parsed.
d = self.open()
self.assertEqual(str(d.ok_button.cget('text')), 'OK')
self.assertEqual(int(d.ok_button.cget('underline')), 0)
self.assertEqual(d.ok_button.cget('underline'),
0 if self.wantobjects else '0')

def test_default_ring(self):
# The default ring follows the keyboard focus among the buttons.
d = self.open()
self.assertEqual(str(d.cancel_button.cget('default')), 'normal')
self.assertEqual(d.cancel_button.cget('default'), 'normal')
d.cancel_button.focus_force()
d.top.update()
self.assertEqual(str(d.cancel_button.cget('default')), 'active')
self.assertEqual(d.cancel_button.cget('default'), 'active')
d.ok_button.focus_force()
d.top.update()
self.assertEqual(str(d.cancel_button.cget('default')), 'normal')
self.assertEqual(d.cancel_button.cget('default'), 'normal')

def test_alt_key(self):
# Alt + the underlined letter invokes the matching button.
Expand All @@ -182,8 +183,8 @@ def test_escape_cancels(self):
def test_horizontal_scrollbars(self):
# Each list has a horizontal scrollbar besides the vertical one.
d = self.open()
self.assertEqual(str(d.dirshbar.cget('orient')), 'horizontal')
self.assertEqual(str(d.fileshbar.cget('orient')), 'horizontal')
self.assertEqual(d.dirshbar.cget('orient'), 'horizontal')
self.assertEqual(d.fileshbar.cget('orient'), 'horizontal')
self.assertTrue(d.dirs.cget('xscrollcommand'))
self.assertTrue(d.files.cget('xscrollcommand'))

Expand Down
41 changes: 22 additions & 19 deletions Lib/test/test_tkinter/test_simpledialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_use_ttk(self):
d = self.create(buttons=['OK'], bitmap='warning')
self.assertEqual(d._buttons[0].winfo_class(), 'TButton')
self.assertEqual(d.message.winfo_class(), 'TLabel')
self.assertEqual(str(d.message.cget('anchor')), 'nw') # cf. MessageBox
self.assertEqual(d.message.cget('anchor'), 'nw') # cf. MessageBox
# The standard icons are drawn with themed images (cf. MessageBox).
self.assertEqual(d.bitmap.winfo_class(), 'TLabel')
self.assertIn('::tk::icons::warning', str(d.bitmap.cget('image')))
Expand All @@ -57,7 +57,7 @@ def test_use_classic(self):
self.assertEqual(d._buttons[0].winfo_class(), 'Button')
self.assertEqual(d.message.winfo_class(), 'Label')
if d.root._windowingsystem == 'x11':
self.assertEqual(str(d.frame.cget('relief')), 'raised')
self.assertEqual(d.frame.cget('relief'), 'raised')
# tk_dialog does not make the buttons equal width.
self.assertIsNone(d.root.children['bot'].grid_columnconfigure(0)['uniform'])
# The bitmap is a classic monochrome label.
Expand All @@ -75,17 +75,20 @@ def test_no_detail(self):
# Without a detail message the message label expands.
d = self.create()
self.assertIsNone(d.detail)
self.assertEqual(int(d.message.pack_info()['expand']), 1)
self.assertEqual(d.message.pack_info()['expand'],
1 if self.wantobjects else '1')

def test_detail(self):
# The detail message is shown below the main message.
d = self.create(detail='More information.')
self.assertEqual(d.detail.winfo_class(), 'TLabel')
self.assertEqual(str(d.detail.cget('text')), 'More information.')
self.assertEqual(str(d.detail.cget('anchor')), 'nw') # cf. MessageBox
self.assertEqual(d.detail.cget('anchor'), 'nw') # cf. MessageBox
# With a detail message it expands and the main message does not.
self.assertEqual(int(d.message.pack_info()['expand']), 0)
self.assertEqual(int(d.detail.pack_info()['expand']), 1)
self.assertEqual(d.message.pack_info()['expand'],
0 if self.wantobjects else '0')
self.assertEqual(d.detail.pack_info()['expand'],
1 if self.wantobjects else '1')

def test_bitmap_fallback(self):
# A non-standard bitmap has no themed image, so even the ttk version
Expand Down Expand Up @@ -114,11 +117,11 @@ def test_button_options(self):
yes, no = d._buttons
self.assertEqual(str(yes.cget('text')), 'Yes')
self.assertEqual(str(no.cget('text')), 'No')
self.assertEqual(int(no.cget('underline')), 0)
self.assertEqual(no.cget('underline'), 0 if self.wantobjects else '0')
self.assertEqual(str(no.cget('width')), '12')
# The dialog still controls the default ring (default=0) ...
self.assertEqual(str(yes.cget('default')), 'active')
self.assertEqual(str(no.cget('default')), 'normal')
self.assertEqual(yes.cget('default'), 'active')
self.assertEqual(no.cget('default'), 'normal')
# ... and the command, which records the button index.
no.invoke()
self.assertEqual(d.num, 1)
Expand All @@ -128,13 +131,13 @@ def test_default_ring(self):
# (cf. tk::MessageBox).
d = self.create() # buttons ['Yes', 'No'], default 0
b0, b1 = d._buttons
self.assertEqual(str(b1.cget('default')), 'normal')
self.assertEqual(b1.cget('default'), 'normal')
b1.focus_force()
d.root.update()
self.assertEqual(str(b1.cget('default')), 'active') # focused -> ring
self.assertEqual(b1.cget('default'), 'active') # focused -> ring
b0.focus_force()
d.root.update()
self.assertEqual(str(b1.cget('default')), 'normal') # unfocused -> none
self.assertEqual(b1.cget('default'), 'normal') # unfocused -> none

def test_alt_key(self):
# Alt + an underlined character (the "underline" button option) invokes
Expand Down Expand Up @@ -269,7 +272,7 @@ def test_use_classic(self):
self.assertEqual(d.children['ok'].winfo_class(), 'Button')
self.assertEqual(d.entry.winfo_class(), 'Entry')
if d._windowingsystem == 'x11':
self.assertEqual(str(d.children['bot'].cget('relief')), 'raised')
self.assertEqual(d.children['bot'].cget('relief'), 'raised')
# tk_dialog does not make the buttons equal width.
self.assertIsNone(d.children['bot'].grid_columnconfigure(0)['uniform'])
# The bindings work with the classic buttons too.
Expand Down Expand Up @@ -311,8 +314,8 @@ def body(self, master):

def test_button_default(self):
d = self.open()
self.assertEqual(str(d.children['ok'].cget('default')), 'active')
self.assertEqual(str(d.children['cancel'].cget('default')), 'normal')
self.assertEqual(d.children['ok'].cget('default'), 'active')
self.assertEqual(d.children['cancel'].cget('default'), 'normal')

def test_underline_ampersand(self):
self.assertEqual(_underline_ampersand('Yes'), ('Yes', -1))
Expand All @@ -326,19 +329,19 @@ def test_button_accelerator(self):
d = self.open()
ok = d.children['ok'] # "&OK" -> underline 0 -> "O"
self.assertEqual(str(ok.cget('text')), 'OK')
self.assertEqual(int(ok.cget('underline')), 0)
self.assertEqual(ok.cget('underline'), 0 if self.wantobjects else '0')

def test_default_ring(self):
# The default ring follows the keyboard focus among the buttons.
d = self.open()
cancel = d.children['cancel']
self.assertEqual(str(cancel.cget('default')), 'normal')
self.assertEqual(cancel.cget('default'), 'normal')
cancel.focus_force()
d.update()
self.assertEqual(str(cancel.cget('default')), 'active')
self.assertEqual(cancel.cget('default'), 'active')
d.children['ok'].focus_force()
d.update()
self.assertEqual(str(cancel.cget('default')), 'normal')
self.assertEqual(cancel.cget('default'), 'normal')

def test_find_alt_key_target(self):
d = self.open()
Expand Down
16 changes: 10 additions & 6 deletions Lib/test/test_tkinter/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,12 @@ def test_image_configure(self):
self.assertEqual(str(text.image_cget(name, 'image')), str(image))
for value in ('top', 'center', 'bottom', 'baseline'):
text.image_configure(name, align=value)
self.assertEqual(str(text.image_cget(name, 'align')), value)
self.assertEqual(text.image_cget(name, 'align'), value)
text.image_configure(name, padx=3, pady=4)
self.assertEqual(text.tk.getint(text.image_cget(name, 'padx')), 3)
self.assertEqual(text.tk.getint(text.image_cget(name, 'pady')), 4)
self.assertEqual(text.image_cget(name, 'padx'),
3 if self.wantobjects else '3')
self.assertEqual(text.image_cget(name, 'pady'),
4 if self.wantobjects else '4')

# Querying returns the full option set.
cnf = text.image_configure(name)
Expand All @@ -528,10 +530,12 @@ def test_window_configure(self):
self.assertEqual(text.window_cget('1.1', 'window'), str(button))
for value in ('top', 'center', 'bottom', 'baseline'):
text.window_configure('1.1', align=value)
self.assertEqual(str(text.window_cget('1.1', 'align')), value)
self.assertEqual(text.window_cget('1.1', 'align'), value)
text.window_configure('1.1', padx=3, pady=4)
self.assertEqual(text.tk.getint(text.window_cget('1.1', 'padx')), 3)
self.assertEqual(text.tk.getint(text.window_cget('1.1', 'pady')), 4)
self.assertEqual(text.window_cget('1.1', 'padx'),
3 if self.wantobjects else '3')
self.assertEqual(text.window_cget('1.1', 'pady'),
4 if self.wantobjects else '4')
text.window_configure('1.1', stretch=True)
self.assertIs(text.tk.getboolean(text.window_cget('1.1', 'stretch')),
True)
Expand Down
13 changes: 7 additions & 6 deletions Lib/test/test_tkinter/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_unique_variables(self):
b = tkinter.Checkbutton(f, text=j)
b.pack()
buttons.append(b)
variables = [str(b['variable']) for b in buttons]
variables = [b['variable'] for b in buttons]
self.assertEqual(len(set(variables)), 4, variables)

def test_same_name(self):
Expand Down Expand Up @@ -442,14 +442,15 @@ def test_kwargs(self):
# Menubutton options can be passed at construction (gh-101284).
widget = tkinter.OptionMenu(self.root, None, 'b',
width=10, direction='right')
# Menubutton -width is a string on Tk 8.6, an int on 9.0+.
self.assertEqual(int(widget['width']), 10)
self.assertEqual(str(widget['direction']), 'right')
self.assertEqual(widget['direction'], 'right')
# They override OptionMenu's own appearance defaults,
widget = tkinter.OptionMenu(self.root, None, 'b', relief='flat')
self.assertEqual(str(widget['relief']), 'flat')
self.assertEqual(widget['relief'], 'flat')
# which otherwise keep their historical values.
widget = tkinter.OptionMenu(self.root, None, 'b')
self.assertEqual(str(widget['relief']), 'raised')
self.assertEqual(widget['relief'], 'raised')

def test_bad_kwarg(self):
with self.assertRaisesRegex(TclError, r'^unknown option "-spam"$'):
Expand Down Expand Up @@ -2472,9 +2473,9 @@ def test_entryconfigure_variable(self):
v2 = tkinter.BooleanVar(self.root)
m1.add_checkbutton(variable=v1, onvalue=True, offvalue=False,
label='Nonsense')
self.assertEqual(str(m1.entrycget(1, 'variable')), str(v1))
self.assertEqual(m1.entrycget(1, 'variable'), str(v1))
m1.entryconfigure(1, variable=v2)
self.assertEqual(str(m1.entrycget(1, 'variable')), str(v2))
self.assertEqual(m1.entrycget(1, 'variable'), str(v2))

def test_add(self):
m = self.create(tearoff=False)
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_tkinter/widget_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def checkParam(self, widget, name, value, *, expected=_sentinel,
expected = tkinter._join(expected)
else:
expected = str(expected)
elif type(expected) is int:
self.assertIsInstance(widget[name], int)
elif type(expected) is float:
# An integral value may be returned as an int.
self.assertIsInstance(widget[name], (int, float))
if eq is None:
eq = tcl_obj_eq
self.assertEqual2(widget[name], expected, eq=eq)
Expand Down Expand Up @@ -439,7 +444,7 @@ def test_configure_justify(self):

def test_configure_orient(self):
widget = self.create()
self.assertEqual(str(widget['orient']), self.default_orient)
self.assertEqual(widget['orient'], self.default_orient)
self.checkEnumParam(widget, 'orient', 'horizontal', 'vertical')

@requires_tk(8, 7)
Expand Down
22 changes: 11 additions & 11 deletions Lib/test/test_ttk/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def test_unique_variables(self):
b = ttk.Checkbutton(f, text=j)
b.pack()
buttons.append(b)
variables = [str(b['variable']) for b in buttons]
variables = [b['variable'] for b in buttons]
self.assertEqual(len(set(variables)), 4, variables)

def test_unique_variables2(self):
Expand All @@ -331,7 +331,7 @@ def test_unique_variables2(self):
buttons.append(b)
names = [str(b) for b in buttons]
self.assertEqual(len(set(names)), len(buttons), names)
variables = [str(b['variable']) for b in buttons]
variables = [b['variable'] for b in buttons]
self.assertEqual(len(set(variables)), len(buttons), variables)


Expand Down Expand Up @@ -618,14 +618,14 @@ def create(self, **kwargs):

def test_configure_orient(self):
widget = self.create()
self.assertEqual(str(widget['orient']), 'vertical')
self.assertEqual(widget['orient'], 'vertical')
errmsg='attempt to change read-only option'
if get_tk_patchlevel(self.root) < (8, 6, 0, 'beta', 3):
errmsg='Attempt to change read-only option'
self.checkInvalidParam(widget, 'orient', 'horizontal',
errmsg=errmsg)
widget2 = self.create(orient='horizontal')
self.assertEqual(str(widget2['orient']), 'horizontal')
self.assertEqual(widget2['orient'], 'horizontal')

def test_add(self):
# attempt to add a child that is not a direct child of the paned window
Expand Down Expand Up @@ -790,7 +790,7 @@ def cb_test():
self.assertEqual(myvar.get(),
conv(cbtn.tk.globalgetvar(cbtn['variable'])))

self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
self.assertEqual(cbtn['variable'], cbtn2['variable'])


@add_configure_tests(StandardTtkOptionsTests)
Expand Down Expand Up @@ -985,13 +985,13 @@ def test_configure_value(self):

def test_step(self):
widget = self.create(maximum=100, mode='determinate')
self.assertEqual(float(widget['value']), 0.0)
self.assertEqual(widget['value'], self._str(0.0))
widget.step() # The default increment is 1.0.
self.assertEqual(float(widget['value']), 1.0)
self.assertEqual(widget['value'], self._str(1.0))
widget.step(5)
self.assertEqual(float(widget['value']), 6.0)
self.assertEqual(widget['value'], self._str(6.0))
widget.step(-2)
self.assertEqual(float(widget['value']), 4.0)
self.assertEqual(widget['value'], self._str(4.0))

def test_start_stop(self):
widget = self.create(maximum=100, mode='determinate')
Expand All @@ -1000,9 +1000,9 @@ def test_start_stop(self):
widget.update()
widget.stop() # Cancel it.
# After stopping, the value no longer changes.
value = float(widget['value'])
value = widget['value']
widget.update()
self.assertEqual(float(widget['value']), value)
self.assertEqual(widget['value'], value)


@unittest.skipIf(sys.platform == 'darwin',
Expand Down
Loading