Skip to content

Commit 4fabbf9

Browse files
miss-islingtonserhiy-storchakaterryjreedy
authored
[3.13] gh-104855: Update Tkinter tests for Tcl/Tk 8.7 and 9.0 (GH-120824) (GH-120864)
The tests are now passed with the current version of Tcl/Tk under development (8.7b1+ and 9.0b3+). The following changes were also made to make the tests more flexible: * Helper methods like checkParam() now interpret the expected error message as a regular expression instead of a literal. * Add support of new arguments in checkEnumParam(): - allow_empty=True skips testing with empty string; - fullname= specifies the name for error message if it differs from the option name; - sort=True sorts values for error message. * Add support of the allow_empty argument in checkReliefParam(): allow_empty=True adds an empty string to the list of accepted values. * Attributes _clip_highlightthickness, _clip_pad and _clip_borderwidth specify how negative values of options -highlightthickness, -padx, -pady and -borderwidth are handled. * Use global variables for some common error messages. (cherry picked from commit 6ad26de) Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent 4dc27bc commit 4fabbf9

File tree

6 files changed

+250
-137
lines changed

6 files changed

+250
-137
lines changed

Lib/test/test_tcl.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,18 @@ def test_evalfile_surrogates_in_result(self):
219219
with open(filename, 'wb') as f:
220220
f.write(b"""
221221
set a "<\xed\xa0\xbd\xed\xb2\xbb>"
222+
""")
223+
if tcl_version >= (9, 0):
224+
self.assertRaises(TclError, tcl.evalfile, filename)
225+
else:
226+
tcl.evalfile(filename)
227+
self.assertEqual(tcl.eval('set a'), '<\U0001f4bb>')
228+
229+
with open(filename, 'wb') as f:
230+
f.write(b"""
222231
set b "<\\ud83d\\udcbb>"
223232
""")
224233
tcl.evalfile(filename)
225-
self.assertEqual(tcl.eval('set a'), '<\U0001f4bb>')
226234
self.assertEqual(tcl.eval('set b'), '<\U0001f4bb>')
227235

228236
def testEvalFileException(self):

Lib/test/test_tkinter/test_geometry_managers.py

+29-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
requires('gui')
1111

1212

13+
EXPECTED_FLOAT_ERRMSG = 'expected floating-point number but got "{}"'
14+
EXPECTED_FLOAT_OR_EMPTY_ERRMSG = 'expected floating-point number (or "" )?but got "{}"'
15+
EXPECTED_SCREEN_DISTANCE_ERRMSG = '(bad|expected) screen distance (but got )?"{}"'
16+
EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG = '(bad|expected) screen distance (or "" but got )?"{}"'
17+
1318
class PackTest(AbstractWidgetTest, unittest.TestCase):
1419

1520
test_keys = None
@@ -317,7 +322,8 @@ def test_place_configure_x(self):
317322
self.assertEqual(f2.place_info()['x'], '-10')
318323
self.root.update()
319324
self.assertEqual(f2.winfo_x(), 190)
320-
with self.assertRaisesRegex(TclError, 'bad screen distance "spam"'):
325+
with self.assertRaisesRegex(TclError,
326+
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('spam')):
321327
f2.place_configure(in_=f, x='spam')
322328

323329
def test_place_configure_y(self):
@@ -334,7 +340,8 @@ def test_place_configure_y(self):
334340
self.assertEqual(f2.place_info()['y'], '-10')
335341
self.root.update()
336342
self.assertEqual(f2.winfo_y(), 110)
337-
with self.assertRaisesRegex(TclError, 'bad screen distance "spam"'):
343+
with self.assertRaisesRegex(TclError,
344+
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('spam')):
338345
f2.place_configure(in_=f, y='spam')
339346

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

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

376381
def test_place_configure_anchor(self):
@@ -391,7 +396,8 @@ def test_place_configure_width(self):
391396
f2.place_configure(width='')
392397
self.root.update()
393398
self.assertEqual(f2.winfo_width(), 30)
394-
with self.assertRaisesRegex(TclError, 'bad screen distance "abcd"'):
399+
with self.assertRaisesRegex(TclError,
400+
EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG.format('abcd')):
395401
f2.place_configure(width='abcd')
396402

397403
def test_place_configure_height(self):
@@ -402,7 +408,8 @@ def test_place_configure_height(self):
402408
f2.place_configure(height='')
403409
self.root.update()
404410
self.assertEqual(f2.winfo_height(), 60)
405-
with self.assertRaisesRegex(TclError, 'bad screen distance "abcd"'):
411+
with self.assertRaisesRegex(TclError,
412+
EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG.format('abcd')):
406413
f2.place_configure(height='abcd')
407414

