[Python-checkins] cpython (2.7): Added test_user_command in test_tcl.

serhiy.storchaka python-checkins at python.org
Thu Jan 23 08:59:09 CET 2014


http://hg.python.org/cpython/rev/43f9295f6b99
changeset:   88644:43f9295f6b99
branch:      2.7
parent:      88641:bcfbab86f49a
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Jan 23 09:42:46 2014 +0200
summary:
  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.

files:
  Lib/test/test_tcl.py |  28 ++++++++++++++++++++++++++++
  1 files changed, 28 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -204,6 +204,34 @@
         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 = []
+        def testfunc(arg):
+            result.append(arg)
+            return arg
+        self.interp.createcommand('testfunc', testfunc)
+        def check(value, expected):
+            del result[:]
+            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, repr(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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list