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

numpy-svn@scip... numpy-svn@scip...
Mon Dec 29 21:56:58 CST 2008


Author: cdavid
Date: 2008-12-29 21:56:54 -0600 (Mon, 29 Dec 2008)
New Revision: 6241

Modified:
   trunk/numpy/core/tests/test_print.py
Log:
Add print tests for complex types.

Modified: trunk/numpy/core/tests/test_print.py
===================================================================
--- trunk/numpy/core/tests/test_print.py	2008-12-30 03:48:11 UTC (rev 6240)
+++ trunk/numpy/core/tests/test_print.py	2008-12-30 03:56:54 UTC (rev 6241)
@@ -74,11 +74,36 @@
         assert_equal(file.getvalue(), file_tp.getvalue(),
                      err_msg='print failed for type%s' % tp)
 
+def check_complex_type_print(tp):
+    # We do not create complex with inf/nan directly because the feature is
+    # missing in python < 2.6
+    for x in [complex(0), complex(1), complex(-1), complex(1e10), complex(1e20),
+              complex(float('inf'), 1), complex(float('nan'), 1),
+              complex(float('-inf'), 1)] :
+        file = StringIO()
+        file_tp = StringIO()
+        stdout = sys.stdout
+        try:
+            sys.stdout = file_tp
+            print tp(x)
+            sys.stdout = file
+            print x
+        finally:
+            sys.stdout = stdout
+
+        assert_equal(file.getvalue(), file_tp.getvalue(),
+                     err_msg='print failed for type%s' % tp)
+
 def test_float_type_print():
     """Check formatting when using print """
     for t in [np.float32, np.double, np.longdouble] :
         yield check_float_type_print, t
 
+def test_complex_type_print():
+    """Check formatting when using print """
+    for t in [np.complex64, np.cdouble, np.clongdouble] :
+        yield check_complex_type_print, t
+
 # Locale tests: scalar types formatting should be independant of the locale
 def has_french_locale():
     curloc = locale.getlocale(locale.LC_NUMERIC)



More information about the Numpy-svn mailing list