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

numpy-svn@scip... numpy-svn@scip...
Mon Dec 29 21:48:14 CST 2008


Author: cdavid
Date: 2008-12-29 21:48:11 -0600 (Mon, 29 Dec 2008)
New Revision: 6240

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

Modified: trunk/numpy/core/tests/test_print.py
===================================================================
--- trunk/numpy/core/tests/test_print.py	2008-12-30 03:19:53 UTC (rev 6239)
+++ trunk/numpy/core/tests/test_print.py	2008-12-30 03:48:11 UTC (rev 6240)
@@ -3,6 +3,7 @@
 
 import locale
 import sys
+from StringIO import StringIO
 
 def check_float_type(tp):
     for x in [0, 1,-1, 1e10, 1e20] :
@@ -56,6 +57,29 @@
     for t in [np.complex64, np.cdouble, np.clongdouble] :
         yield check_complex_type, t
 
+# print tests
+def check_float_type_print(tp):
+    for x in [0, 1,-1, 1e10, 1e20, float('inf'), float('nan'), float('-inf')] :
+        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
+
+# Locale tests: scalar types formatting should be independant of the locale
 def has_french_locale():
     curloc = locale.getlocale(locale.LC_NUMERIC)
     try:



More information about the Numpy-svn mailing list