From: Serhiy Storchaka Date: Mon, 18 Aug 2014 14:46:34 +0000 (+0300) Subject: Clean up test_user_command. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ede745a7edb9ada7fba7cee07d60f2a8ee9d924f;p=python Clean up test_user_command. --- diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py index fcbafc5bd2..c0afba6e55 100644 --- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -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} {}')