Skip to content

[3.13] gh-104855: Update Tkinter tests for Tcl/Tk 8.7 and 9.0 (GH-120824) #120864

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 1 commit into from
Jun 22, 2024
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
10 changes: 9 additions & 1 deletion Lib/test/test_tcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,18 @@ def test_evalfile_surrogates_in_result(self):
with open(filename, 'wb') as f:
f.write(b"""
set a "<\xed\xa0\xbd\xed\xb2\xbb>"
""")
if tcl_version >= (9, 0):
self.assertRaises(TclError, tcl.evalfile, filename)
else:
tcl.evalfile(filename)
self.assertEqual(tcl.eval('set a'), '<\U0001f4bb>')

with open(filename, 'wb') as f:
f.write(b"""
set b "<\\ud83d\\udcbb>"
""")
tcl.evalfile(filename)
self.assertEqual(tcl.eval('set a'), '<\U0001f4bb>')
self.assertEqual(tcl.eval('set b'), '<\U0001f4bb>')

def testEvalFileException(self):
Expand Down
47 changes: 29 additions & 18 deletions Lib/test/test_tkinter/test_geometry_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
requires('gui')


EXPECTED_FLOAT_ERRMSG = 'expected floating-point number but got "{}"'
EXPECTED_FLOAT_OR_EMPTY_ERRMSG = 'expected floating-point number (or "" )?but got "{}"'
EXPECTED_SCREEN_DISTANCE_ERRMSG = '(bad|expected) screen distance (but got )?"{}"'
EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG = '(bad|expected) screen distance (or "" but got )?"{}"'

class PackTest(AbstractWidgetTest, unittest.TestCase):

