blob: ee7344c48ed0beb73d00584876bd58c6f18a9b05 [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 Storchakab02ad242020-12-27 10:13:30 +0200141 # bignum was added in Tcl 8.5, but its support is able only since 8.5.8.
142 # Actually it is determined at compile time, so using get_tk_patchlevel()
143 # is not reliable.
144 # TODO: expose full static version.
145 if tcl_version >= (8, 5):
146 v = get_tk_patchlevel()
147 if v >= (8, 6, 0, 'final') or (8, 5, 8) <= v < (8, 6):
148 integers += (2**63, -2**63-1, 2**1000, -2**1000)
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300149 return integers
150
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300151 def test_getint(self):
152 tcl = self.interp.tk
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300153 for i in self.get_integers():
154 self.assertEqual(tcl.getint(' %d ' % i), i)
Serhiy Storchaka2379d542015-04-02 20:07:09 +0300155 if tcl_version >= (8, 5):
156 self.assertEqual(tcl.getint(' %#o ' % i), i)
157 self.assertEqual(tcl.getint((' %#o ' % i).replace('o', '')), i)
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300158 self.assertEqual(tcl.getint(' %#x ' % i), i)
159 if tcl_version < (8, 5): # bignum was added in Tcl 8.5
160 self.assertRaises(TclError, tcl.getint, str(2**1000))
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300161 self.assertEqual(tcl.getint(42), 42)
162 self.assertRaises(TypeError, tcl.getint)
163 self.assertRaises(TypeError, tcl.getint, '42', '10')
164 self.assertRaises(TypeError, tcl.getint, b'42')
165 self.assertRaises(TypeError, tcl.getint, 42.0)
166 self.assertRaises(TclError, tcl.getint, 'a')
167 self.assertRaises((TypeError, ValueError, TclError),
168 tcl.getint, '42\0')
169 self.assertRaises((UnicodeEncodeError, ValueError, TclError),
170 tcl.getint, '42\ud800')
171
172 def test_getdouble(self):
173 tcl = self.interp.tk
174 self.assertEqual(tcl.getdouble(' 42 '), 42.0)
175 self.assertEqual(tcl.getdouble(' 42.5 '), 42.5)
176 self.assertEqual(tcl.getdouble(42.5), 42.5)
Serhiy Storchaka645058d2015-05-06 14:00:04 +0300177 self.assertEqual(tcl.getdouble(42), 42.0)
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300178 self.assertRaises(TypeError, tcl.getdouble)
179 self.assertRaises(TypeError, tcl.getdouble, '42.5', '10')
180 self.assertRaises(TypeError, tcl.getdouble, b'42.5')
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300181 self.assertRaises(TclError, tcl.getdouble, 'a')
182 self.assertRaises((TypeError, ValueError, TclError),
183 tcl.getdouble, '42.5\0')
184 self.assertRaises((UnicodeEncodeError, ValueError, TclError),
185 tcl.getdouble, '42.5\ud800')
186
187 def test_getboolean(self):
188 tcl = self.interp.tk
189 self.assertIs(tcl.getboolean('on'), True)
190 self.assertIs(tcl.getboolean('1'), True)
Serhiy Storchaka9a6e2012015-04-04 12:43:01 +0300191 self.assertIs(tcl.getboolean(42), True)
192 self.assertIs(tcl.getboolean(0), False)
Serhiy Storchaka9f1f4f42014-05-30 14:07:38 +0300193 self.assertRaises(TypeError, tcl.getboolean)
194 self.assertRaises(TypeError, tcl.getboolean, 'on', '1')
195 self.assertRaises(TypeError, tcl.getboolean, b'on')
196 self.assertRaises(TypeError, tcl.getboolean, 1.0)
197 self.assertRaises(TclError, tcl.getboolean, 'a')
198 self.assertRaises((TypeError, ValueError, TclError),
199 tcl.getboolean, 'on\0')
200 self.assertRaises((UnicodeEncodeError, ValueError, TclError),
201 tcl.getboolean, 'on\ud800')
202
David Aschere2b4b322004-02-18 05:59:53 +0000203 def testEvalFile(self):
204 tcl = self.interp
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200205 filename = os_helper.TESTFN_ASCII
206 self.addCleanup(os_helper.unlink, filename)
207 with open(filename, 'w') as f:
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200208 f.write("""set a 1
209 set b 2
210 set c [ expr $a + $b ]
211 """)
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200212 tcl.evalfile(filename)
David Aschere2b4b322004-02-18 05:59:53 +0000213 self.assertEqual(tcl.eval('set a'),'1')
214 self.assertEqual(tcl.eval('set b'),'2')
215 self.assertEqual(tcl.eval('set c'),'3')
216
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200217 def test_evalfile_null_in_result(self):
218 tcl = self.interp
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200219 filename = os_helper.TESTFN_ASCII
220 self.addCleanup(os_helper.unlink, filename)
221 with open(filename, 'w') as f:
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200222 f.write("""
223 set a "a\0b"
224 set b "a\\0b"
225 """)
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200226 tcl.evalfile(filename)
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200227 self.assertEqual(tcl.eval('set a'), 'a\x00b')
228 self.assertEqual(tcl.eval('set b'), 'a\x00b')
229
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200230 def test_evalfile_surrogates_in_result(self):
231 tcl = self.interp
232 encoding = tcl.call('encoding', 'system')
233 self.addCleanup(tcl.call, 'encoding', 'system', encoding)
234 tcl.call('encoding', 'system', 'utf-8')
235
236 filename = os_helper.TESTFN_ASCII
237 self.addCleanup(os_helper.unlink, filename)
238 with open(filename, 'wb') as f:
239 f.write(b"""
240 set a "<\xed\xa0\xbd\xed\xb2\xbb>"
241 set b "<\\ud83d\\udcbb>"
242 """)
243 tcl.evalfile(filename)
244 self.assertEqual(tcl.eval('set a'), '<\U0001f4bb>')
245 self.assertEqual(tcl.eval('set b'), '<\U0001f4bb>')
246
David Aschere2b4b322004-02-18 05:59:53 +0000247 def testEvalFileException(self):
248 tcl = self.interp
249 filename = "doesnotexists"
250 try:
251 os.remove(filename)
Guido van Rossumb940e112007-01-10 16:19:56 +0000252 except Exception as e:
David Aschere2b4b322004-02-18 05:59:53 +0000253 pass
254 self.assertRaises(TclError,tcl.evalfile,filename)
255
David Aschere2b4b322004-02-18 05:59:53 +0000256 def testPackageRequireException(self):
257 tcl = self.interp
258 self.assertRaises(TclError,tcl.eval,'package require DNE')
259
Hirokazu Yamamotodda7fdf2010-09-23 15:28:35 +0000260 @unittest.skipUnless(sys.platform == 'win32', 'Requires Windows')
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000261 def testLoadWithUNC(self):
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000262 # Build a UNC path from the regular path.
263 # Something like
264 # \\%COMPUTERNAME%\c$\python27\python.exe
265
266 fullname = os.path.abspath(sys.executable)
267 if fullname[1] != ':':
Hirokazu Yamamotodda7fdf2010-09-23 15:28:35 +0000268 raise unittest.SkipTest('Absolute path should have drive part')
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000269 unc_name = r'\\%s\%s$\%s' % (os.environ['COMPUTERNAME'],
270 fullname[0],
271 fullname[3:])
Hirokazu Yamamotodda7fdf2010-09-23 15:28:35 +0000272 if not os.path.exists(unc_name):
273 raise unittest.SkipTest('Cannot connect to UNC Path')
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000274
Hai Shi79bb2c92020-08-06 19:51:29 +0800275 with os_helper.EnvironmentVarGuard() as env:
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000276 env.unset("TCL_LIBRARY")
Zachary Ware83fd0a82015-10-12 23:27:58 -0500277 stdout = subprocess.check_output(
278 [unc_name, '-c', 'import tkinter; print(tkinter)'])
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000279
Zachary Ware83fd0a82015-10-12 23:27:58 -0500280 self.assertIn(b'tkinter', stdout)
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000281
Serhiy Storchakafc055252014-02-03 20:41:34 +0200282 def test_exprstring(self):
283 tcl = self.interp
284 tcl.call('set', 'a', 3)
285 tcl.call('set', 'b', 6)
286 def check(expr, expected):
287 result = tcl.exprstring(expr)
288 self.assertEqual(result, expected)
289 self.assertIsInstance(result, str)
290
291 self.assertRaises(TypeError, tcl.exprstring)
292 self.assertRaises(TypeError, tcl.exprstring, '8.2', '+6')
293 self.assertRaises(TypeError, tcl.exprstring, b'8.2 + 6')
294 self.assertRaises(TclError, tcl.exprstring, 'spam')
295 check('', '0')
296 check('8.2 + 6', '14.2')
Serhiy Storchakafc055252014-02-03 20:41:34 +0200297 check('3.1 + $a', '6.1')
298 check('2 + "$a.$b"', '5.6')
299 check('4*[llength "6 2"]', '8')
300 check('{word one} < "word $a"', '0')
301 check('4*2 < 7', '0')
302 check('hypot($a, 4)', '5.0')
303 check('5 / 4', '1')
304 check('5 / 4.0', '1.25')
305 check('5 / ( [string length "abcd"] + 0.0 )', '1.25')
306 check('20.0/5.0', '4.0')
307 check('"0x03" > "2"', '1')
308 check('[string length "a\xbd\u20ac"]', '3')
309 check(r'[string length "a\xbd\u20ac"]', '3')
310 check('"abc"', 'abc')
311 check('"a\xbd\u20ac"', 'a\xbd\u20ac')
312 check(r'"a\xbd\u20ac"', 'a\xbd\u20ac')
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200313 check(r'"a\0b"', 'a\x00b')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300314 if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka160f8922014-02-03 22:31:09 +0200315 check('2**64', str(2**64))
Serhiy Storchakafc055252014-02-03 20:41:34 +0200316
317 def test_exprdouble(self):
318 tcl = self.interp
319 tcl.call('set', 'a', 3)
320 tcl.call('set', 'b', 6)
321 def check(expr, expected):
322 result = tcl.exprdouble(expr)
323 self.assertEqual(result, expected)
324 self.assertIsInstance(result, float)
325
326 self.assertRaises(TypeError, tcl.exprdouble)
327 self.assertRaises(TypeError, tcl.exprdouble, '8.2', '+6')
328 self.assertRaises(TypeError, tcl.exprdouble, b'8.2 + 6')
329 self.assertRaises(TclError, tcl.exprdouble, 'spam')
330 check('', 0.0)
331 check('8.2 + 6', 14.2)
Serhiy Storchakafc055252014-02-03 20:41:34 +0200332 check('3.1 + $a', 6.1)
333 check('2 + "$a.$b"', 5.6)
334 check('4*[llength "6 2"]', 8.0)
335 check('{word one} < "word $a"', 0.0)
336 check('4*2 < 7', 0.0)
337 check('hypot($a, 4)', 5.0)
338 check('5 / 4', 1.0)
339 check('5 / 4.0', 1.25)
340 check('5 / ( [string length "abcd"] + 0.0 )', 1.25)
341 check('20.0/5.0', 4.0)
342 check('"0x03" > "2"', 1.0)
343 check('[string length "a\xbd\u20ac"]', 3.0)
344 check(r'[string length "a\xbd\u20ac"]', 3.0)
345 self.assertRaises(TclError, tcl.exprdouble, '"abc"')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300346 if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka160f8922014-02-03 22:31:09 +0200347 check('2**64', float(2**64))
Serhiy Storchakafc055252014-02-03 20:41:34 +0200348
349 def test_exprlong(self):
350 tcl = self.interp
351 tcl.call('set', 'a', 3)
352 tcl.call('set', 'b', 6)
353 def check(expr, expected):
354 result = tcl.exprlong(expr)
355 self.assertEqual(result, expected)
356 self.assertIsInstance(result, int)
357
358 self.assertRaises(TypeError, tcl.exprlong)
359 self.assertRaises(TypeError, tcl.exprlong, '8.2', '+6')
360 self.assertRaises(TypeError, tcl.exprlong, b'8.2 + 6')
361 self.assertRaises(TclError, tcl.exprlong, 'spam')
362 check('', 0)
363 check('8.2 + 6', 14)
Serhiy Storchakafc055252014-02-03 20:41:34 +0200364 check('3.1 + $a', 6)
365 check('2 + "$a.$b"', 5)
366 check('4*[llength "6 2"]', 8)
367 check('{word one} < "word $a"', 0)
368 check('4*2 < 7', 0)
369 check('hypot($a, 4)', 5)
370 check('5 / 4', 1)
371 check('5 / 4.0', 1)
372 check('5 / ( [string length "abcd"] + 0.0 )', 1)
373 check('20.0/5.0', 4)
374 check('"0x03" > "2"', 1)
375 check('[string length "a\xbd\u20ac"]', 3)
376 check(r'[string length "a\xbd\u20ac"]', 3)
377 self.assertRaises(TclError, tcl.exprlong, '"abc"')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300378 if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka160f8922014-02-03 22:31:09 +0200379 self.assertRaises(TclError, tcl.exprlong, '2**64')
Serhiy Storchakafc055252014-02-03 20:41:34 +0200380
381 def test_exprboolean(self):
382 tcl = self.interp
383 tcl.call('set', 'a', 3)
384 tcl.call('set', 'b', 6)
385 def check(expr, expected):
386 result = tcl.exprboolean(expr)
387 self.assertEqual(result, expected)
388 self.assertIsInstance(result, int)
389 self.assertNotIsInstance(result, bool)
390
391 self.assertRaises(TypeError, tcl.exprboolean)
392 self.assertRaises(TypeError, tcl.exprboolean, '8.2', '+6')
393 self.assertRaises(TypeError, tcl.exprboolean, b'8.2 + 6')
394 self.assertRaises(TclError, tcl.exprboolean, 'spam')
395 check('', False)
396 for value in ('0', 'false', 'no', 'off'):
397 check(value, False)
398 check('"%s"' % value, False)
399 check('{%s}' % value, False)
400 for value in ('1', 'true', 'yes', 'on'):
401 check(value, True)
402 check('"%s"' % value, True)
403 check('{%s}' % value, True)
404 check('8.2 + 6', True)
Serhiy Storchakafc055252014-02-03 20:41:34 +0200405 check('3.1 + $a', True)
406 check('2 + "$a.$b"', True)
407 check('4*[llength "6 2"]', True)
408 check('{word one} < "word $a"', False)
409 check('4*2 < 7', False)
410 check('hypot($a, 4)', True)
411 check('5 / 4', True)
412 check('5 / 4.0', True)
413 check('5 / ( [string length "abcd"] + 0.0 )', True)
414 check('20.0/5.0', True)
415 check('"0x03" > "2"', True)
416 check('[string length "a\xbd\u20ac"]', True)
417 check(r'[string length "a\xbd\u20ac"]', True)
418 self.assertRaises(TclError, tcl.exprboolean, '"abc"')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300419 if tcl_version >= (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka160f8922014-02-03 22:31:09 +0200420 check('2**64', True)
Serhiy Storchakafc055252014-02-03 20:41:34 +0200421
Serhiy Storchakaa5a4bd72015-04-02 19:57:52 +0300422 @unittest.skipUnless(tcl_version >= (8, 5), 'requires Tcl version >= 8.5')
Serhiy Storchakaf7de3dd2015-04-02 10:35:57 +0300423 def test_booleans(self):
424 tcl = self.interp
425 def check(expr, expected):
426 result = tcl.call('expr', expr)
Serhiy Storchaka9171fe52015-04-02 11:46:07 +0300427 if tcl.wantobjects():
428 self.assertEqual(result, expected)
429 self.assertIsInstance(result, int)
430 else:
431 self.assertIn(result, (expr, str(int(expected))))
432 self.assertIsInstance(result, str)
Serhiy Storchakaf7de3dd2015-04-02 10:35:57 +0300433 check('true', True)
434 check('yes', True)
435 check('on', True)
436 check('false', False)
437 check('no', False)
438 check('off', False)
439 check('1 < 2', True)
440 check('1 > 2', False)
441
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300442 def test_expr_bignum(self):
443 tcl = self.interp
444 for i in self.get_integers():
445 result = tcl.call('expr', str(i))
446 if self.wantobjects:
447 self.assertEqual(result, i)
448 self.assertIsInstance(result, int)
449 else:
450 self.assertEqual(result, str(i))
451 self.assertIsInstance(result, str)
Serhiy Storchaka156b7f72020-12-29 12:55:55 +0200452 if get_tk_patchlevel() < (8, 5): # bignum was added in Tcl 8.5
Serhiy Storchaka2379d542015-04-02 20:07:09 +0300453 self.assertRaises(TclError, tcl.call, 'expr', str(2**1000))
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300454
Serhiy Storchakadf4bb462013-02-07 15:40:03 +0200455 def test_passing_values(self):
456 def passValue(value):
457 return self.interp.call('set', '_', value)
458
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200459 self.assertEqual(passValue(True), True if self.wantobjects else '1')
460 self.assertEqual(passValue(False), False if self.wantobjects else '0')
Serhiy Storchakadf4bb462013-02-07 15:40:03 +0200461 self.assertEqual(passValue('string'), 'string')
462 self.assertEqual(passValue('string\u20ac'), 'string\u20ac')
Serhiy Storchaka06cb94b2019-10-04 13:09:52 +0300463 self.assertEqual(passValue('string\U0001f4bb'), 'string\U0001f4bb')
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200464 self.assertEqual(passValue('str\x00ing'), 'str\x00ing')
465 self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd')
466 self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac')
Serhiy Storchaka06cb94b2019-10-04 13:09:52 +0300467 self.assertEqual(passValue('str\x00ing\U0001f4bb'),
468 'str\x00ing\U0001f4bb')
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200469 if sys.platform != 'win32':
470 self.assertEqual(passValue('<\udce2\udc82\udcac>'),
471 '<\u20ac>')
472 self.assertEqual(passValue('<\udced\udca0\udcbd\udced\udcb2\udcbb>'),
473 '<\U0001f4bb>')
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300474 self.assertEqual(passValue(b'str\x00ing'),
475 b'str\x00ing' if self.wantobjects else 'str\x00ing')
476 self.assertEqual(passValue(b'str\xc0\x80ing'),
477 b'str\xc0\x80ing' if self.wantobjects else 'str\xc0\x80ing')
478 self.assertEqual(passValue(b'str\xbding'),
479 b'str\xbding' if self.wantobjects else 'str\xbding')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300480 for i in self.get_integers():
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200481 self.assertEqual(passValue(i), i if self.wantobjects else str(i))
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300482 if tcl_version < (8, 5): # bignum was added in Tcl 8.5
483 self.assertEqual(passValue(2**1000), str(2**1000))
Serhiy Storchakadf4bb462013-02-07 15:40:03 +0200484 for f in (0.0, 1.0, -1.0, 1/3,
485 sys.float_info.min, sys.float_info.max,
486 -sys.float_info.min, -sys.float_info.max):
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200487 if self.wantobjects:
Serhiy Storchakadf4bb462013-02-07 15:40:03 +0200488 self.assertEqual(passValue(f), f)
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200489 else:
490 self.assertEqual(float(passValue(f)), f)
491 if self.wantobjects:
492 f = passValue(float('nan'))
493 self.assertNotEqual(f, f)
494 self.assertEqual(passValue(float('inf')), float('inf'))
495 self.assertEqual(passValue(-float('inf')), -float('inf'))
496 else:
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200497 self.assertEqual(float(passValue(float('inf'))), float('inf'))
498 self.assertEqual(float(passValue(-float('inf'))), -float('inf'))
Serhiy Storchaka6f1435c2014-07-07 14:57:08 +0300499 # XXX NaN representation can be not parsable by float()
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200500 self.assertEqual(passValue((1, '2', (3.4,))),
501 (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
Serhiy Storchaka2b00c492014-05-21 17:12:21 +0300502 self.assertEqual(passValue(['a', ['b', 'c']]),
503 ('a', ('b', 'c')) if self.wantobjects else 'a {b c}')
Martin v. Löwis2d5157e2010-06-04 19:50:26 +0000504
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200505 def test_user_command(self):
506 result = None
507 def testfunc(arg):
508 nonlocal result
509 result = arg
510 return arg
511 self.interp.createcommand('testfunc', testfunc)
Antoine Pitrou220cc212014-02-23 19:39:06 +0100512 self.addCleanup(self.interp.tk.deletecommand, 'testfunc')
Serhiy Storchakad6ec3092014-08-18 17:47:29 +0300513 def check(value, expected=None, *, eq=self.assertEqual):
514 if expected is None:
515 expected = value
516 nonlocal result
517 result = None
Serhiy Storchakabdf0cb52014-01-23 16:48:44 +0200518 r = self.interp.call('testfunc', value)
519 self.assertIsInstance(result, str)
520 eq(result, expected)
521 self.assertIsInstance(r, str)
522 eq(r, expected)
523 def float_eq(actual, expected):
Serhiy Storchakabdf0cb52014-01-23 16:48:44 +0200524 self.assertAlmostEqual(float(actual), expected,
525 delta=abs(expected) * 1e-10)
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200526
527 check(True, '1')
528 check(False, '0')
Serhiy Storchakad6ec3092014-08-18 17:47:29 +0300529 check('string')
530 check('string\xbd')
531 check('string\u20ac')
Serhiy Storchaka06cb94b2019-10-04 13:09:52 +0300532 check('string\U0001f4bb')
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200533 if sys.platform != 'win32':
534 check('<\udce2\udc82\udcac>', '<\u20ac>')
535 check('<\udced\udca0\udcbd\udced\udcb2\udcbb>', '<\U0001f4bb>')
Serhiy Storchakaabf68ce2014-09-11 10:57:13 +0300536 check('')
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200537 check(b'string', 'string')
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300538 check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
539 check(b'string\xbd', 'string\xbd')
Serhiy Storchakaabf68ce2014-09-11 10:57:13 +0300540 check(b'', '')
Serhiy Storchakad6ec3092014-08-18 17:47:29 +0300541 check('str\x00ing')
542 check('str\x00ing\xbd')
543 check('str\x00ing\u20ac')
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300544 check(b'str\x00ing', 'str\x00ing')
545 check(b'str\xc0\x80ing', 'str\xc0\x80ing')
546 check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac')
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300547 for i in self.get_integers():
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200548 check(i, str(i))
Serhiy Storchakaea134da2015-04-02 18:46:50 +0300549 if tcl_version < (8, 5): # bignum was added in Tcl 8.5
550 check(2**1000, str(2**1000))
Serhiy Storchakabdf0cb52014-01-23 16:48:44 +0200551 for f in (0.0, 1.0, -1.0):
552 check(f, repr(f))
553 for f in (1/3.0, sys.float_info.min, sys.float_info.max,
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200554 -sys.float_info.min, -sys.float_info.max):
Serhiy Storchakad6ec3092014-08-18 17:47:29 +0300555 check(f, eq=float_eq)
556 check(float('inf'), eq=float_eq)
557 check(-float('inf'), eq=float_eq)
Serhiy Storchaka6f1435c2014-07-07 14:57:08 +0300558 # XXX NaN representation can be not parsable by float()
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200559 check((), '')
560 check((1, (2,), (3, 4), '5 6', ()), '1 2 {3 4} {5 6} {}')
Serhiy Storchaka2b00c492014-05-21 17:12:21 +0300561 check([1, [2,], [3, 4], '5 6', []], '1 2 {3 4} {5 6} {}')
Serhiy Storchaka4b730162014-01-23 09:44:05 +0200562
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300563 def test_splitlist(self):
564 splitlist = self.interp.tk.splitlist
565 call = self.interp.tk.call
566 self.assertRaises(TypeError, splitlist)
567 self.assertRaises(TypeError, splitlist, 'a', 'b')
568 self.assertRaises(TypeError, splitlist, 2)
569 testcases = [
570 ('2', ('2',)),
571 ('', ()),
572 ('{}', ('',)),
573 ('""', ('',)),
574 ('a\n b\t\r c\n ', ('a', 'b', 'c')),
575 (b'a\n b\t\r c\n ', ('a', 'b', 'c')),
576 ('a \u20ac', ('a', '\u20ac')),
Serhiy Storchaka06cb94b2019-10-04 13:09:52 +0300577 ('a \U0001f4bb', ('a', '\U0001f4bb')),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300578 (b'a \xe2\x82\xac', ('a', '\u20ac')),
Serhiy Storchakaa26215d2020-11-15 18:16:59 +0200579 (b'a \xf0\x9f\x92\xbb', ('a', '\U0001f4bb')),
580 (b'a \xed\xa0\xbd\xed\xb2\xbb', ('a', '\U0001f4bb')),
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200581 (b'a\xc0\x80b c\xc0\x80d', ('a\x00b', 'c\x00d')),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300582 ('a {b c}', ('a', 'b c')),
583 (r'a b\ c', ('a', 'b c')),
584 (('a', 'b c'), ('a', 'b c')),
585 ('a 2', ('a', '2')),
586 (('a', 2), ('a', 2)),
587 ('a 3.4', ('a', '3.4')),
588 (('a', 3.4), ('a', 3.4)),
589 ((), ()),
Serhiy Storchaka2b00c492014-05-21 17:12:21 +0300590 ([], ()),
591 (['a', ['b', 'c']], ('a', ['b', 'c'])),
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200592 (call('list', 1, '2', (3.4,)),
593 (1, '2', (3.4,)) if self.wantobjects else
594 ('1', '2', '3.4')),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300595 ]
Victor Stinnerece38d92014-09-04 09:53:16 +0200596 tk_patchlevel = get_tk_patchlevel()
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300597 if tcl_version >= (8, 5):
Victor Stinnerece38d92014-09-04 09:53:16 +0200598 if not self.wantobjects or tk_patchlevel < (8, 5, 5):
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200599 # Before 8.5.5 dicts were converted to lists through string
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300600 expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4')
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200601 else:
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300602 expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,))
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300603 testcases += [
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200604 (call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
605 expected),
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300606 ]
Victor Stinnerece38d92014-09-04 09:53:16 +0200607 dbg_info = ('want objects? %s, Tcl version: %s, Tk patchlevel: %s'
608 % (self.wantobjects, tcl_version, tk_patchlevel))
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300609 for arg, res in testcases:
Victor Stinnerece38d92014-09-04 09:53:16 +0200610 self.assertEqual(splitlist(arg), res,
611 'arg=%a, %s' % (arg, dbg_info))
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300612 self.assertRaises(TclError, splitlist, '{')
613
614 def test_split(self):
615 split = self.interp.tk.split
616 call = self.interp.tk.call
Serhiy Storchakad05b0002019-10-08 14:31:35 +0300617 with warnings.catch_warnings():
618 warnings.filterwarnings('ignore', r'\bsplit\b.*\bsplitlist\b',
619 DeprecationWarning)
620 self.assertRaises(TypeError, split)
621 self.assertRaises(TypeError, split, 'a', 'b')
622 self.assertRaises(TypeError, split, 2)
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300623 testcases = [
624 ('2', '2'),
625 ('', ''),
626 ('{}', ''),
627 ('""', ''),
628 ('{', '{'),
629 ('a\n b\t\r c\n ', ('a', 'b', 'c')),
630 (b'a\n b\t\r c\n ', ('a', 'b', 'c')),
631 ('a \u20ac', ('a', '\u20ac')),
632 (b'a \xe2\x82\xac', ('a', '\u20ac')),
Serhiy Storchaka1317e142014-02-03 21:24:07 +0200633 (b'a\xc0\x80b', 'a\x00b'),
634 (b'a\xc0\x80b c\xc0\x80d', ('a\x00b', 'c\x00d')),
635 (b'{a\xc0\x80b c\xc0\x80d', '{a\x00b c\x00d'),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300636 ('a {b c}', ('a', ('b', 'c'))),
637 (r'a b\ c', ('a', ('b', 'c'))),
638 (('a', b'b c'), ('a', ('b', 'c'))),
639 (('a', 'b c'), ('a', ('b', 'c'))),
640 ('a 2', ('a', '2')),
641 (('a', 2), ('a', 2)),
642 ('a 3.4', ('a', '3.4')),
643 (('a', 3.4), ('a', 3.4)),
644 (('a', (2, 3.4)), ('a', (2, 3.4))),
645 ((), ()),
Serhiy Storchaka2b00c492014-05-21 17:12:21 +0300646 ([], ()),
647 (['a', 'b c'], ('a', ('b', 'c'))),
648 (['a', ['b', 'c']], ('a', ('b', 'c'))),
Serhiy Storchakacc4290b2013-12-25 17:29:01 +0200649 (call('list', 1, '2', (3.4,)),
650 (1, '2', (3.4,)) if self.wantobjects else
651 ('1', '2', '3.4')),
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300652 ]
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300653 if tcl_version >= (8, 5):
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200654 if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
655 # Before 8.5.5 dicts were converted to lists through string
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300656 expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4')
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200657 else:
Serhiy Storchaka74596a82014-07-30 18:33:13 +0300658 expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,))
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300659 testcases += [
660 (call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)),
Serhiy Storchaka92af06b2014-02-02 23:04:24 +0200661 expected),
Serhiy Storchakadfa689b2013-09-08 20:29:37 +0300662 ]
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300663 for arg, res in testcases:
Serhiy Storchakad05b0002019-10-08 14:31:35 +0300664 with self.assertWarns(DeprecationWarning):
665 self.assertEqual(split(arg), res, msg=arg)
Serhiy Storchaka275d5fd2013-07-11 20:34:47 +0300666
Serhiy Storchaka8f0a1d02014-09-06 22:47:58 +0300667 def test_splitdict(self):
668 splitdict = tkinter._splitdict
669 tcl = self.interp.tk
670
671 arg = '-a {1 2 3} -something foo status {}'
672 self.assertEqual(splitdict(tcl, arg, False),
673 {'-a': '1 2 3', '-something': 'foo', 'status': ''})
674 self.assertEqual(splitdict(tcl, arg),
675 {'a': '1 2 3', 'something': 'foo', 'status': ''})
676
677 arg = ('-a', (1, 2, 3), '-something', 'foo', 'status', '{}')
678 self.assertEqual(splitdict(tcl, arg, False),
679 {'-a': (1, 2, 3), '-something': 'foo', 'status': '{}'})
680 self.assertEqual(splitdict(tcl, arg),
681 {'a': (1, 2, 3), 'something': 'foo', 'status': '{}'})
682
683 self.assertRaises(RuntimeError, splitdict, tcl, '-a b -c ')
684 self.assertRaises(RuntimeError, splitdict, tcl, ('-a', 'b', '-c'))
685
686 arg = tcl.call('list',
687 '-a', (1, 2, 3), '-something', 'foo', 'status', ())
688 self.assertEqual(splitdict(tcl, arg),
689 {'a': (1, 2, 3) if self.wantobjects else '1 2 3',
690 'something': 'foo', 'status': ''})
691
692 if tcl_version >= (8, 5):
693 arg = tcl.call('dict', 'create',
694 '-a', (1, 2, 3), '-something', 'foo', 'status', ())
695 if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5):
696 # Before 8.5.5 dicts were converted to lists through string
697 expected = {'a': '1 2 3', 'something': 'foo', 'status': ''}
698 else:
699 expected = {'a': (1, 2, 3), 'something': 'foo', 'status': ''}
700 self.assertEqual(splitdict(tcl, arg), expected)
701
Serhiy Storchaka5bb5bbf2018-06-30 09:20:28 +0300702 def test_join(self):
703 join = tkinter._join
704 tcl = self.interp.tk
705 def unpack(s):
706 return tcl.call('lindex', s, 0)
707 def check(value):
708 self.assertEqual(unpack(join([value])), value)
709 self.assertEqual(unpack(join([value, 0])), value)
710 self.assertEqual(unpack(unpack(join([[value]]))), value)
711 self.assertEqual(unpack(unpack(join([[value, 0]]))), value)
712 self.assertEqual(unpack(unpack(join([[value], 0]))), value)
713 self.assertEqual(unpack(unpack(join([[value, 0], 0]))), value)
714 check('')
715 check('spam')
716 check('sp am')
717 check('sp\tam')
718 check('sp\nam')
719 check(' \t\n')
720 check('{spam}')
721 check('{sp am}')
722 check('"spam"')
723 check('"sp am"')
724 check('{"spam"}')
725 check('"{spam}"')
726 check('sp\\am')
727 check('"sp\\am"')
728 check('"{}" "{}"')
729 check('"\\')
730 check('"{')
731 check('"}')
732 check('\n\\')
733 check('\n{')
734 check('\n}')
735 check('\\\n')
736 check('{\n')
737 check('}\n')
738
Serhiy Storchakae3f1b092016-05-08 20:46:22 +0300739 def test_new_tcl_obj(self):
740 self.assertRaises(TypeError, _tkinter.Tcl_Obj)
Neal Norwitz63dfece2004-02-19 02:37:29 +0000741
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300742class BigmemTclTest(unittest.TestCase):
743
744 def setUp(self):
745 self.interp = Tcl()
746
Serhiy Storchaka5cfc79d2014-02-07 10:06:39 +0200747 @support.cpython_only
748 @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX")
749 @support.bigmemtest(size=INT_MAX + 1, memuse=5, dry_run=False)
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300750 def test_huge_string_call(self, size):
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300751 value = ' ' * size
Serhiy Storchaka27c623c2017-10-03 22:39:55 +0300752 self.assertRaises(OverflowError, self.interp.call, 'string', 'index', value, 0)
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300753
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300754 @support.cpython_only
755 @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX")
Serhiy Storchaka27c623c2017-10-03 22:39:55 +0300756 @support.bigmemtest(size=INT_MAX + 1, memuse=2, dry_run=False)
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300757 def test_huge_string_builtins(self, size):
Serhiy Storchaka27c623c2017-10-03 22:39:55 +0300758 tk = self.interp.tk
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300759 value = '1' + ' ' * size
Serhiy Storchaka27c623c2017-10-03 22:39:55 +0300760 self.assertRaises(OverflowError, tk.getint, value)
761 self.assertRaises(OverflowError, tk.getdouble, value)
762 self.assertRaises(OverflowError, tk.getboolean, value)
763 self.assertRaises(OverflowError, tk.eval, value)
764 self.assertRaises(OverflowError, tk.evalfile, value)
765 self.assertRaises(OverflowError, tk.record, value)
766 self.assertRaises(OverflowError, tk.adderrorinfo, value)
767 self.assertRaises(OverflowError, tk.setvar, value, 'x', 'a')
768 self.assertRaises(OverflowError, tk.setvar, 'x', value, 'a')
769 self.assertRaises(OverflowError, tk.unsetvar, value)
770 self.assertRaises(OverflowError, tk.unsetvar, 'x', value)
771 self.assertRaises(OverflowError, tk.adderrorinfo, value)
772 self.assertRaises(OverflowError, tk.exprstring, value)
773 self.assertRaises(OverflowError, tk.exprlong, value)
774 self.assertRaises(OverflowError, tk.exprboolean, value)
775 self.assertRaises(OverflowError, tk.splitlist, value)
776 self.assertRaises(OverflowError, tk.split, value)
777 self.assertRaises(OverflowError, tk.createcommand, value, max)
778 self.assertRaises(OverflowError, tk.deletecommand, value)
779
780 @support.cpython_only
781 @unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX, "needs UINT_MAX < SIZE_MAX")
782 @support.bigmemtest(size=INT_MAX + 1, memuse=6, dry_run=False)
783 def test_huge_string_builtins2(self, size):
784 # These commands require larger memory for possible error messages
785 tk = self.interp.tk
786 value = '1' + ' ' * size
787 self.assertRaises(OverflowError, tk.evalfile, value)
788 self.assertRaises(OverflowError, tk.unsetvar, value)
789 self.assertRaises(OverflowError, tk.unsetvar, 'x', value)
Serhiy Storchaka79851d72014-05-30 14:24:03 +0300790
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300791
Serhiy Storchaka8db18232013-11-20 17:43:49 +0200792def setUpModule():
793 if support.verbose:
794 tcl = Tcl()
795 print('patchlevel =', tcl.call('info', 'patchlevel'))
796
797
Neal Norwitz63dfece2004-02-19 02:37:29 +0000798def test_main():
Serhiy Storchaka9e6b9752013-08-21 21:38:21 +0300799 support.run_unittest(TclTest, TkinterTest, BigmemTclTest)
Neal Norwitz63dfece2004-02-19 02:37:29 +0000800
David Aschere2b4b322004-02-18 05:59:53 +0000801if __name__ == "__main__":
Neal Norwitz63dfece2004-02-19 02:37:29 +0000802 test_main()