summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2008-12-30 04:04:47 +0000
committerDavid Cournapeau <cournape@gmail.com>2008-12-30 04:04:47 +0000
commitb85b457d472c24efcd5d57c03a74ac1ac06a705d (patch)
treecd36e4aed845e4e615175937f8b4808c8a8cf20c /numpy
parentf6f9ac09ac060d7430abf51510eb84cc4c57c08b (diff)
parentffbeb6e9b3eeb6eadac1407c908ffb510e20a98d (diff)
downloadnumpy-b85b457d472c24efcd5d57c03a74ac1ac06a705d.tar.gz
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. ........
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/tests/test_print.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/numpy/core/tests/test_print.py b/numpy/core/tests/test_print.py
index a9db5e480..0490978ff 100644
--- a/numpy/core/tests/test_print.py
+++ b/numpy/core/tests/test_print.py
@@ -3,6 +3,7 @@ from numpy.testing import *
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 @@ def test_complex_types():
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: