Commit ee6d3d4f authored by Serhiy Storchaka's avatar Serhiy Storchaka

Clean up test_user_command.

parent 68fe151c
......@@ -434,43 +434,42 @@ class TclTest(unittest.TestCase):
return arg
self.interp.createcommand('testfunc', testfunc)
self.addCleanup(self.interp.tk.deletecommand, 'testfunc')
def check(value, expected, expected2=None, eq=self.assertEqual):
if expected2 is None:
expected2 = expected
def check(value, expected=None, eq=self.assertEqual):
if expected is None:
expected = value
del result[:]
r = self.interp.call('testfunc', value)
self.assertEqual(len(result), 1)
self.assertIsInstance(result[0], (str, unicode))
eq(result[0], expected2)
eq(result[0], expected)
self.assertIsInstance(r, (str, unicode))
eq(r, expected2)
eq(r, expected)
def float_eq(actual, expected):
expected = float(expected)
self.assertAlmostEqual(float(actual), expected,
delta=abs(expected) * 1e-10)
check(True, '1')
check(False, '0')
check('string', 'string')
check('string\xbd', 'string\xbd')
check('string\xe2\x82\xac', 'string\xe2\x82\xac', u'string\u20ac')
check(u'string', u'string')
check(u'string\xbd', 'string\xc2\xbd', u'string\xbd')
check(u'string\u20ac', 'string\xe2\x82\xac', u'string\u20ac')
check('str\xc0\x80ing', 'str\xc0\x80ing', u'str\x00ing')
check('str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac', u'str\x00ing\u20ac')
check(u'str\x00ing', 'str\xc0\x80ing', u'str\x00ing')
check(u'str\x00ing\xbd', 'str\xc0\x80ing\xc2\xbd', u'str\x00ing\xbd')
check(u'str\x00ing\u20ac', 'str\xc0\x80ing\xe2\x82\xac', u'str\x00ing\u20ac')
check('string')
check('string\xbd')
check('string\xe2\x82\xac', u'string\u20ac')
check(u'string')
check(u'string\xbd')
check(u'string\u20ac')
check('str\xc0\x80ing', u'str\x00ing')
check('str\xc0\x80ing\xe2\x82\xac', u'str\x00ing\u20ac')
check(u'str\x00ing')
check(u'str\x00ing\xbd')
check(u'str\x00ing\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):
check(f, repr(f))
for f in (1/3.0, sys.float_info.min, sys.float_info.max,
-sys.float_info.min, -sys.float_info.max):
check(f, f, eq=float_eq)
check(float('inf'), 'Inf', eq=float_eq)
check(-float('inf'), '-Inf', eq=float_eq)
check(f, eq=float_eq)
check(float('inf'), eq=float_eq)
check(-float('inf'), eq=float_eq)
# XXX NaN representation can be not parsable by float()
check((), '')
check((1, (2,), (3, 4), '5 6', ()), '1 2 {3 4} {5 6} {}')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment