summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tcl.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-02-03 18:41:34 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-02-03 18:41:34 (GMT)
commitfc055252ebab9a1ecdfc0d04bc9c11168c2db9f7 (patch)
tree994131a3e14c47794099144c4f5eeec88d3495b3 /Lib/test/test_tcl.py
parent3633da239eb3f2582ddac3df97fbc9db4d16252d (diff)
downloadcpython-fc055252ebab9a1ecdfc0d04bc9c11168c2db9f7.zip
cpython-fc055252ebab9a1ecdfc0d04bc9c11168c2db9f7.tar.gz
cpython-fc055252ebab9a1ecdfc0d04bc9c11168c2db9f7.tar.bz2
Issue #20368: Add tests for Tkinter methods exprstring(), exprdouble(),
exprlong() and exprboolean().
Diffstat (limited to 'Lib/test/test_tcl.py')
-rw-r--r--Lib/test/test_tcl.py135
1 files changed, 135 insertions, 0 deletions
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
index 6d422e0..b73a11d 100644
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -177,6 +177,141 @@ class TclTest(unittest.TestCase):
# exit code must be zero
self.assertEqual(f.close(), None)
+ def test_exprstring(self):
+ tcl = self.interp
+ tcl.call('set', 'a', 3)
+ tcl.call('set', 'b', 6)
+ def check(expr, expected):
+ result = tcl.exprstring(expr)
+ self.assertEqual(result, expected)
+ self.assertIsInstance(result, str)
+
+ self.assertRaises(TypeError, tcl.exprstring)
+ self.assertRaises(TypeError, tcl.exprstring, '8.2', '+6')
+ self.assertRaises(TypeError, tcl.exprstring, b'8.2 + 6')
+ self.assertRaises(TclError, tcl.exprstring, 'spam')
+ check('', '0')
+ check('8.2 + 6', '14.2')
+ check('2**64', str(2**64))
+ check('3.1 + $a', '6.1')
+ check('2 + "$a.$b"', '5.6')
+ check('4*[llength "6 2"]', '8')
+ check('{word one} < "word $a"', '0')
+ check('4*2 < 7', '0')
+ check('hypot($a, 4)', '5.0')
+ check('5 / 4', '1')
+ check('5 / 4.0', '1.25')
+ check('5 / ( [string length "abcd"] + 0.0 )', '1.25')
+ check('20.0/5.0', '4.0')
+ check('"0x03" > "2"', '1')
+ check('[string length "a\xbd\u20ac"]', '3')
+ check(r'[string length "a\xbd\u20ac"]', '3')
+ check('"abc"', 'abc')
+ check('"a\xbd\u20ac"', 'a\xbd\u20ac')
+ check(r'"a\xbd\u20ac"', 'a\xbd\u20ac')
+
+ def test_exprdouble(self):
+ tcl = self.interp
+ tcl.call('set', 'a', 3)
+ tcl.call('set', 'b', 6)
+ def check(expr, expected):
+ result = tcl.exprdouble(expr)
+ self.assertEqual(result, expected)
+ self.assertIsInstance(result, float)
+
+ self.assertRaises(TypeError, tcl.exprdouble)
+ self.assertRaises(TypeError, tcl.exprdouble, '8.2', '+6')
+ self.assertRaises(TypeError, tcl.exprdouble, b'8.2 + 6')
+ self.assertRaises(TclError, tcl.exprdouble, 'spam')
+ check('', 0.0)
+ check('8.2 + 6', 14.2)
+ check('2**64', float(2**64))
+ check('3.1 + $a', 6.1)
+ check('2 + "$a.$b"', 5.6)
+ check('4*[llength "6 2"]', 8.0)
+ check('{word one} < "word $a"', 0.0)
+ check('4*2 < 7', 0.0)
+ check('hypot($a, 4)', 5.0)
+ check('5 / 4', 1.0)
+ check('5 / 4.0', 1.25)
+ check('5 / ( [string length "abcd"] + 0.0 )', 1.25)
+ check('20.0/5.0', 4.0)
+ check('"0x03" > "2"', 1.0)
+ check('[string length "a\xbd\u20ac"]', 3.0)
+ check(r'[string length "a\xbd\u20ac"]', 3.0)
+ self.assertRaises(TclError, tcl.exprdouble, '"abc"')
+
+ def test_exprlong(self):
+ tcl = self.interp
+ tcl.call('set', 'a', 3)
+ tcl.call('set', 'b', 6)
+ def check(expr, expected):
+ result = tcl.exprlong(expr)
+ self.assertEqual(result, expected)
+ self.assertIsInstance(result, int)
+
+ self.assertRaises(TypeError, tcl.exprlong)
+ self.assertRaises(TypeError, tcl.exprlong, '8.2', '+6')
+ self.assertRaises(TypeError, tcl.exprlong, b'8.2 + 6')
+ self.assertRaises(TclError, tcl.exprlong, 'spam')
+ check('', 0)
+ check('8.2 + 6', 14)
+ self.assertRaises(TclError, tcl.exprlong, '2**64')
+ check('3.1 + $a', 6)
+ check('2 + "$a.$b"', 5)
+ check('4*[llength "6 2"]', 8)
+ check('{word one} < "word $a"', 0)
+ check('4*2 < 7', 0)
+ check('hypot($a, 4)', 5)
+ check('5 / 4', 1)
+ check('5 / 4.0', 1)
+ check('5 / ( [string length "abcd"] + 0.0 )', 1)
+ check('20.0/5.0', 4)
+ check('"0x03" > "2"', 1)
+ check('[string length "a\xbd\u20ac"]', 3)
+ check(r'[string length "a\xbd\u20ac"]', 3)
+ self.assertRaises(TclError, tcl.exprlong, '"abc"')
+
+ def test_exprboolean(self):
+ tcl = self.interp
+ tcl.call('set', 'a', 3)
+ tcl.call('set', 'b', 6)
+ def check(expr, expected):
+ result = tcl.exprboolean(expr)
+ self.assertEqual(result, expected)
+ self.assertIsInstance(result, int)
+ self.assertNotIsInstance(result, bool)
+
+ self.assertRaises(TypeError, tcl.exprboolean)
+ self.assertRaises(TypeError, tcl.exprboolean, '8.2', '+6')
+ self.assertRaises(TypeError, tcl.exprboolean, b'8.2 + 6')
+ self.assertRaises(TclError, tcl.exprboolean, 'spam')
+ check('', False)
+ for value in ('0', 'false', 'no', 'off'):
+ check(value, False)
+ check('"%s"' % value, False)
+ check('{%s}' % value, False)
+ for value in ('1', 'true', 'yes', 'on'):
+ check(value, True)
+ check('"%s"' % value, True)
+ check('{%s}' % value, True)
+ check('8.2 + 6', True)
+ check('2**64', True)
+ check('3.1 + $a', True)
+ check('2 + "$a.$b"', True)
+ check('4*[llength "6 2"]', True)
+ check('{word one} < "word $a"', False)
+ check('4*2 < 7', False)
+ check('hypot($a, 4)', True)
+ check('5 / 4', True)
+ check('5 / 4.0', True)
+ check('5 / ( [string length "abcd"] + 0.0 )', True)
+ check('20.0/5.0', True)
+ check('"0x03" > "2"', True)
+ check('[string length "a\xbd\u20ac"]', True)
+ check(r'[string length "a\xbd\u20ac"]', True)
+ self.assertRaises(TclError, tcl.exprboolean, '"abc"')
+
def test_passing_values(self):
def passValue(value):
return self.interp.call('set', '_', value)