summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_coercion.py
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2004-03-10 17:30:03 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2004-03-10 17:30:03 (GMT)
commit6cbba50a43cdb4c8584d418153d8e0c2683107cb (patch)
tree2d9b27503ce7f70d4e69059b77f71a7432d3db41 /Lib/test/test_coercion.py
parent66d31f8f3812f91d8d9bf7878f93fabe6f005082 (diff)
downloadcpython-6cbba50a43cdb4c8584d418153d8e0c2683107cb.zip
cpython-6cbba50a43cdb4c8584d418153d8e0c2683107cb.tar.gz
cpython-6cbba50a43cdb4c8584d418153d8e0c2683107cb.tar.bz2
Make test_coercion.py less sensitive to platform fp quirks. Closes
SF bug #678265.
Diffstat (limited to 'Lib/test/test_coercion.py')
-rw-r--r--Lib/test/test_coercion.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/Lib/test/test_coercion.py b/Lib/test/test_coercion.py
index be5b744..331771f 100644
--- a/Lib/test/test_coercion.py
+++ b/Lib/test/test_coercion.py
@@ -67,11 +67,26 @@ class MethodNumber:
candidates = [ 2, 4.0, 2L, 2+0j, [1], (2,), None,
- MethodNumber(1), CoerceNumber(2)]
+ MethodNumber(2), CoerceNumber(2)]
infix_binops = [ '+', '-', '*', '/', '**', '%' ]
prefix_binops = [ 'divmod' ]
+def format_float(value):
+ if abs(value) < 0.01:
+ return '0.0'
+ else:
+ return '%.1f' % value
+
+# avoid testing platform fp quirks
+def format_result(value):
+ if isinstance(value, complex):
+ return '(%s + %sj)' % (format_float(value.real),
+ format_float(value.imag))
+ elif isinstance(value, float):
+ return format_float(value)
+ return str(value)
+
def do_infix_binops():
for a in candidates:
for b in candidates:
@@ -83,7 +98,7 @@ def do_infix_binops():
error = sys.exc_info()[:2]
print '... %s' % error[0]
else:
- print '=', x
+ print '=', format_result(x)
try:
z = copy.copy(a)
except copy.Error:
@@ -95,7 +110,7 @@ def do_infix_binops():
error = sys.exc_info()[:2]
print '... %s' % error[0]
else:
- print '=>', z
+ print '=>', format_result(z)
def do_prefix_binops():
for a in candidates:
@@ -108,7 +123,7 @@ def do_prefix_binops():
error = sys.exc_info()[:2]
print '... %s' % error[0]
else:
- print '=', x
+ print '=', format_result(x)
warnings.filterwarnings("ignore",
r'complex divmod\(\), // and % are deprecated',