[Numpy-svn] r6243 - in branches/fix_float_format: . numpy/core/tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Dec 29 23:04:53 EST 2008
Author: cdavid
Date: 2008-12-29 22:04:47 -0600 (Mon, 29 Dec 2008)
New Revision: 6243
Modified:
branches/fix_float_format/
branches/fix_float_format/numpy/core/tests/test_print.py
Log:
Merged revisions 6240-6241 via svnmerge from
http://svn.scipy.org/svn/numpy/trunk
........
r6240 | cdavid | 2008-12-30 12:48:11 +0900 (Tue, 30 Dec 2008) | 1 line
Add tests for print of float types.
........
r6241 | cdavid | 2008-12-30 12:56:54 +0900 (Tue, 30 Dec 2008) | 1 line
Add print tests for complex types.
........
Property changes on: branches/fix_float_format
___________________________________________________________________
Name: svnmerge-integrated
- /branches/distutils-revamp:1-2752 /branches/dynamic_cpu_configuration:1-6101 /branches/multicore:1-3687 /branches/numpy-mingw-w64:1-6150 /branches/visualstudio_manifest:1-6077 /trunk:1-6238
+ /branches/distutils-revamp:1-2752 /branches/dynamic_cpu_configuration:1-6101 /branches/multicore:1-3687 /branches/numpy-mingw-w64:1-6150 /branches/visualstudio_manifest:1-6077 /trunk:1-6242
Modified: branches/fix_float_format/numpy/core/tests/test_print.py
===================================================================
--- branches/fix_float_format/numpy/core/tests/test_print.py 2008-12-30 03:57:33 UTC (rev 6242)
+++ branches/fix_float_format/numpy/core/tests/test_print.py 2008-12-30 04:04:47 UTC (rev 6243)
@@ -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,54 @@
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 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)
try:
More information about the Numpy-svn
mailing list