diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/tests/test_print.py | 49 |
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: |