[Numpy-svn] r6271 - trunk/numpy/core/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Tue Dec 30 01:32:07 EST 2008


Author: cdavid
Date: 2008-12-30 00:32:03 -0600 (Tue, 30 Dec 2008)
New Revision: 6271

Modified:
   trunk/numpy/core/tests/test_print.py
Log:
Do not use dict for reference: hashing on scalar arrays does not work as I expected.

Modified: trunk/numpy/core/tests/test_print.py
===================================================================
--- trunk/numpy/core/tests/test_print.py	2008-12-30 06:28:22 UTC (rev 6270)
+++ trunk/numpy/core/tests/test_print.py	2008-12-30 06:32:03 UTC (rev 6271)
@@ -5,22 +5,8 @@
 import sys
 from StringIO import StringIO
 
-_REF = {np.inf: 'inf', -np.inf: '-inf', np.nan: 'nan',
-        np.complex64(complex(np.inf, 1)): '(inf+1j)',
-        np.complex64(complex(np.nan, 1)): '(nan+1j)',
-        np.complex64(complex(-np.inf, 1)): '(-inf+1j)',
-        np.cdouble(complex(np.inf, 1)): '(inf+1j)',
-        np.cdouble(complex(np.nan, 1)): '(nan+1j)',
-        np.cdouble(complex(-np.inf, 1)): '(-inf+1j)',
-        np.clongdouble(complex(np.inf, 1)): '(inf+1j)',
-        np.clongdouble(complex(np.nan, 1)): '(nan+1j)',
-        np.clongdouble(complex(-np.inf, 1)): '(-inf+1j)'
-        }
+_REF = {np.inf: 'inf', -np.inf: '-inf', np.nan: 'nan'}
 
-if sys.platform == 'win32' and sys.version_info[0] <= 2 and sys.version_info[1] <= 5:
-    _REF[np.float32(1e10)] = '1e+010'
-else:
-    _REF[np.float32(1e10)] = '1e+10'
 
 def check_float_type(tp):
     for x in [0, 1,-1, 1e20] :
@@ -31,7 +17,12 @@
         assert_equal(str(tp(1e10)), str(float('1e10')),
                      err_msg='Failed str formatting for type %s' % tp)
     else:
-        assert_equal(str(tp(1e10)), _REF[tp(1e10)],
+        if sys.platform == 'win32' and sys.version_info[0] <= 2 and \
+           sys.version_info[1] <= 5:
+            ref = '1e+010'
+        else:
+            ref = '1e+10'
+        assert_equal(str(tp(1e10)), ref,
                      err_msg='Failed str formatting for type %s' % tp)
 
 def test_float_types():
@@ -74,7 +65,12 @@
         assert_equal(str(tp(1e10)), str(complex(1e10)),
                      err_msg='Failed str formatting for type %s' % tp)
     else:
-        assert_equal(str(tp(1e10)), _REF[tp(1e10)],
+        if sys.platform == 'win32' and sys.version_info[0] <= 2 and \
+           sys.version_info[1] <= 5:
+            ref = '1e+010'
+        else:
+            ref = '1e+10'
+        assert_equal(str(tp(1e10)), ref,
                      err_msg='Failed str formatting for type %s' % tp)
 
 def test_complex_types():
@@ -89,7 +85,7 @@
         yield check_complex_type, t
 
 # print tests
-def _test_redirected_print(x, tp):
+def _test_redirected_print(x, tp, ref=None):
     file = StringIO()
     file_tp = StringIO()
     stdout = sys.stdout
@@ -97,8 +93,8 @@
         sys.stdout = file_tp
         print tp(x)
         sys.stdout = file
-        if tp(x) in _REF:
-            print _REF[tp(x)]
+        if ref:
+            print ref
         else:
             print x
     finally:




More information about the Numpy-svn mailing list