test_keys = None
Expand Down Expand Up @@ -317,7 +322,8 @@ def test_place_configure_x(self):
self.assertEqual(f2.place_info()['x'], '-10')
self.root.update()
self.assertEqual(f2.winfo_x(), 190)
with self.assertRaisesRegex(TclError, 'bad screen distance "spam"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('spam')):
f2.place_configure(in_=f, x='spam')

def test_place_configure_y(self):
Expand All @@ -334,7 +340,8 @@ def test_place_configure_y(self):
self.assertEqual(f2.place_info()['y'], '-10')
self.root.update()
self.assertEqual(f2.winfo_y(), 110)
with self.assertRaisesRegex(TclError, 'bad screen distance "spam"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('spam')):
f2.place_configure(in_=f, y='spam')

def test_place_configure_relx(self):
Expand All @@ -351,8 +358,7 @@ def test_place_configure_relx(self):
self.assertEqual(f2.place_info()['relx'], '1')
self.root.update()
self.assertEqual(f2.winfo_x(), 200)
with self.assertRaisesRegex(TclError, 'expected floating-point number '
'but got "spam"'):
with self.assertRaisesRegex(TclError, EXPECTED_FLOAT_ERRMSG.format('spam')):
f2.place_configure(in_=f, relx='spam')

def test_place_configure_rely(self):
Expand All @@ -369,8 +375,7 @@ def test_place_configure_rely(self):
self.assertEqual(f2.place_info()['rely'], '1')
self.root.update()
self.assertEqual(f2.winfo_y(), 120)
with self.assertRaisesRegex(TclError, 'expected floating-point number '
'but got "spam"'):
with self.assertRaisesRegex(TclError, EXPECTED_FLOAT_ERRMSG.format('spam')):
f2.place_configure(in_=f, rely='spam')

def test_place_configure_anchor(self):
Expand All @@ -391,7 +396,8 @@ def test_place_configure_width(self):
f2.place_configure(width='')
self.root.update()
self.assertEqual(f2.winfo_width(), 30)
with self.assertRaisesRegex(TclError, 'bad screen distance "abcd"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG.format('abcd')):
f2.place_configure(width='abcd')

def test_place_configure_height(self):
Expand All @@ -402,7 +408,8 @@ def test_place_configure_height(self):
f2.place_configure(height='')
self.root.update()
self.assertEqual(f2.winfo_height(), 60)
with self.assertRaisesRegex(TclError, 'bad screen distance "abcd"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG.format('abcd')):
f2.place_configure(height='abcd')

def test_place_configure_relwidth(self):
Expand All @@ -413,8 +420,7 @@ def test_place_configure_relwidth(self):
f2.place_configure(relwidth='')
self.root.update()
self.assertEqual(f2.winfo_width(), 30)
with self.assertRaisesRegex(TclError, 'expected floating-point number '
'but got "abcd"'):
with self.assertRaisesRegex(TclError, EXPECTED_FLOAT_OR_EMPTY_ERRMSG.format('abcd')):
f2.place_configure(relwidth='abcd')

def test_place_configure_relheight(self):
Expand All @@ -425,8 +431,7 @@ def test_place_configure_relheight(self):
f2.place_configure(relheight='')
self.root.update()
self.assertEqual(f2.winfo_height(), 60)
with self.assertRaisesRegex(TclError, 'expected floating-point number '
'but got "abcd"'):
with self.assertRaisesRegex(TclError, EXPECTED_FLOAT_OR_EMPTY_ERRMSG.format('abcd')):
f2.place_configure(relheight='abcd')

def test_place_configure_bordermode(self):
Expand Down Expand Up @@ -629,7 +634,8 @@ def test_grid_columnconfigure(self):
self.assertEqual(self.root.grid_columnconfigure(0, 'weight'), 4)

def test_grid_columnconfigure_minsize(self):
with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('foo')):
self.root.grid_columnconfigure(0, minsize='foo')
self.root.grid_columnconfigure(0, minsize=10)
self.assertEqual(self.root.grid_columnconfigure(0, 'minsize'), 10)
Expand All @@ -646,7 +652,8 @@ def test_grid_columnconfigure_weight(self):
self.assertEqual(self.root.grid_columnconfigure(0)['weight'], 3)

def test_grid_columnconfigure_pad(self):
with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('foo')):
self.root.grid_columnconfigure(0, pad='foo')
with self.assertRaisesRegex(TclError, 'invalid arg "-pad": '
'should be non-negative'):
Expand Down Expand Up @@ -683,7 +690,8 @@ def test_grid_rowconfigure(self):
self.assertEqual(self.root.grid_rowconfigure(0, 'weight'), 4)

def test_grid_rowconfigure_minsize(self):
with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('foo')):
self.root.grid_rowconfigure(0, minsize='foo')
self.root.grid_rowconfigure(0, minsize=10)
self.assertEqual(self.root.grid_rowconfigure(0, 'minsize'), 10)
Expand All @@ -700,7 +708,8 @@ def test_grid_rowconfigure_weight(self):
self.assertEqual(self.root.grid_rowconfigure(0)['weight'], 3)

def test_grid_rowconfigure_pad(self):
with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('foo')):
self.root.grid_rowconfigure(0, pad='foo')
with self.assertRaisesRegex(TclError, 'invalid arg "-pad": '
'should be non-negative'):
Expand Down Expand Up @@ -818,9 +827,11 @@ def test_grid_location(self):
self.root.grid_location(0)
with self.assertRaises(TypeError):
self.root.grid_location(0, 0, 0)
with self.assertRaisesRegex(TclError, 'bad screen distance "x"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('x')):
self.root.grid_location('x', 'y')
with self.assertRaisesRegex(TclError, 'bad screen distance "y"'):
with self.assertRaisesRegex(TclError,
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('y')):
self.root.grid_location('1c', 'y')
t = self.root
# de-maximize
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_tkinter/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tkinter import (Variable, StringVar, IntVar, DoubleVar, BooleanVar, Tcl,
TclError)
from test.support import ALWAYS_EQ
from test.test_tkinter.support import AbstractDefaultRootTest
from test.test_tkinter.support import AbstractDefaultRootTest, tcl_version


class Var(Variable):
Expand Down Expand Up @@ -112,6 +112,8 @@ def test_initialize(self):
self.assertTrue(v.side_effect)

def test_trace_old(self):
if tcl_version >= (9, 0):
self.skipTest('requires Tcl version < 9.0')
# Old interface
v = Variable(self.root)
vname = str(v)
Expand Down
Loading
Loading