[Python-checkins] python/dist/src/Lib/test test_coercion.py, 1.6, 1.7

nascheme at users.sourceforge.net nascheme at users.sourceforge.net
Wed Mar 10 12:30:06 EST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14349/Lib/test

Modified Files:
	test_coercion.py 
Log Message:
Make test_coercion.py less sensitive to platform fp quirks.  Closes
SF bug #678265.


Index: test_coercion.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_coercion.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** test_coercion.py	30 Jul 2002 23:26:01 -0000	1.6
--- test_coercion.py	10 Mar 2004 17:30:03 -0000	1.7
***************
*** 68,76 ****
  
  candidates = [ 2, 4.0, 2L, 2+0j, [1], (2,), None,
!                MethodNumber(1), CoerceNumber(2)]
  
  infix_binops = [ '+', '-', '*', '/', '**', '%' ]
  prefix_binops = [ 'divmod' ]
  
  def do_infix_binops():
      for a in candidates:
--- 68,91 ----
  
  candidates = [ 2, 4.0, 2L, 2+0j, [1], (2,), None,
!                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:
***************
*** 84,88 ****
                      print '... %s' % error[0]
                  else:
!                     print '=', x
                  try:
                      z = copy.copy(a)
--- 99,103 ----
                      print '... %s' % error[0]
                  else:
!                     print '=', format_result(x)
                  try:
                      z = copy.copy(a)
***************
*** 96,100 ****
                      print '... %s' % error[0]
                  else:
!                     print '=>', z
  
  def do_prefix_binops():
--- 111,115 ----
                      print '... %s' % error[0]
                  else:
!                     print '=>', format_result(z)
  
  def do_prefix_binops():
***************
*** 109,113 ****
                      print '... %s' % error[0]
                  else:
!                     print '=', x
  
  warnings.filterwarnings("ignore",
--- 124,128 ----
                      print '... %s' % error[0]
                  else:
!                     print '=', format_result(x)
  
  warnings.filterwarnings("ignore",




More information about the Python-checkins mailing list