From 5542b15d2504dd7e2feefea290dc6c74054c78c7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 25 Dec 2013 17:28:50 +0200 Subject: [PATCH] Issue #19320: test_tcl no longer fails when wantobjects is false. --- Lib/test/test_tcl.py | 45 +++++++++++++++++++++++++++++--------------- Misc/NEWS | 2 ++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py index a44a0a16f92..ec21f077de6 100644 --- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -33,6 +33,7 @@ class TclTest(unittest.TestCase): def setUp(self): self.interp = Tcl() + self.wantobjects = self.interp.tk.wantobjects() def testEval(self): tcl = self.interp @@ -178,24 +179,32 @@ class TclTest(unittest.TestCase): def test_passing_values(self): def passValue(value): return self.interp.call('set', '_', value) - self.assertEqual(passValue(True), True) - self.assertEqual(passValue(False), False) - self.assertEqual(passValue('string'), 'string') - self.assertEqual(passValue('string\u20ac'), 'string\u20ac') + + self.assertEqual(passValue(True), True if self.wantobjects else '1') + self.assertEqual(passValue(False), False if self.wantobjects else '0') self.assertEqual(passValue(u'string'), u'string') self.assertEqual(passValue(u'string\u20ac'), u'string\u20ac') for i in (0, 1, -1, int(2**31-1), int(-2**31)): - self.assertEqual(passValue(i), i) + self.assertEqual(passValue(i), i if self.wantobjects else str(i)) for f in (0.0, 1.0, -1.0, 1//3, 1/3.0, sys.float_info.min, sys.float_info.max, -sys.float_info.min, -sys.float_info.max): - self.assertEqual(passValue(f), f) - for f in float('nan'), float('inf'), -float('inf'): - if f != f: # NaN - self.assertNotEqual(passValue(f), f) - else: + if self.wantobjects: self.assertEqual(passValue(f), f) - self.assertEqual(passValue((1, '2', (3.4,))), (1, '2', (3.4,))) + else: + self.assertEqual(float(passValue(f)), f) + if self.wantobjects: + f = passValue(float('nan')) + self.assertNotEqual(f, f) + self.assertEqual(passValue(float('inf')), float('inf')) + self.assertEqual(passValue(-float('inf')), -float('inf')) + else: + f = float(passValue(float('nan'))) + self.assertNotEqual(f, f) + self.assertEqual(float(passValue(float('inf'))), float('inf')) + self.assertEqual(float(passValue(-float('inf'))), -float('inf')) + self.assertEqual(passValue((1, '2', (3.4,))), + (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4') def test_splitlist(self): splitlist = self.interp.tk.splitlist @@ -220,12 +229,15 @@ class TclTest(unittest.TestCase): ('a 3.4', ('a', '3.4')), (('a', 3.4), ('a', 3.4)), ((), ()), - (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))), + (call('list', 1, '2', (3.4,)), + (1, '2', (3.4,)) if self.wantobjects else + ('1', '2', '3.4')), ] if tcl_version >= (8, 5): testcases += [ (call('dict', 'create', 1, u'\u20ac', '\xe2\x82\xac', (3.4,)), - (1, u'\u20ac', u'\u20ac', (3.4,))), + (1, u'\u20ac', u'\u20ac', (3.4,)) if self.wantobjects else + ('1', '\xe2\x82\xac', '\xe2\x82\xac', '3.4')), ] for arg, res in testcases: self.assertEqual(splitlist(arg), res) @@ -257,12 +269,15 @@ class TclTest(unittest.TestCase): (('a', 3.4), ('a', 3.4)), (('a', (2, 3.4)), ('a', (2, 3.4))), ((), ()), - (call('list', 1, '2', (3.4,)), (1, '2', (3.4,))), + (call('list', 1, '2', (3.4,)), + (1, '2', (3.4,)) if self.wantobjects else + ('1', '2', '3.4')), ] if tcl_version >= (8, 5): testcases += [ (call('dict', 'create', 12, u'\u20ac', '\xe2\x82\xac', (3.4,)), - (12, u'\u20ac', u'\u20ac', (3.4,))), + (12, u'\u20ac', u'\u20ac', (3.4,)) if self.wantobjects else + ('12', '\xe2\x82\xac', '\xe2\x82\xac', '3.4')), ] for arg, res in testcases: self.assertEqual(split(arg), res) diff --git a/Misc/NEWS b/Misc/NEWS index d9cd29ff2eb..12106579e0e 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -132,6 +132,8 @@ IDLE Tests ----- +- Issue #19320: test_tcl no longer fails when wantobjects is false. + - Issue #19683: Removed empty tests from test_minidom. Initial patch by Ajitesh Gupta.