Commit a503293f authored by Serhiy Storchaka's avatar Serhiy Storchaka

Other attempt to fix test_user_command on OpenSolaris.

parent eae7681f
...@@ -210,14 +210,19 @@ class TclTest(unittest.TestCase): ...@@ -210,14 +210,19 @@ class TclTest(unittest.TestCase):
result.append(arg) result.append(arg)
return arg return arg
self.interp.createcommand('testfunc', testfunc) self.interp.createcommand('testfunc', testfunc)
def check(value, expected, conv=lambda x: x): def check(value, expected, eq=self.assertEqual):
del result[:] del result[:]
r = self.interp.call('testfunc', value) r = self.interp.call('testfunc', value)
self.assertEqual(len(result), 1) self.assertEqual(len(result), 1)
self.assertIsInstance(result[0], str) self.assertIsInstance(result[0], str)
self.assertEqual(conv(result[0]), expected) eq(result[0], expected)
self.assertIsInstance(r, str) self.assertIsInstance(r, str)
self.assertEqual(conv(r), expected) eq(r, expected)
def float_eq(actual, expected):
self.assertAlmostEqual(float(actual), float(expected))
def nan_eq(actual, expected):
actual = float(actual)
self.assertNotEqual(actual, actual)
check(True, '1') check(True, '1')
check(False, '0') check(False, '0')
...@@ -226,13 +231,14 @@ class TclTest(unittest.TestCase): ...@@ -226,13 +231,14 @@ class TclTest(unittest.TestCase):
check('string\u20ac', 'string\u20ac') check('string\u20ac', 'string\u20ac')
for i in (0, 1, -1, 2**31-1, -2**31): for i in (0, 1, -1, 2**31-1, -2**31):
check(i, str(i)) check(i, str(i))
for f in (0.0, 1.0, -1.0, 1/3, for f in (0.0, 1.0, -1.0):
sys.float_info.min, sys.float_info.max, 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): -sys.float_info.min, -sys.float_info.max):
check(f, f, conv=float) check(f, f, eq=float_eq)
check(float('inf'), float('inf'), conv=float) check(float('inf'), 'Inf', eq=float_eq)
check(-float('inf'), -float('inf'), conv=float) check(-float('inf'), '-Inf', eq=float_eq)
check(float('nan'), 'NaN') check(float('nan'), 'NaN', eq=nan_eq)
check((), '') check((), '')
check((1, (2,), (3, 4), '5 6', ()), '1 2 {3 4} {5 6} {}') 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