From: Serhiy Storchaka Date: Thu, 23 Jan 2014 12:38:44 +0000 (+0200) Subject: Other attempt to fix test_user_command on OpenSolaris. X-Git-Tag: v2.7.8~92 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc97667254bdc7bc3fc662f2c5fdb0298ab9fc8b;p=python Other attempt to fix test_user_command on OpenSolaris. --- diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py index 5863dd572c..dfad31977c 100644 --- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -210,14 +210,19 @@ class TclTest(unittest.TestCase): result.append(arg) return arg self.interp.createcommand('testfunc', testfunc) - def check(value, expected, conv=lambda x: x): + def check(value, expected, eq=self.assertEqual): del result[:] r = self.interp.call('testfunc', value) self.assertEqual(len(result), 1) self.assertIsInstance(result[0], str) - self.assertEqual(conv(result[0]), expected) + eq(result[0], expected) 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(False, '0') @@ -226,13 +231,14 @@ class TclTest(unittest.TestCase): 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, + 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, conv=float) - check(float('inf'), float('inf'), conv=float) - check(-float('inf'), -float('inf'), conv=float) - check(float('nan'), 'NaN') + check(f, f, eq=float_eq) + check(float('inf'), 'Inf', eq=float_eq) + check(-float('inf'), '-Inf', eq=float_eq) + check(float('nan'), 'NaN', eq=nan_eq) check((), '') check((1, (2,), (3, 4), '5 6', ()), '1 2 {3 4} {5 6} {}')