blob: d104eb89104215cbc68d09dc13c30677b29b4348 [file] [log] [blame]
David Aschere2b4b322004-02-18 05:59:53 +00001import unittest
Serhiy Storchakaa26215d2020-11-15 18:16:59 +02002import locale
Serhiy Storchaka462c3572015-04-22 08:36:03 +03003import re
Zachary Ware83fd0a82015-10-12 23:27:58 -05004import subprocess
Hirokazu Yamamotodda7fdf2010-09-23 15:28:35 +00005import sys
David Aschere2b4b322004-02-18 05:59:53 +00006import os
Serhiy Storchakad05b0002019-10-08 14:31:35 +03007import warnings
Benjamin Petersonee8712c2008-05-20 21:35:26 +00008from test import support
Hai Shi06a40d72020-06-25 20:15:40 +08009from test.support import import_helper
Hai Shi79bb2c92020-08-06 19:51:29 +080010from test.support import os_helper
R. David Murraya21e4ca2009-03-31 23:16:50 +000011
12# Skip this test if the _tkinter module wasn't built.
Hai Shi06a40d72020-06-25 20:15:40 +080013_tkinter = import_helper.import_module('_tkinter')
R. David Murraya21e4ca2009-03-31 23:16:50 +000014
Zachary Ware7dc9dea2015-05-22 11:36:53 -050015import tkinter
Guilherme Polofa8fba92009-02-07 02:33:47 +000016from tkinter import Tcl
David Aschere2b4b322004-02-18 05:59:53 +000017from _tkinter import TclError
18
Serhiy Storchaka5cfc79d2014-02-07 10:06:39 +020019try:
20 from _testcapi import INT_MAX, PY_SSIZE_T_MAX
21except ImportError:
22 INT_MAX = PY_SSIZE_T_MAX = sys.maxsize
23
Serhiy Storchaka462c3572015-04-22 08:36:03 +030024tcl_version = tuple(map(int, _tkinter.TCL_VERSION.split('.')))
Serhiy Storchakadfa689b2013-09-08 20:29:37 +030025
Serhiy Storchaka92af06b2014-02-02 23:04:24 +020026_tk_patchlevel = None
27def get_tk_patchlevel():
28 global _tk_patchlevel
29 if _tk_patchlevel is None:
30 tcl = Tcl()
Serhiy Storchaka462c3572015-04-22 08:36:03 +030031 patchlevel = tcl.call('info', 'patchlevel')
32 m = re.fullmatch(r'(\d+)\.(\d+)([ab.])(\d+)', patchlevel)
33 major, minor, releaselevel, serial = m.groups()
34 major, minor, serial = int(major), int(minor), int(serial)
35 releaselevel = {'a': 'alpha', 'b': 'beta', '.': 'final'}[releaselevel]
36 if releaselevel == 'final':
37 _tk_patchlevel = major, minor, serial, releaselevel, 0
38 else:
39 _tk_patchlevel = major, minor, 0, releaselevel, serial
Serhiy Storchaka92af06b2014-02-02 23:04:24 +020040 return _tk_patchlevel
41
Benjamin Petersonc4bbc8d2009-01-30 03:39:35 +000042
43class TkinterTest(unittest.TestCase):
44
45 def testFlattenLen(self):
46 # flatten(<object with no length>)
47 self.assertRaises(TypeError, _tkinter._flatten, True)
48
49
David Aschere2b4b322004-02-18 05:59:53 +000050class TclTest(unittest.TestCase):
51
52 def setUp(self):
53 self.interp = Tcl()
Serhiy Storchakacc4290b2013-12-25 17:29:01 +020054 self.wantobjects = self.interp.tk.wantobjects()
David Aschere2b4b322004-02-18 05:59:53 +000055
56 def testEval(self):
57 tcl = self.interp
58 tcl.eval('set a 1')
59 self.assertEqual(tcl.eval('set a'),'1')
60
Serhiy Storchaka1317e142014-02-03 21:24:07 +020061 def test_eval_null_in_result(self):
62 tcl = self.interp
63 self.assertEqual(tcl.eval('set a "a\\0b"'), 'a\x00b')
64
Serhiy Storchakaa26215d2020-11-15 18:16:59 +020065 def test_eval_surrogates_in_result(self):
66 tcl = self.interp
67 self.assertIn(tcl.eval(r'set a "<\ud83d\udcbb>"'), '<\U0001f4bb>')
68
David Aschere2b4b322004-02-18 05:59:53 +000069 def testEvalException(self):
70 tcl = self.interp
71 self.assertRaises(TclError,tcl.eval,'set a')
72
73 def testEvalException2(self):
74 tcl = self.interp
75 self.assertRaises(TclError,tcl.eval,'this is wrong')
76
77 def testCall(self):
78 tcl = self.interp
79 tcl.call('set','a','1')
80 self.assertEqual(tcl.call('set','a'),'1')
81
82 def testCallException(self):
83 tcl = self.interp
84 self.assertRaises(TclError,tcl.call,'set','a')
85
86 def testCallException2(self):
87 tcl = self.interp
88 self.assertRaises(TclError,tcl.call,'this','is','wrong')
89
90 def testSetVar(self):
91 tcl = self.interp
92 tcl.setvar('a','1')
93 self.assertEqual(tcl.eval('set a'),'1')
94
95 def testSetVarArray(self):
96 tcl = self.interp
97 tcl.setvar('a(1)','1')
98 self.assertEqual(tcl.eval('set a(1)'),'1')
99
100 def testGetVar(self):
101 tcl = self.interp
102 tcl.eval('set a 1')
103 self.assertEqual(tcl.getvar('a'),'1')
104
105 def testGetVarArray(self):
106 tcl = self.interp
107 tcl.eval('set a(1) 1')
108 self.assertEqual(tcl.getvar('a(1)'),'1')
109
110 def testGetVarException(self):
111 tcl = self.interp
112 self.assertRaises(TclError,tcl.getvar,'a')
113
114 def testGetVarArrayException(self):
115 tcl = self.interp
116 self.assertRaises(TclError,tcl.getvar,'a(1)')
117
118 def testUnsetVar(self):
119 tcl = self.interp
120 tcl.setvar('a',1)
121 self.assertEqual(tcl.eval('info exists a'),'1')
122 tcl.unsetvar('a')
123 self.assertEqual(tcl.eval('info exists a'),'0')
124
125 def testUnsetVarArray(self):
126 tcl = self.interp
127 tcl.setvar('a(1)',1)
128 tcl.setvar('a(2)',2)
129 self.assertEqual(tcl.eval('info exists a(1)'),'1')
130 self.assertEqual(tcl.eval('info exists a(2)'),'1')
131 tcl.unsetvar('a(1)')
132 self.assertEqual(tcl.eval('info exists a(1)'),'0')
133 self.assertEqual(tcl.eval('info exists a(2)'),'1')
134
135 def testUnsetVarException(self):
136 tcl = self.interp
137 self.assertRaises(TclError,tcl.unsetvar,'a')
Tim Peters27f88362004-07-08 04:22:35 +0000138
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300139 def get_integers(self):
Serhiy Storchaka4c7dc482015-04-02 18:49:14 +0300140 integers = (0, 1, -1, 2**31-1, -2**31, 2**31, -2**31-1, 2**63-1, -2**63)
Serhiy Storchaka3af7a382015-04-22 10:53:08 +0300141 # bignum was added in Tcl 8.5, but its support is able only since 8.5.8
142 if (get_tk_patchlevel() >= (8, 6, 0, 'final') or
143 (8, 5, 8) <= get_tk_patchlevel() < (8, 6)):
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300144 integers += (2**63, -2**63-1, 2**1000, -2**1000)
145 return integers
146
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300147 def test_getint(self):
148 tcl = self.interp.tk
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300149 for i in self.get_integers():
150 self.assertEqual(tcl.getint(' %d ' % i), i)
Serhiy Storchaka2379d542015-04-02 20:07:09 +0300151 if tcl_version >= (8, 5):
152 self.assertEqual(tcl.getint(' %#o ' % i), i)
153 self.assertEqual(tcl.getint((' %#o ' % i).replace('o', '')), i)
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300154 self.assertEqual(tcl.getint(' %#x ' % i), i)
155 if tcl_version < (8, 5): # bignum was added in Tcl 8.5
156 self.assertRaises(TclError, tcl.getint, str(2**1000))
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300157 self.assertEqual(tcl.getint(42), 42)
158 self.assertRaises(TypeError, tcl.getint)
159 self.assertRaises(TypeError, tcl.getint, '42', '10')
160 self.assertRaises(TypeError, tcl.getint, b'42')
161 self.assertRaises(TypeError, tcl.getint, 42.0)
162 self.assertRaises(TclError, tcl.getint, 'a')
163 self.assertRaises((TypeError, ValueError, TclError),
164 tcl.getint, '42\0')
165 self.assertRaises((UnicodeEncodeError, ValueError, TclError),
166 tcl.getint, '42\ud800')
167
168 def test_getdouble(self):
169 tcl = self.interp.tk
170 self.assertEqual(tcl.getdouble(' 42 '), 42.0)
171 self.assertEqual(tcl.getdouble(' 42.5 '), 42.5)
172 self.assertEqual(tcl.getdouble(42.5), 42.5)
Serhiy Storchaka645058d2015-05-06 14:00:04 +0300173 self.assertEqual(tcl.getdouble(42), 42.0)
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300174 self.assertRaises(TypeError, tcl.getdouble)
175 self.assertRaises(TypeError, tcl.getdouble, '42.5', '10')
176 self.assertRaises(TypeError, tcl.getdouble, b'42.5')
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300177 self.assertRaises(TclError, tcl.getdouble, 'a')
178 self.assertRaises((TypeError, ValueError, TclError),
179 tcl.getdouble, '42.5\0')
180 self.assertRaises((UnicodeEncodeError, ValueError, TclError),
181 tcl.getdouble, '42.5\ud800')
182
183 def test_getboolean(self):
184 tcl = self.interp.tk
185 self.assertIs(tcl.getboolean('on'), True)
186 self.assertIs(tcl.getboolean('1'), True)
Serhiy Storchaka9a6e2012015-04-04 12:43:01 +0300187 self.assertIs(tcl.getboolean(42), True)
188 self.assertIs(tcl.getboolean(0), False)
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300189 self.assertRaises(TypeError, tcl.getboolean)
190 self.assertRaises(TypeError, tcl.getboolean, 'on', '1')
191 self.assertRaises(TypeError, tcl.getboolean, b'on')
192 self.assertRaises(TypeError, tcl.getboolean, 1.0)
193 self.assertRaises(TclError, tcl.getboolean, 'a')
194 self.assertRaises((TypeError, ValueError, TclError),
195 tcl.getboolean, 'on\0')
196 self.assertRaises((UnicodeEncodeError, ValueError, TclError),
197 tcl.getboolean, 'on\ud800')
198
David Aschere2b4b322004-02-18 05:59:53 +0000199 def testEvalFile(self):
200 tcl = self.interp
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200201 filename = os_helper.TESTFN_ASCII
202 self.addCleanup(os_helper.unlink, filename)
203 with open(filename, 'w') as f:
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200204 f.write("""set a 1
205 set b 2
206 set c [ expr $a + $b ]
207 """)
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200208 tcl.evalfile(filename)
David Aschere2b4b322004-02-18 05:59:53 +0000209 self.assertEqual(tcl.eval('set a'),'1')
210 self.assertEqual(tcl.eval('set b'),'2')
211 self.assertEqual(tcl.eval('set c'),'3')
212
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200213 def test_evalfile_null_in_result(self):
214 tcl = self.interp
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200215 filename = os_helper.TESTFN_ASCII
216 self.addCleanup(os_helper.unlink, filename)
217 with open(filename, 'w') as f:
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200218 f.write("""
219 set a "a\0b"
220 set b "a\\0b"
221 """)
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200222 tcl.evalfile(filename)
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200223 self.assertEqual(tcl.eval('set a'), 'a\x00b')
224 self.assertEqual(tcl.eval('set b'), 'a\x00b')
225
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200226 def test_evalfile_surrogates_in_result(self):
227 tcl = self.interp
228 encoding = tcl.call('encoding', 'system')
229 self.addCleanup(tcl.call, 'encoding', 'system', encoding)
230 tcl.call('encoding', 'system', 'utf-8')
231
232 filename = os_helper.TESTFN_ASCII
233 self.addCleanup(os_helper.unlink, filename)
234 with open(filename, 'wb') as f:
235 f.write(b"""
236 set a "<\xed\xa0\xbd\xed\xb2\xbb>"
237 set b "<\\ud83d\\udcbb>"
238 """)
239 tcl.evalfile(filename)
240 self.assertEqual(tcl.eval('set a'), '<\U0001f4bb>')
241 self.assertEqual(tcl.eval('set b'), '<\U0001f4bb>')
242
David Aschere2b4b322004-02-18 05:59:53 +0000243 def testEvalFileException(self):
244 tcl = self.interp
245 filename = "doesnotexists"
246 try:
247 os.remove(filename)
Guido van Rossumb940e112007-01-10 16:19:56 +0000248 except Exception as e:
David Aschere2b4b322004-02-18 05:59:53 +0000249 pass
250 self.assertRaises(TclError,tcl.evalfile,filename)
251
David Aschere2b4b322004-02-18 05:59:53 +0000252 def testPackageRequireException(self):
253 tcl = self.interp
254 self.assertRaises(TclError,tcl.eval,'package require DNE')
255
Hirokazu Yamamotodda7fdf2010-09-23 15:28:35 +0000256 @unittest.skipUnless(sys.platform == 'win32', 'Requires Windows')
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000257 def testLoadWithUNC(self):
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000258 # Build a UNC path from the regular path.
259 # Something like
260 # \\%COMPUTERNAME%\c$\python27\python.exe
261
262 fullname = os.path.abspath(sys.executable)
263 if fullname[1] != ':':
Hirokazu Yamamotodda7fdf2010-09-23 15:28:35 +0000264 raise unittest.SkipTest('Absolute path should have drive part')
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000265 unc_name = r'\\%s\%s$\%s' % (os.environ['COMPUTERNAME'],
266 fullname[0],
267 fullname[3:])
Hirokazu Yamamotodda7fdf2010-09-23 15:28:35 +0000268 if not os.path.exists(unc_name):
269 raise unittest.SkipTest('Cannot connect to UNC Path')
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000270
Hai Shi79bb2c92020-08-06 19:51:29 +0800271 with os_helper.EnvironmentVarGuard() as env:
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000272 env.unset("TCL_LIBRARY")
Zachary Ware83fd0a82015-10-12 23:27:58 -0500273 stdout = subprocess.check_output(
274 [unc_name, '-c', 'import tkinter; print(tkinter)'])
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000275
Zachary Ware83fd0a82015-10-12 23:27:58 -0500276 self.assertIn(b'tkinter', stdout)
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000277
Serhiy Storchakafc055252014-02-03 20:41:34 +0200278 def test_exprstring(self):
279 tcl = self.interp
280 tcl.call('set', 'a', 3)
281 tcl.call('set', 'b', 6)
282 def check(expr, expected):
283 result = tcl.exprstring(expr)
284 self.assertEqual(result, expected)
285 self.assertIsInstance(result, str)
286
287 self.assertRaises(TypeError, tcl.exprstring)
288 self.assertRaises(TypeError, tcl.exprstring, '8.2', '+6')
289 self.assertRaises(TypeError, tcl.exprstring, b'8.2 + 6')
290 self.assertRaises(TclError, tcl.exprstring, 'spam')
291 check('', '0')
292 check('8.2 + 6', '14.2')
Serhiy Storchakafc055252014-02-03 20:41:34 +0200293 check('3.1 + $a', '6.1')
294 check('2 + "$a.$b"', '5.6')
295 check('4*[llength "6 2"]', '8')
296 check('{word one} < "word $a"', '0')
297 check('4*2 < 7', '0')
298 check('hypot($a, 4)', '5.0')
299 check('5 / 4', '1')
300 check('5 / 4.0', '1.25')
301 check('5 / ( [string length "abcd"] + 0.0 )', '1.25')
302 check('20.0/5.0', '4.0')
303 check('"0x03" > "2"', '1')
304 check('[string length "a\xbd\u20ac"]', '3')
305 check(r'[string length "a\xbd\u20ac"]', '3')
306 check('"abc"', 'abc')
307 check('"a\xbd\u20ac"', 'a\xbd\u20ac')
308 check(r'"a\xbd\u20ac"', 'a\xbd\u20ac')
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200309 check(r'"a\0b"', 'a\x00b')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300310 if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka160f8922014-02-03 22:31:09 +0200311 check('2**64', str(2**64))
Serhiy Storchakafc055252014-02-03 20:41:34 +0200312
313 def test_exprdouble(self):
314 tcl = self.interp
315 tcl.call('set', 'a', 3)
316 tcl.call('set', 'b', 6)
317 def check(expr, expected):
318 result = tcl.exprdouble(expr)
319 self.assertEqual(result, expected)
320 self.assertIsInstance(result, float)
321
322 self.assertRaises(TypeError, tcl.exprdouble)
323 self.assertRaises(TypeError, tcl.exprdouble, '8.2', '+6')
324 self.assertRaises(TypeError, tcl.exprdouble, b'8.2 + 6')
325 self.assertRaises(TclError, tcl.exprdouble, 'spam')
326 check('', 0.0)
327 check('8.2 + 6', 14.2)
Serhiy Storchakafc055252014-02-03 20:41:34 +0200328 check('3.1 + $a', 6.1)
329 check('2 + "$a.$b"', 5.6)
330 check('4*[llength "6 2"]', 8.0)
331 check('{word one} < "word $a"', 0.0)
332 check('4*2 < 7', 0.0)
333 check('hypot($a, 4)', 5.0)
334 check('5 / 4', 1.0)
335 check('5 / 4.0', 1.25)
336 check('5 / ( [string length "abcd"] + 0.0 )', 1.25)
337 check('20.0/5.0', 4.0)
338 check('"0x03" > "2"', 1.0)
339 check('[string length "a\xbd\u20ac"]', 3.0)
340 check(r'[string length "a\xbd\u20ac"]', 3.0)
341 self.assertRaises(TclError, tcl.exprdouble, '"abc"')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300342 if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka160f8922014-02-03 22:31:09 +0200343 check('2**64', float(2**64))
Serhiy Storchakafc055252014-02-03 20:41:34 +0200344
345 def test_exprlong(self):
346 tcl = self.interp
347 tcl.call('set', 'a', 3)
348 tcl.call('set', 'b', 6)
349 def check(expr, expected):
350 result = tcl.exprlong(expr)
351 self.assertEqual(result, expected)
352 self.assertIsInstance(result, int)
353
354 self.assertRaises(TypeError, tcl.exprlong)
355 self.assertRaises(TypeError, tcl.exprlong, '8.2', '+6')
356 self.assertRaises(TypeError, tcl.exprlong, b'8.2 + 6')
357 self.assertRaises(TclError, tcl.exprlong, 'spam')
358 check('', 0)
359 check('8.2 + 6', 14)
Serhiy Storchakafc055252014-02-03 20:41:34 +0200360 check('3.1 + $a', 6)
361 check('2 + "$a.$b"', 5)
362 check('4*[llength "6 2"]', 8)
363 check('{word one} < "word $a"', 0)
364 check('4*2 < 7', 0)
365 check('hypot($a, 4)', 5)
366 check('5 / 4', 1)
367 check('5 / 4.0', 1)
368 check('5 / ( [string length "abcd"] + 0.0 )', 1)
369 check('20.0/5.0', 4)
370 check('"0x03" > "2"', 1)
371 check('[string length "a\xbd\u20ac"]', 3)
372 check(r'[string length "a\xbd\u20ac"]', 3)
373 self.assertRaises(TclError, tcl.exprlong, '"abc"')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300374 if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka160f8922014-02-03 22:31:09 +0200375 self.assertRaises(TclError, tcl.exprlong, '2**64')
Serhiy Storchakafc055252014-02-03 20:41:34 +0200376
377 def test_exprboolean(self):
378 tcl = self.interp
379 tcl.call('set', 'a', 3)
380 tcl.call('set', 'b', 6)
381 def check(expr, expected):
382 result = tcl.exprboolean(expr)
383 self.assertEqual(result, expected)
384 self.assertIsInstance(result, int)
385 self.assertNotIsInstance(result, bool)
386
387 self.assertRaises(TypeError, tcl.exprboolean)
388 self.assertRaises(TypeError, tcl.exprboolean, '8.2', '+6')
389 self.assertRaises(TypeError, tcl.exprboolean, b'8.2 + 6')
390 self.assertRaises(TclError, tcl.exprboolean, 'spam')
391 check('', False)
392 for value in ('0', 'false', 'no', 'off'):
393 check(value, False)
394 check('"%s"' % value, False)
395 check('{%s}' % value, False)
396 for value in ('1', 'true', 'yes', 'on'):
397 check(value, True)
398 check('"%s"' % value, True)
399 check('{%s}' % value, True)
400 check('8.2 + 6', True)
Serhiy Storchakafc055252014-02-03 20:41:34 +0200401 check('3.1 + $a', True)
402 check('2 + "$a.$b"', True)
403 check('4*[llength "6 2"]', True)
404 check('{word one} < "word $a"', False)
405 check('4*2 < 7', False)
406 check('hypot($a, 4)', True)
407 check('5 / 4', True)
408 check('5 / 4.0', True)
409 check('5 / ( [string length "abcd"] + 0.0 )', True)
410 check('20.0/5.0', True)
411 check('"0x03" > "2"', True)
412 check('[string length "a\xbd\u20ac"]', True)
413 check(r'[string length "a\xbd\u20ac"]', True)
414 self.assertRaises(TclError, tcl.exprboolean, '"abc"')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300415 if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka160f8922014-02-03 22:31:09 +0200416 check('2**64', True)
Serhiy Storchakafc055252014-02-03 20:41:34 +0200417
Serhiy Storchakaa5a4bd72015-04-02 19:57:52 +0300418 @unittest.skipUnless(tcl_version >= (8, 5), 'requires Tcl version >= 8.5')
Serhiy Storchakaf7de3dd2015-04-02 10:35:57 +0300419 def test_booleans(self):
420 tcl = self.interp
421 def check(expr, expected):
422 result = tcl.call('expr', expr)
Serhiy Storchaka9171fe52015-04-02 11:46:07 +0300423 if tcl.wantobjects():
424 self.assertEqual(result, expected)
425 self.assertIsInstance(result, int)
426 else:
427 self.assertIn(result, (expr, str(int(expected))))
428 self.assertIsInstance(result, str)
Serhiy Storchakaf7de3dd2015-04-02 10:35:57 +0300429 check('true', True)
430 check('yes', True)
431 check('on', True)
432 check('false', False)
433 check('no', False)
434 check('off', False)
435 check('1 < 2', True)
436 check('1 > 2', False)
437
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300438 def test_expr_bignum(self):
439 tcl = self.interp
440 for i in self.get_integers():
441 result = tcl.call('expr', str(i))
442 if self.wantobjects:
443 self.assertEqual(result, i)
444 self.assertIsInstance(result, int)
445 else:
446 self.assertEqual(result, str(i))
447 self.assertIsInstance(result, str)
448 if tcl_version < (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka2379d542015-04-02 20:07:09 +0300449 self.assertRaises(TclError, tcl.call, 'expr', str(2**1000))
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300450
Serhiy Storchakadf4bb462013-02-07 15:40:03 +0200451 def test_passing_values(self):
452 def passValue(value):
453 return self.interp.call('set', '_', value)
454
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200455 self.assertEqual(passValue(True), True if self.wantobjects else '1')
456 self.assertEqual(passValue(False), False if self.wantobjects else '0')
Serhiy Storchakadf4bb462013-02-07 15:40:03 +0200457 self.assertEqual(passValue('string'), 'string')
458 self.assertEqual(passValue('string\u20ac'), 'string\u20ac')
Serhiy Storchaka06cb94b2019-10-04 13:09:52 +0300459 self.assertEqual(passValue('string\U0001f4bb'), 'string\U0001f4bb')
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200460 self.assertEqual(passValue('str\x00ing'), 'str\x00ing')
461 self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd')
462 self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac')
Serhiy Storchaka06cb94b2019-10-04 13:09:52 +0300463 self.assertEqual(passValue('str\x00ing\U0001f4bb'),
464 'str\x00ing\U0001f4bb')
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200465 if sys.platform != 'win32':
466 self.assertEqual(passValue('<\udce2\udc82\udcac>'),
467 '<\u20ac>')
468 self.assertEqual(passValue('<\udced\udca0\udcbd\udced\udcb2\udcbb>'),
469 '<\U0001f4bb>')
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300470 self.assertEqual(passValue(b'str\x00ing'),
471 b'str\x00ing' if self.wantobjects else 'str\x00ing')
472 self.assertEqual(passValue(b'str\xc0\x80ing'),
473 b'str\xc0\x80ing' if self.wantobjects else 'str\xc0\x80ing')
474 self.assertEqual(passValue(b'str\xbding'),
475 b'str\xbding' if self.wantobjects else 'str\xbding')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300476 for i in self.get_integers():
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200477 self.assertEqual(passValue(i), i if self.wantobjects else str(i))
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300478 if tcl_version < (8, 5): # bignum was added in Tcl 8.5
479 self.assertEqual(passValue(2**1000), str(2**1000))
Serhiy Storchakadf4bb462013-02-07 15:40:03 +0200480 for f in (0.0, 1.0, -1.0, 1/3,
481 sys.float_info.min, sys.float_info.max,
482 -sys.float_info.min, -sys.float_info.max):
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200483 if self.wantobjects:
Serhiy Storchakadf4bb462013-02-07 15:40:03 +0200484 self.assertEqual(passValue(f), f)
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200485 else:
486 self.assertEqual(float(passValue(f)), f)
487 if self.wantobjects:
488 f = passValue(float('nan'))
489 self.assertNotEqual(f, f)
490 self.assertEqual(passValue(float('inf')), float('inf'))
491 self.assertEqual(passValue(-float('inf')), -float('inf'))
492 else:
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200493 self.assertEqual(float(passValue(float('inf'))), float('inf'))
494 self.assertEqual(float(passValue(-float('inf'))), -float('inf'))
Serhiy Storchaka6f1435c2014-07-07 14:57:08 +0300495 # XXX NaN representation can be not parsable by float()
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200496 self.assertEqual(passValue((1, '2', (3.4,))),
497 (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
Serhiy Storchaka2b00c492014-05-21 17:12:21 +0300498 self.assertEqual(passValue(['a', ['b', 'c']]),
499 ('a', ('b', 'c')) if self.wantobjects else 'a {b c}')
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000500
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200501 def test_user_command(self):
502 result = None
503 def testfunc(arg):
504 nonlocal result
505 result = arg
506 return arg
507 self.interp.createcommand('testfunc', testfunc)
Antoine Pitrou220cc212014-02-23 19:39:06 +0100508 self.addCleanup(self.interp.tk.deletecommand, 'testfunc')
Serhiy Storchakad6ec3092014-08-18 17:47:29 +0300509 def check(value, expected=None, *, eq=self.assertEqual):
510 if expected is None:
511 expected = value
512 nonlocal result
513 result = None
Serhiy Storchakabdf0cb52014-01-23 16:48:44 +0200514 r = self.interp.call('testfunc', value)
515 self.assertIsInstance(result, str)
516 eq(result, expected)
517 self.assertIsInstance(r, str)
518 eq(r, expected)
519 def float_eq(actual, expected):
Serhiy Storchakabdf0cb52014-01-23 16:48:44 +0200520 self.assertAlmostEqual(float(actual), expected,
521 delta=abs(expected) * 1e-10)
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200522
523 check(True, '1')
524 check(False, '0')
Serhiy Storchakad6ec3092014-08-18 17:47:29 +0300525 check('string')
526 check('string\xbd')
527 check('string\u20ac')
Serhiy Storchaka06cb94b2019-10-04 13:09:52 +0300528 check('string\U0001f4bb')
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200529 if sys.platform != 'win32':
530 check('<\udce2\udc82\udcac>', '<\u20ac>')
531 check('<\udced\udca0\udcbd\udced\udcb2\udcbb>', '<\U0001f4bb>')
Serhiy Storchakaabf68ce2014-09-11 10:57:13 +0300532 check('')
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200533 check(b'string', 'string')
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300534 check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
535 check(b'string\xbd', 'string\xbd')
Serhiy Storchakaabf68ce2014-09-11 10:57:13 +0300536 check(b'', '')
Serhiy Storchakad6ec3092014-08-18 17:47:29 +0300537 check('str\x00ing')
538 check('str\x00ing\xbd')
539 check('str\x00ing\u20ac')
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300540 check(b'str\x00ing', 'str\x00ing')
541 check(b'str\xc0\x80ing', 'str\xc0\x80ing')
542 check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300543 for i in self.get_integers():
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200544 check(i, str(i))
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300545 if tcl_version < (8, 5): # bignum was added in Tcl 8.5
546 check(2**1000, str(2**1000))
Serhiy Storchakabdf0cb52014-01-23 16:48:44 +0200547 for f in (0.0, 1.0, -1.0):
548 check(f, repr(f))
549 for f in (1/3.0, sys.float_info.min, sys.float_info.max,
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200550 -sys.float_info.min, -sys.float_info.max):
Serhiy Storchakad6ec3092014-08-18 17:47:29 +0300551 check(f, eq=float_eq)
552 check(float('inf'), eq=float_eq)
553 check(-float('inf'), eq=float_eq)
Serhiy Storchaka6f1435c2014-07-07 14:57:08 +0300554 # XXX NaN representation can be not parsable by float()
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200555 check((), '')
556 check((1, (2,), (3, 4), '5 6', ()), '1 2 {3 4} {5 6} {}')
Serhiy Storchaka2b00c492014-05-21 17:12:21 +0300557 check([1, [2,], [3, 4], '5 6', []], '1 2 {3 4} {5 6} {}')
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200558
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300559 def test_splitlist(self):
560 splitlist = self.interp.tk.splitlist
561 call = self.interp.tk.call
562 self.assertRaises(TypeError, splitlist)
563 self.assertRaises(TypeError, splitlist, 'a', 'b')
564 self.assertRaises(TypeError, splitlist, 2)
565 testcases = [
566 ('2', ('2',)),
567 ('', ()),
568 ('{}', ('',)),
569 ('""', ('',)),
570 ('a\n b\t\r c\n ', ('a', 'b', 'c')),
571 (b'a\n b\t\r c\n ', ('a', 'b', 'c')),
572 ('a \u20ac', ('a', '\u20ac')),
Serhiy Storchaka06cb94b2019-10-04 13:09:52 +0300573 ('a \U0001f4bb', ('a', '\U0001f4bb')),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300574 (b'a \xe2\x82\xac', ('a', '\u20ac')),
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200575 (b'a \xf0\x9f\x92\xbb', ('a', '\U0001f4bb')),
576 (b'a \xed\xa0\xbd\xed\xb2\xbb', ('a', '\U0001f4bb')),
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200577 (b'a\xc0\x80b c\xc0\x80d', ('a\x00b', 'c\x00d')),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300578 ('a {b c}', ('a', 'b c')),
579 (r'a b\ c', ('a', 'b c')),
580 (('a', 'b c'), ('a', 'b c')),
581 ('a 2', ('a', '2')),
582 (('a', 2), ('a', 2)),
583 ('a 3.4', ('a', '3.4')),
584 (('a', 3.4), ('a', 3.4)),
585 ((), ()),
Serhiy Storchaka2b00c492014-05-21 17:12:21 +0300586 ([], ()),
587 (['a', ['b', 'c']], ('a', ['b', 'c'])),
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200588 (call('list', 1, '2', (3.4,)),
589 (1, '2', (3.4,)) if self.wantobjects else
590 ('1', '2', '3.4')),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300591 ]
Victor Stinnerece38d92014-09-04 09:53:16 +0200592 tk_patchlevel = get_tk_patchlevel()
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300593 if tcl_version >= (8, 5):
Victor Stinnerece38d92014-09-04 09:53:16 +0200594 if not self.wantobjects or tk_patchlevel < (8, 5, 5):
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200595 # Before 8.5.5 dicts were converted to lists through string
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300596 expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4')
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200597 else:
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300598 expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,))
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300599 testcases += [
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200600 (call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
601 expected),
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300602 ]
Victor Stinnerece38d92014-09-04 09:53:16 +0200603 dbg_info = ('want objects? %s, Tcl version: %s, Tk patchlevel: %s'
604 % (self.wantobjects, tcl_version, tk_patchlevel))
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300605 for arg, res in testcases:
Victor Stinnerece38d92014-09-04 09:53:16 +0200606 self.assertEqual(splitlist(arg), res,
607 'arg=%a, %s' % (arg, dbg_info))
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300608 self.assertRaises(TclError, splitlist, '{')
609
610 def test_split(self):
611 split = self.interp.tk.split
612 call = self.interp.tk.call
Serhiy Storchakad05b0002019-10-08 14:31:35 +0300613 with warnings.catch_warnings():
614 warnings.filterwarnings('ignore', r'\bsplit\b.*\bsplitlist\b',
615 DeprecationWarning)
616 self.assertRaises(TypeError, split)
617 self.assertRaises(TypeError, split, 'a', 'b')
618 self.assertRaises(TypeError, split, 2)
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300619 testcases = [
620 ('2', '2'),
621 ('', ''),
622 ('{}', ''),
623 ('""', ''),
624 ('{', '{'),
625 ('a\n b\t\r c\n ', ('a', 'b', 'c')),
626 (b'a\n b\t\r c\n ', ('a', 'b', 'c')),
627 ('a \u20ac', ('a', '\u20ac')),
628 (b'a \xe2\x82\xac', ('a', '\u20ac')),
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200629 (b'a\xc0\x80b', 'a\x00b'),
630 (b'a\xc0\x80b c\xc0\x80d', ('a\x00b', 'c\x00d')),
631 (b'{a\xc0\x80b c\xc0\x80d', '{a\x00b c\x00d'),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300632 ('a {b c}', ('a', ('b', 'c'))),
633 (r'a b\ c', ('a', ('b', 'c'))),
634 (('a', b'b c'), ('a', ('b', 'c'))),
635 (('a', 'b c'), ('a', ('b', 'c'))),
636 ('a 2', ('a', '2')),
637 (('a', 2), ('a', 2)),
638 ('a 3.4', ('a', '3.4')),
639 (('a', 3.4), ('a', 3.4)),
640 (('a', (2, 3.4)), ('a', (2, 3.4))),
641 ((), ()),
Serhiy Storchaka2b00c492014-05-21 17:12:21 +0300642 ([], ()),
643 (['a', 'b c'], ('a', ('b', 'c'))),
644 (['a', ['b', 'c']], ('a', ('b', 'c'))),
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200645 (call('list', 1, '2', (3.4,)),
646 (1, '2', (3.4,)) if self.wantobjects else
647 ('1', '2', '3.4')),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300648 ]
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300649 if tcl_version >= (8, 5):
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200650 if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
651 # Before 8.5.5 dicts were converted to lists through string
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300652 expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4')
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200653 else:
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300654 expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,))
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300655 testcases += [
656 (call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200657 expected),
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300658 ]
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300659 for arg, res in testcases:
Serhiy Storchakad05b0002019-10-08 14:31:35 +0300660 with self.assertWarns(DeprecationWarning):
661 self.assertEqual(split(arg), res, msg=arg)
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300662
Serhiy Storchaka8f0a1d02014-09-06 22:47:58 +0300663 def test_splitdict(self):
664 splitdict = tkinter._splitdict
665 tcl = self.interp.tk
666
667 arg = '-a {1 2 3} -something foo status {}'
668 self.assertEqual(splitdict(tcl, arg, False),
669 {'-a': '1 2 3', '-something': 'foo', 'status': ''})
670 self.assertEqual(splitdict(tcl, arg),
671 {'a': '1 2 3', 'something': 'foo', 'status': ''})
672
673 arg = ('-a', (1, 2, 3), '-something', 'foo', 'status', '{}')
674 self.assertEqual(splitdict(tcl, arg, False),
675 {'-a': (1, 2, 3), '-something': 'foo', 'status': '{}'})
676 self.assertEqual(splitdict(tcl, arg),
677 {'a': (1, 2, 3), 'something': 'foo', 'status': '{}'})
678
679 self.assertRaises(RuntimeError, splitdict, tcl, '-a b -c ')
680 self.assertRaises(RuntimeError, splitdict, tcl, ('-a', 'b', '-c'))
681
682 arg = tcl.call('list',
683 '-a', (1, 2, 3), '-something', 'foo', 'status', ())
684 self.assertEqual(splitdict(tcl, arg),
685 {'a': (1, 2, 3) if self.wantobjects else '1 2 3',
686 'something': 'foo', 'status': ''})
687
688 if tcl_version >= (8, 5):
689 arg = tcl.call('dict', 'create',
690 '-a', (1, 2, 3), '-something', 'foo', 'status', ())
691 if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
692 # Before 8.5.5 dicts were converted to lists through string
693 expected = {'a': '1 2 3', 'something': 'foo', 'status': ''}
694 else:
695 expected = {'a': (1, 2, 3), 'something': 'foo', 'status': ''}
696 self.assertEqual(splitdict(tcl, arg), expected)
697
Serhiy Storchaka5bb5bbf2018-06-30 09:20:28 +0300698 def test_join(self):
699 join = tkinter._join
700 tcl = self.interp.tk
701 def unpack(s):
702 return tcl.call('lindex', s, 0)
703 def check(value):
704 self.assertEqual(unpack(join([value])), value)
705 self.assertEqual(unpack(join([value, 0])), value)
706 self.assertEqual(unpack(unpack(join([[value]]))), value)
707 self.assertEqual(unpack(unpack(join([[value, 0]]))), value)
708 self.assertEqual(unpack(unpack(join([[value], 0]))), value)
709 self.assertEqual(unpack(unpack(join([[value, 0], 0]))), value)
710 check('')
711 check('spam')
712 check('sp am')
713 check('sp\tam')
714 check('sp\nam')
715 check(' \t\n')
716 check('{spam}')
717 check('{sp am}')
718 check('"spam"')
719 check('"sp am"')
720 check('{"spam"}')
721 check('"{spam}"')
722 check('sp\\am')
723 check('"sp\\am"')
724 check('"{}" "{}"')
725 check('"\\')
726 check('"{')
727 check('"}')
728 check('\n\\')
729 check('\n{')
730 check('\n}')
731 check('\\\n')
732 check('{\n')
733 check('}\n')
734
Serhiy Storchakae3f1b092016-05-08 20:46:22 +0300735 def test_new_tcl_obj(self):
736 self.assertRaises(TypeError, _tkinter.Tcl_Obj)
Neal Norwitz63dfece2004-02-19 02:37:29 +0000737
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300738class BigmemTclTest(unittest.TestCase):
739
740 def setUp(self):
741 self.interp = Tcl()
742
Serhiy Storchaka5cfc79d2014-02-07 10:06:39 +0200743 @support.cpython_only
744 @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX")
745 @support.bigmemtest(size=INT_MAX + 1, memuse=5, dry_run=False)
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300746 def test_huge_string_call(self, size):
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300747 value = ' ' * size
Serhiy Storchaka27c623c2017-10-03 22:39:55 +0300748 self.assertRaises(OverflowError, self.interp.call, 'string', 'index', value, 0)
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300749
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300750 @support.cpython_only
751 @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX")
Serhiy Storchaka27c623c2017-10-03 22:39:55 +0300752 @support.bigmemtest(size=INT_MAX + 1, memuse=2, dry_run=False)
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300753 def test_huge_string_builtins(self, size):
Serhiy Storchaka27c623c2017-10-03 22:39:55 +0300754 tk = self.interp.tk
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300755 value = '1' + ' ' * size
Serhiy Storchaka27c623c2017-10-03 22:39:55 +0300756 self.assertRaises(OverflowError, tk.getint, value)
757 self.assertRaises(OverflowError, tk.getdouble, value)
758 self.assertRaises(OverflowError, tk.getboolean, value)
759 self.assertRaises(OverflowError, tk.eval, value)
760 self.assertRaises(OverflowError, tk.evalfile, value)
761 self.assertRaises(OverflowError, tk.record, value)
762 self.assertRaises(OverflowError, tk.adderrorinfo, value)
763 self.assertRaises(OverflowError, tk.setvar, value, 'x', 'a')
764 self.assertRaises(OverflowError, tk.setvar, 'x', value, 'a')
765 self.assertRaises(OverflowError, tk.unsetvar, value)
766 self.assertRaises(OverflowError, tk.unsetvar, 'x', value)
767 self.assertRaises(OverflowError, tk.adderrorinfo, value)
768 self.assertRaises(OverflowError, tk.exprstring, value)
769 self.assertRaises(OverflowError, tk.exprlong, value)
770 self.assertRaises(OverflowError, tk.exprboolean, value)
771 self.assertRaises(OverflowError, tk.splitlist, value)
772 self.assertRaises(OverflowError, tk.split, value)
773 self.assertRaises(OverflowError, tk.createcommand, value, max)
774 self.assertRaises(OverflowError, tk.deletecommand, value)
775
776 @support.cpython_only
777 @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX")
778 @support.bigmemtest(size=INT_MAX + 1, memuse=6, dry_run=False)
779 def test_huge_string_builtins2(self, size):
780 # These commands require larger memory for possible error messages
781 tk = self.interp.tk
782 value = '1' + ' ' * size
783 self.assertRaises(OverflowError, tk.evalfile, value)
784 self.assertRaises(OverflowError, tk.unsetvar, value)
785 self.assertRaises(OverflowError, tk.unsetvar, 'x', value)
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300786
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300787
Serhiy Storchaka8db18232013-11-20 17:43:49 +0200788def setUpModule():
789 if support.verbose:
790 tcl = Tcl()
791 print('patchlevel =', tcl.call('info', 'patchlevel'))
792
793
Neal Norwitz63dfece2004-02-19 02:37:29 +0000794def test_main():
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300795 support.run_unittest(TclTest, TkinterTest, BigmemTclTest)
Neal Norwitz63dfece2004-02-19 02:37:29 +0000796
David Aschere2b4b322004-02-18 05:59:53 +0000797if __name__ == "__main__":
Neal Norwitz63dfece2004-02-19 02:37:29 +0000798 test_main()