408415
def test_place_configure_relwidth(self):
@@ -413,8 +420,7 @@ def test_place_configure_relwidth(self):
413420
f2.place_configure(relwidth='')
414421
self.root.update()
415422
self.assertEqual(f2.winfo_width(), 30)
416-
with self.assertRaisesRegex(TclError, 'expected floating-point number '
417-
'but got "abcd"'):
423+
with self.assertRaisesRegex(TclError, EXPECTED_FLOAT_OR_EMPTY_ERRMSG.format('abcd')):
418424
f2.place_configure(relwidth='abcd')
419425

420426
def test_place_configure_relheight(self):
@@ -425,8 +431,7 @@ def test_place_configure_relheight(self):
425431
f2.place_configure(relheight='')
426432
self.root.update()
427433
self.assertEqual(f2.winfo_height(), 60)
428-
with self.assertRaisesRegex(TclError, 'expected floating-point number '
429-
'but got "abcd"'):
434+
with self.assertRaisesRegex(TclError, EXPECTED_FLOAT_OR_EMPTY_ERRMSG.format('abcd')):
430435
f2.place_configure(relheight='abcd')
431436

432437
def test_place_configure_bordermode(self):
@@ -629,7 +634,8 @@ def test_grid_columnconfigure(self):
629634
self.assertEqual(self.root.grid_columnconfigure(0, 'weight'), 4)
630635

631636
def test_grid_columnconfigure_minsize(self):
632-
with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'):
637+
with self.assertRaisesRegex(TclError,
638+
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('foo')):
633639
self.root.grid_columnconfigure(0, minsize='foo')
634640
self.root.grid_columnconfigure(0, minsize=10)
635641
self.assertEqual(self.root.grid_columnconfigure(0, 'minsize'), 10)
@@ -646,7 +652,8 @@ def test_grid_columnconfigure_weight(self):
646652
self.assertEqual(self.root.grid_columnconfigure(0)['weight'], 3)
647653

648654
def test_grid_columnconfigure_pad(self):
649-
with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'):
655+
with self.assertRaisesRegex(TclError,
656+
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('foo')):
650657
self.root.grid_columnconfigure(0, pad='foo')
651658
with self.assertRaisesRegex(TclError, 'invalid arg "-pad": '
652659
'should be non-negative'):
@@ -683,7 +690,8 @@ def test_grid_rowconfigure(self):
683690
self.assertEqual(self.root.grid_rowconfigure(0, 'weight'), 4)
684691

685692
def test_grid_rowconfigure_minsize(self):
686-
with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'):
693+
with self.assertRaisesRegex(TclError,
694+
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('foo')):
687695
self.root.grid_rowconfigure(0, minsize='foo')
688696
self.root.grid_rowconfigure(0, minsize=10)
689697
self.assertEqual(self.root.grid_rowconfigure(0, 'minsize'), 10)
@@ -700,7 +708,8 @@ def test_grid_rowconfigure_weight(self):
700708
self.assertEqual(self.root.grid_rowconfigure(0)['weight'], 3)
701709

702710
def test_grid_rowconfigure_pad(self):
703-
with self.assertRaisesRegex(TclError, 'bad screen distance "foo"'):
711+
with self.assertRaisesRegex(TclError,
712+
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('foo')):
704713
self.root.grid_rowconfigure(0, pad='foo')
705714
with self.assertRaisesRegex(TclError, 'invalid arg "-pad": '
706715
'should be non-negative'):
@@ -818,9 +827,11 @@ def test_grid_location(self):
818827
self.root.grid_location(0)
819828
with self.assertRaises(TypeError):
820829
self.root.grid_location(0, 0, 0)
821-
with self.assertRaisesRegex(TclError, 'bad screen distance "x"'):
830+
with self.assertRaisesRegex(TclError,
831+
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('x')):
822832
self.root.grid_location('x', 'y')
823-
with self.assertRaisesRegex(TclError, 'bad screen distance "y"'):
833+
with self.assertRaisesRegex(TclError,
834+
EXPECTED_SCREEN_DISTANCE_ERRMSG.format('y')):
824835
self.root.grid_location('1c', 'y')
825836
t = self.root
826837
# de-maximize

Lib/test/test_tkinter/test_variables.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from tkinter import (Variable, StringVar, IntVar, DoubleVar, BooleanVar, Tcl,
77
TclError)
88
from test.support import ALWAYS_EQ
9-
from test.test_tkinter.support import AbstractDefaultRootTest
9+
from test.test_tkinter.support import AbstractDefaultRootTest, tcl_version
1010

1111

1212
class Var(Variable):
@@ -112,6 +112,8 @@ def test_initialize(self):
112112
self.assertTrue(v.side_effect)
113113

114114
def test_trace_old(self):
115+
if tcl_version >= (9, 0):
116+
self.skipTest('requires Tcl version < 9.0')
115117
# Old interface
116118
v = Variable(self.root)
117119
vname = str(v)

0 commit comments

Comments
 (0)