Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Lib/test/test_tcl.py

Issue 16840: Tkinter doesn't support large integers
Patch Set: Created 4 years, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Modules/_tkinter.c » ('j') | Modules/_tkinter.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import unittest 1 import unittest
2 import sys 2 import sys
3 import os 3 import os
4 from test import support 4 from test import support
5 5
6 # Skip this test if the _tkinter module wasn't built. 6 # Skip this test if the _tkinter module wasn't built.
7 _tkinter = support.import_module('_tkinter') 7 _tkinter = support.import_module('_tkinter')
8 8
9 # Make sure tkinter._fix runs to set up the environment 9 # Make sure tkinter._fix runs to set up the environment
10 tkinter = support.import_fresh_module('tkinter') 10 tkinter = support.import_fresh_module('tkinter')
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 tcl.unsetvar('a(1)') 128 tcl.unsetvar('a(1)')
129 self.assertEqual(tcl.eval('info exists a(1)'),'0') 129 self.assertEqual(tcl.eval('info exists a(1)'),'0')
130 self.assertEqual(tcl.eval('info exists a(2)'),'1') 130 self.assertEqual(tcl.eval('info exists a(2)'),'1')
131 131
132 def testUnsetVarException(self): 132 def testUnsetVarException(self):
133 tcl = self.interp 133 tcl = self.interp
134 self.assertRaises(TclError,tcl.unsetvar,'a') 134 self.assertRaises(TclError,tcl.unsetvar,'a')
135 135
136 def test_getint(self): 136 def test_getint(self):
137 tcl = self.interp.tk 137 tcl = self.interp.tk
138 self.assertEqual(tcl.getint(' 42 '), 42) 138 integers = (0, 1, -1, 2**31-1, -2**31, 2**31, -2**31-1, 2**63-1, -2**63)
139 if tcl_version >= (8, 5):
haypo 2015/03/27 11:16:37 Hum, please add a comment explaining why larger in
storchaka 2015/03/27 12:01:44 This type was added in Tcl 8.5. Needed also a che
140 integers += (2**63, -2**63-1, 2**1000, -2**1000)
141 for i in integers:
142 self.assertEqual(tcl.getint(' %d ' % i), i)
143 self.assertEqual(tcl.getint(' %#o ' % i), i)
144 self.assertEqual(tcl.getint(' %#x ' % i), i)
139 self.assertEqual(tcl.getint(42), 42) 145 self.assertEqual(tcl.getint(42), 42)
140 self.assertRaises(TypeError, tcl.getint) 146 self.assertRaises(TypeError, tcl.getint)
141 self.assertRaises(TypeError, tcl.getint, '42', '10') 147 self.assertRaises(TypeError, tcl.getint, '42', '10')
142 self.assertRaises(TypeError, tcl.getint, b'42') 148 self.assertRaises(TypeError, tcl.getint, b'42')
143 self.assertRaises(TypeError, tcl.getint, 42.0) 149 self.assertRaises(TypeError, tcl.getint, 42.0)
144 self.assertRaises(TclError, tcl.getint, 'a') 150 self.assertRaises(TclError, tcl.getint, 'a')
145 self.assertRaises((TypeError, ValueError, TclError), 151 self.assertRaises((TypeError, ValueError, TclError),
146 tcl.getint, '42\0') 152 tcl.getint, '42\0')
147 self.assertRaises((UnicodeEncodeError, ValueError, TclError), 153 self.assertRaises((UnicodeEncodeError, ValueError, TclError),
148 tcl.getint, '42\ud800') 154 tcl.getint, '42\ud800')
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 self.assertIn('tkinter', f.read()) 243 self.assertIn('tkinter', f.read())
238 # exit code must be zero 244 # exit code must be zero
239 self.assertEqual(f.close(), None) 245 self.assertEqual(f.close(), None)
240 246
241 def test_exprstring(self): 247 def test_exprstring(self):
242 tcl = self.interp 248 tcl = self.interp
243 tcl.call('set', 'a', 3) 249 tcl.call('set', 'a', 3)
244 tcl.call('set', 'b', 6) 250 tcl.call('set', 'b', 6)
245 def check(expr, expected): 251 def check(expr, expected):
246 result = tcl.exprstring(expr) 252 result = tcl.exprstring(expr)
253 self.assertIsInstance(result, str)
247 self.assertEqual(result, expected) 254 self.assertEqual(result, expected)
248 self.assertIsInstance(result, str)
249 255
250 self.assertRaises(TypeError, tcl.exprstring) 256 self.assertRaises(TypeError, tcl.exprstring)
251 self.assertRaises(TypeError, tcl.exprstring, '8.2', '+6') 257 self.assertRaises(TypeError, tcl.exprstring, '8.2', '+6')
252 self.assertRaises(TypeError, tcl.exprstring, b'8.2 + 6') 258 self.assertRaises(TypeError, tcl.exprstring, b'8.2 + 6')
253 self.assertRaises(TclError, tcl.exprstring, 'spam') 259 self.assertRaises(TclError, tcl.exprstring, 'spam')
254 check('', '0') 260 check('', '0')
255 check('8.2 + 6', '14.2') 261 check('8.2 + 6', '14.2')
256 check('3.1 + $a', '6.1') 262 check('3.1 + $a', '6.1')
257 check('2 + "$a.$b"', '5.6') 263 check('2 + "$a.$b"', '5.6')
258 check('4*[llength "6 2"]', '8') 264 check('4*[llength "6 2"]', '8')
(...skipping 13 matching lines...) Expand all
272 check(r'"a\0b"', 'a\x00b') 278 check(r'"a\0b"', 'a\x00b')
273 if tcl_version >= (8, 5): 279 if tcl_version >= (8, 5):
274 check('2**64', str(2**64)) 280 check('2**64', str(2**64))
275 281
276 def test_exprdouble(self): 282 def test_exprdouble(self):
277 tcl = self.interp 283 tcl = self.interp
278 tcl.call('set', 'a', 3) 284 tcl.call('set', 'a', 3)
279 tcl.call('set', 'b', 6) 285 tcl.call('set', 'b', 6)
280 def check(expr, expected): 286 def check(expr, expected):
281 result = tcl.exprdouble(expr) 287 result = tcl.exprdouble(expr)
288 self.assertIsInstance(result, float)
282 self.assertEqual(result, expected) 289 self.assertEqual(result, expected)
283 self.assertIsInstance(result, float)
284 290
285 self.assertRaises(TypeError, tcl.exprdouble) 291 self.assertRaises(TypeError, tcl.exprdouble)
286 self.assertRaises(TypeError, tcl.exprdouble, '8.2', '+6') 292 self.assertRaises(TypeError, tcl.exprdouble, '8.2', '+6')
287 self.assertRaises(TypeError, tcl.exprdouble, b'8.2 + 6') 293 self.assertRaises(TypeError, tcl.exprdouble, b'8.2 + 6')
288 self.assertRaises(TclError, tcl.exprdouble, 'spam') 294 self.assertRaises(TclError, tcl.exprdouble, 'spam')
289 check('', 0.0) 295 check('', 0.0)
290 check('8.2 + 6', 14.2) 296 check('8.2 + 6', 14.2)
291 check('3.1 + $a', 6.1) 297 check('3.1 + $a', 6.1)
292 check('2 + "$a.$b"', 5.6) 298 check('2 + "$a.$b"', 5.6)
293 check('4*[llength "6 2"]', 8.0) 299 check('4*[llength "6 2"]', 8.0)
(...skipping 10 matching lines...) Expand all
304 self.assertRaises(TclError, tcl.exprdouble, '"abc"') 310 self.assertRaises(TclError, tcl.exprdouble, '"abc"')
305 if tcl_version >= (8, 5): 311 if tcl_version >= (8, 5):
306 check('2**64', float(2**64)) 312 check('2**64', float(2**64))
307 313
308 def test_exprlong(self): 314 def test_exprlong(self):
309 tcl = self.interp 315 tcl = self.interp
310 tcl.call('set', 'a', 3) 316 tcl.call('set', 'a', 3)
311 tcl.call('set', 'b', 6) 317 tcl.call('set', 'b', 6)
312 def check(expr, expected): 318 def check(expr, expected):
313 result = tcl.exprlong(expr) 319 result = tcl.exprlong(expr)
320 self.assertIsInstance(result, int)
314 self.assertEqual(result, expected) 321 self.assertEqual(result, expected)
315 self.assertIsInstance(result, int)
316 322
317 self.assertRaises(TypeError, tcl.exprlong) 323 self.assertRaises(TypeError, tcl.exprlong)
318 self.assertRaises(TypeError, tcl.exprlong, '8.2', '+6') 324 self.assertRaises(TypeError, tcl.exprlong, '8.2', '+6')
319 self.assertRaises(TypeError, tcl.exprlong, b'8.2 + 6') 325 self.assertRaises(TypeError, tcl.exprlong, b'8.2 + 6')
320 self.assertRaises(TclError, tcl.exprlong, 'spam') 326 self.assertRaises(TclError, tcl.exprlong, 'spam')
321 check('', 0) 327 check('', 0)
322 check('8.2 + 6', 14) 328 check('8.2 + 6', 14)
323 check('3.1 + $a', 6) 329 check('3.1 + $a', 6)
324 check('2 + "$a.$b"', 5) 330 check('2 + "$a.$b"', 5)
325 check('4*[llength "6 2"]', 8) 331 check('4*[llength "6 2"]', 8)
(...skipping 10 matching lines...) Expand all
336 self.assertRaises(TclError, tcl.exprlong, '"abc"') 342 self.assertRaises(TclError, tcl.exprlong, '"abc"')
337 if tcl_version >= (8, 5): 343 if tcl_version >= (8, 5):
338 self.assertRaises(TclError, tcl.exprlong, '2**64') 344 self.assertRaises(TclError, tcl.exprlong, '2**64')
339 345
340 def test_exprboolean(self): 346 def test_exprboolean(self):
341 tcl = self.interp 347 tcl = self.interp
342 tcl.call('set', 'a', 3) 348 tcl.call('set', 'a', 3)
343 tcl.call('set', 'b', 6) 349 tcl.call('set', 'b', 6)
344 def check(expr, expected): 350 def check(expr, expected):
345 result = tcl.exprboolean(expr) 351 result = tcl.exprboolean(expr)
346 self.assertEqual(result, expected)
347 self.assertIsInstance(result, int) 352 self.assertIsInstance(result, int)
348 self.assertNotIsInstance(result, bool) 353 self.assertNotIsInstance(result, bool)
354 self.assertEqual(result, expected)
349 355
350 self.assertRaises(TypeError, tcl.exprboolean) 356 self.assertRaises(TypeError, tcl.exprboolean)
351 self.assertRaises(TypeError, tcl.exprboolean, '8.2', '+6') 357 self.assertRaises(TypeError, tcl.exprboolean, '8.2', '+6')
352 self.assertRaises(TypeError, tcl.exprboolean, b'8.2 + 6') 358 self.assertRaises(TypeError, tcl.exprboolean, b'8.2 + 6')
353 self.assertRaises(TclError, tcl.exprboolean, 'spam') 359 self.assertRaises(TclError, tcl.exprboolean, 'spam')
354 check('', False) 360 check('', False)
355 for value in ('0', 'false', 'no', 'off'): 361 for value in ('0', 'false', 'no', 'off'):
356 check(value, False) 362 check(value, False)
357 check('"%s"' % value, False) 363 check('"%s"' % value, False)
358 check('{%s}' % value, False) 364 check('{%s}' % value, False)
(...skipping 11 matching lines...) Expand all
370 check('5 / 4', True) 376 check('5 / 4', True)
371 check('5 / 4.0', True) 377 check('5 / 4.0', True)
372 check('5 / ( [string length "abcd"] + 0.0 )', True) 378 check('5 / ( [string length "abcd"] + 0.0 )', True)
373 check('20.0/5.0', True) 379 check('20.0/5.0', True)
374 check('"0x03" > "2"', True) 380 check('"0x03" > "2"', True)
375 check('[string length "a\xbd\u20ac"]', True) 381 check('[string length "a\xbd\u20ac"]', True)
376 check(r'[string length "a\xbd\u20ac"]', True) 382 check(r'[string length "a\xbd\u20ac"]', True)
377 self.assertRaises(TclError, tcl.exprboolean, '"abc"') 383 self.assertRaises(TclError, tcl.exprboolean, '"abc"')
378 if tcl_version >= (8, 5): 384 if tcl_version >= (8, 5):
379 check('2**64', True) 385 check('2**64', True)
386
387 def test_expr_bignum(self):
388 tcl = self.interp
389 integers = (2**31-1, -2**31, 2**31, -2**31-1, 2**63-1, -2**63)
390 if tcl_version >= (8, 5):
391 integers += (2**63, -2**63-1, 2**1000, -2**1000)
392 for i in integers:
393 result = tcl.call('expr', str(i))
394 if self.wantobjects:
395 self.assertIsInstance(result, int)
396 self.assertEqual(result, i)
397 else:
398 self.assertIsInstance(result, str)
399 self.assertEqual(result, str(i))
380 400
381 def test_passing_values(self): 401 def test_passing_values(self):
382 def passValue(value): 402 def passValue(value):
383 return self.interp.call('set', '_', value) 403 return self.interp.call('set', '_', value)
384 404
385 self.assertEqual(passValue(True), True if self.wantobjects else '1') 405 self.assertEqual(passValue(True), True if self.wantobjects else '1')
386 self.assertEqual(passValue(False), False if self.wantobjects else '0') 406 self.assertEqual(passValue(False), False if self.wantobjects else '0')
387 self.assertEqual(passValue('string'), 'string') 407 self.assertEqual(passValue('string'), 'string')
388 self.assertEqual(passValue('string\u20ac'), 'string\u20ac') 408 self.assertEqual(passValue('string\u20ac'), 'string\u20ac')
389 self.assertEqual(passValue('str\x00ing'), 'str\x00ing') 409 self.assertEqual(passValue('str\x00ing'), 'str\x00ing')
390 self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd') 410 self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd')
391 self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac') 411 self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac')
392 self.assertEqual(passValue(b'str\x00ing'), 412 self.assertEqual(passValue(b'str\x00ing'),
393 b'str\x00ing' if self.wantobjects else 'str\x00ing') 413 b'str\x00ing' if self.wantobjects else 'str\x00ing')
394 self.assertEqual(passValue(b'str\xc0\x80ing'), 414 self.assertEqual(passValue(b'str\xc0\x80ing'),
395 b'str\xc0\x80ing' if self.wantobjects else 'str\xc0\x80 ing') 415 b'str\xc0\x80ing' if self.wantobjects else 'str\xc0\x80 ing')
396 self.assertEqual(passValue(b'str\xbding'), 416 self.assertEqual(passValue(b'str\xbding'),
397 b'str\xbding' if self.wantobjects else 'str\xbding') 417 b'str\xbding' if self.wantobjects else 'str\xbding')
398 for i in (0, 1, -1, 2**31-1, -2**31): 418 integers = (0, 1, -1, 2**31-1, -2**31, 2**31, -2**31-1, 2**63-1, -2**63)
419 if tcl_version >= (8, 5):
420 integers += (2**63, -2**63-1, 2**1000, -2**1000)
421 for i in integers:
399 self.assertEqual(passValue(i), i if self.wantobjects else str(i)) 422 self.assertEqual(passValue(i), i if self.wantobjects else str(i))
400 for f in (0.0, 1.0, -1.0, 1/3, 423 for f in (0.0, 1.0, -1.0, 1/3,
401 sys.float_info.min, sys.float_info.max, 424 sys.float_info.min, sys.float_info.max,
402 -sys.float_info.min, -sys.float_info.max): 425 -sys.float_info.min, -sys.float_info.max):
403 if self.wantobjects: 426 if self.wantobjects:
404 self.assertEqual(passValue(f), f) 427 self.assertEqual(passValue(f), f)
405 else: 428 else:
406 self.assertEqual(float(passValue(f)), f) 429 self.assertEqual(float(passValue(f)), f)
407 if self.wantobjects: 430 if self.wantobjects:
408 f = passValue(float('nan')) 431 f = passValue(float('nan'))
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 check(b'string', 'string') 472 check(b'string', 'string')
450 check(b'string\xe2\x82\xac', 'string\xe2\x82\xac') 473 check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
451 check(b'string\xbd', 'string\xbd') 474 check(b'string\xbd', 'string\xbd')
452 check(b'', '') 475 check(b'', '')
453 check('str\x00ing') 476 check('str\x00ing')
454 check('str\x00ing\xbd') 477 check('str\x00ing\xbd')
455 check('str\x00ing\u20ac') 478 check('str\x00ing\u20ac')
456 check(b'str\x00ing', 'str\x00ing') 479 check(b'str\x00ing', 'str\x00ing')
457 check(b'str\xc0\x80ing', 'str\xc0\x80ing') 480 check(b'str\xc0\x80ing', 'str\xc0\x80ing')
458 check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac') 481 check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac')
459 for i in (0, 1, -1, 2**31-1, -2**31): 482 integers = (0, 1, -1, 2**31-1, -2**31, 2**31, -2**31-1, 2**63-1, -2**63)
haypo 2015/03/27 11:16:37 Hum, you should generate this list in a function t
storchaka 2015/03/27 12:01:44 May be. This list is used in 4 tests, but only in
483 if tcl_version >= (8, 5):
484 integers += (2**63, -2**63-1, 2**1000, -2**1000)
485 for i in integers:
460 check(i, str(i)) 486 check(i, str(i))
461 for f in (0.0, 1.0, -1.0): 487 for f in (0.0, 1.0, -1.0):
462 check(f, repr(f)) 488 check(f, repr(f))
463 for f in (1/3.0, sys.float_info.min, sys.float_info.max, 489 for f in (1/3.0, sys.float_info.min, sys.float_info.max,
464 -sys.float_info.min, -sys.float_info.max): 490 -sys.float_info.min, -sys.float_info.max):
465 check(f, eq=float_eq) 491 check(f, eq=float_eq)
466 check(float('inf'), eq=float_eq) 492 check(float('inf'), eq=float_eq)
467 check(-float('inf'), eq=float_eq) 493 check(-float('inf'), eq=float_eq)
468 # XXX NaN representation can be not parsable by float() 494 # XXX NaN representation can be not parsable by float()
469 check((), '') 495 check((), '')
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 if support.verbose: 671 if support.verbose:
646 tcl = Tcl() 672 tcl = Tcl()
647 print('patchlevel =', tcl.call('info', 'patchlevel')) 673 print('patchlevel =', tcl.call('info', 'patchlevel'))
648 674
649 675
650 def test_main(): 676 def test_main():
651 support.run_unittest(TclTest, TkinterTest, BigmemTclTest) 677 support.run_unittest(TclTest, TkinterTest, BigmemTclTest)
652 678
653 if __name__ == "__main__": 679 if __name__ == "__main__":
654 test_main() 680 test_main()
OLDNEW
« no previous file with comments | « no previous file | Modules/_tkinter.c » ('j') | Modules/_tkinter.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+