Skip to content

Commit 29d8e85

Browse files
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.
1 parent 5924365 commit 29d8e85

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lib/test/test_tcl.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,34 @@ def passValue(value):
204204
self.assertEqual(passValue((1, '2', (3.4,))),
205205
(1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
206206

207+
def test_user_command(self):
208+
result = []
209+
def testfunc(arg):
210+
result.append(arg)
211+
return arg
212+
self.interp.createcommand('testfunc', testfunc)
213+
def check(value, expected):
214+
del result[:]
215+
self.assertEqual(self.interp.call('testfunc', value), expected)
216+
self.assertEqual(result, [expected])
217+
218+
check(True, '1')
219+
check(False, '0')
220+
check('string', 'string')
221+
check('string\xbd', 'string\xbd')
222+
check('string\u20ac', 'string\u20ac')
223+
for i in (0, 1, -1, 2**31-1, -2**31):
224+
check(i, str(i))
225+
for f in (0.0, 1.0, -1.0, 1/3,
226+
sys.float_info.min, sys.float_info.max,
227+
-sys.float_info.min, -sys.float_info.max):
228+
check(f, repr(f))
229+
check(float('nan'), 'NaN')
230+
check(float('inf'), 'Inf')
231+
check(-float('inf'), '-Inf')
232+
check((), '')
233+
check((1, (2,), (3, 4), '5 6', ()), '1 2 {3 4} {5 6} {}')
234+
207235
def test_splitlist(self):
208236
splitlist = self.interp.tk.splitlist
209237
call = self.interp.tk.call

0 commit comments

Comments
 (0)