summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tcl.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-23 14:49:22 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-23 14:49:22 (GMT)
commit418e80ba00e88db4ab7098da4fa5b141bbdf6fcd (patch)
tree401f6673861b0edd3d29377403bb6366c27c85a1 /Lib/test/test_tcl.py
parentfe5fff6305eb76f64d7cc4d666053e9e185dec60 (diff)
parentbdf0cb52eb4b0676003b3d3ee08f1a48528f1959 (diff)
downloadcpython-418e80ba00e88db4ab7098da4fa5b141bbdf6fcd.zip
cpython-418e80ba00e88db4ab7098da4fa5b141bbdf6fcd.tar.gz
cpython-418e80ba00e88db4ab7098da4fa5b141bbdf6fcd.tar.bz2
Fixed test_user_command on OpenSolaris where floats can have different string
representation in Tcl and Python.
Diffstat (limited to 'Lib/test/test_tcl.py')
-rw-r--r--Lib/test/test_tcl.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
index 6c8ef05..d804f0f 100644
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -199,9 +199,19 @@ class TclTest(unittest.TestCase):
result = arg
return arg
self.interp.createcommand('testfunc', testfunc)
- def check(value, expected):
- self.assertEqual(self.interp.call('testfunc', value), expected)
- self.assertEqual(result, expected)
+ def check(value, expected, eq=self.assertEqual):
+ r = self.interp.call('testfunc', value)
+ self.assertIsInstance(result, str)
+ eq(result, expected)
+ self.assertIsInstance(r, str)
+ eq(r, expected)
+ def float_eq(actual, expected):
+ expected = float(expected)
+ self.assertAlmostEqual(float(actual), expected,
+ delta=abs(expected) * 1e-10)
+ def nan_eq(actual, expected):
+ actual = float(actual)
+ self.assertNotEqual(actual, actual)
check(True, '1')
check(False, '0')
@@ -210,13 +220,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, str(f))
- check(float('nan'), 'NaN')
- check(float('inf'), 'Inf')
- check(-float('inf'), '-Inf')
+ 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} {}')