summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-23 07:49:42 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-23 07:49:42 (GMT)
commitd869a0b132308e600534cc56d6e11f63e0c85eda (patch)
tree9b571c1bdab368ceb1b251917c78598eed3b0942 /Lib
parent8860443749295acbeecb074be8460113fc478468 (diff)
parent4b730161fde1965796ffefdbdd5601369e5c10c2 (diff)
downloadcpython-d869a0b132308e600534cc56d6e11f63e0c85eda.zip
cpython-d869a0b132308e600534cc56d6e11f63e0c85eda.tar.gz
cpython-d869a0b132308e600534cc56d6e11f63e0c85eda.tar.bz2
Added test_user_command in test_tcl.
It tests the convertion Tcl values to Python values when Tcl calls a command implemented on Python. Currently all values are passed as strings.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_tcl.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
index 2d304d1..6c8ef05 100644
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -192,6 +192,34 @@ class TclTest(unittest.TestCase):
self.assertEqual(passValue((1, '2', (3.4,))),
(1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
+ def test_user_command(self):
+ result = None
+ def testfunc(arg):
+ nonlocal result
+ result = arg
+ return arg
+ self.interp.createcommand('testfunc', testfunc)
+ def check(value, expected):
+ self.assertEqual(self.interp.call('testfunc', value), expected)
+ self.assertEqual(result, expected)
+
+ check(True, '1')
+ check(False, '0')
+ check('string', 'string')
+ check('string\xbd', 'string\xbd')
+ check('string\u20ac', 'string\u20ac')
+ for i in (0, 1, -1, 2**31-1, -2**31):
+ check(i, str(i))
+ for f in (0.0, 1.0, -1.0, 1/3,
+ sys.float_info.min, sys.float_info.max,
+ -sys.float_info.min, -sys.float_info.max):
+ check(f, str(f))
+ check(float('nan'), 'NaN')
+ check(float('inf'), 'Inf')
+ check(-float('inf'), '-Inf')
+ check((), '')
+ check((1, (2,), (3, 4), '5 6', ()), '1 2 {3 4} {5 6} {}')
+
def test_splitlist(self):
splitlist = self.interp.tk.splitlist
call = self.interp.tk.call