[Numpy-svn] r6250 - in trunk: . numpy/core/tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Tue Dec 30 00:02:32 EST 2008
Author: cdavid
Date: 2008-12-29 23:02:28 -0600 (Mon, 29 Dec 2008)
New Revision: 6250
Modified:
trunk/
trunk/numpy/core/tests/test_print.py
Log:
Merged revisions 6247-6249 via svnmerge from
http://svn.scipy.org/svn/numpy/branches/fix_float_format
........
r6247 | cdavid | 2008-12-30 13:41:37 +0900 (Tue, 30 Dec 2008) | 1 line
Handle 1e10 specially, as it is the limit where exp notation is shorter than decimal for single precision, but not for double (python native one).
........
r6248 | cdavid | 2008-12-30 13:47:38 +0900 (Tue, 30 Dec 2008) | 1 line
Refactor a bit redirected output print test.
........
r6249 | cdavid | 2008-12-30 13:49:31 +0900 (Tue, 30 Dec 2008) | 1 line
Fix test for single precision print.
........
Property changes on: trunk
___________________________________________________________________
Name: svnmerge-integrated
- /branches/distutils-revamp:1-2752 /branches/dynamic_cpu_configuration:1-6101 /branches/fix_float_format:1-6222,6233-6234 /branches/multicore:1-3687 /branches/numpy-mingw-w64:1-6150 /branches/visualstudio_manifest:1-6077 /trunk:1-2871
+ /branches/distutils-revamp:1-2752 /branches/dynamic_cpu_configuration:1-6101 /branches/fix_float_format:1-6222,6233-6234,6247-6249 /branches/multicore:1-3687 /branches/numpy-mingw-w64:1-6150 /branches/visualstudio_manifest:1-6077 /trunk:1-2871
Modified: trunk/numpy/core/tests/test_print.py
===================================================================
--- trunk/numpy/core/tests/test_print.py 2008-12-30 04:49:31 UTC (rev 6249)
+++ trunk/numpy/core/tests/test_print.py 2008-12-30 05:02:28 UTC (rev 6250)
@@ -6,10 +6,17 @@
from StringIO import StringIO
def check_float_type(tp):
- for x in [0, 1,-1, 1e10, 1e20] :
+ for x in [0, 1,-1, 1e20] :
assert_equal(str(tp(x)), str(float(x)),
err_msg='Failed str formatting for type %s' % tp)
+ if tp(1e10).itemsize > 4:
+ assert_equal(str(tp(1e10)), str(float('1e10')),
+ err_msg='Failed str formatting for type %s' % tp)
+ else:
+ assert_equal(str(tp(1e10)), '1e+10',
+ err_msg='Failed str formatting for type %s' % tp)
+
def test_float_types():
""" Check formatting.
@@ -38,7 +45,7 @@
yield check_nan_inf_float, t
def check_complex_type(tp):
- for x in [0, 1,-1, 1e10, 1e20] :
+ for x in [0, 1,-1, 1e20] :
assert_equal(str(tp(x)), str(complex(x)),
err_msg='Failed str formatting for type %s' % tp)
assert_equal(str(tp(x*1j)), str(complex(x*1j)),
@@ -46,6 +53,13 @@
assert_equal(str(tp(x + x*1j)), str(complex(x + x*1j)),
err_msg='Failed str formatting for type %s' % tp)
+ if tp(1e10).itemsize > 8:
+ assert_equal(str(tp(1e10)), str(complex(1e10)),
+ err_msg='Failed str formatting for type %s' % tp)
+ else:
+ assert_equal(str(tp(1e10)), '(1e+10+0j)',
+ err_msg='Failed str formatting for type %s' % tp)
+
def test_complex_types():
"""Check formatting.
@@ -58,42 +72,45 @@
yield check_complex_type, t
# print tests
+def _test_redirected_print(x, tp):
+ 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_float_type_print(tp):
- for x in [0, 1,-1, 1e10, 1e20, float('inf'), float('nan'), float('-inf')] :
- x = float(x)
- 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
+ for x in [0, 1,-1, 1e20, 'inf', 'nan', '-inf'] :
+ _test_redirected_print(float(x), tp)
- assert_equal(file.getvalue(), file_tp.getvalue(),
- err_msg='print failed for type%s' % tp)
+ if tp(1e10).itemsize > 4:
+ assert_equal(str(tp(1e10)), str(float(1e10)),
+ err_msg='Failed str formatting for type %s' % tp)
+ else:
+ assert_equal(str(tp(1e10)), '1e+10',
+ err_msg='Failed str formatting 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
+ for x in [0, 1, -1, 1e20, complex(float('inf'), 1),
+ complex(float('nan'), 1), complex(float('-inf'), 1)] :
+ _test_redirected_print(complex(x), tp)
- assert_equal(file.getvalue(), file_tp.getvalue(),
- err_msg='print failed for type%s' % tp)
+ if tp(1e10).itemsize > 8:
+ assert_equal(str(tp(1e10)), str(complex(1e10)),
+ err_msg='Failed str formatting for type %s' % tp)
+ else:
+ assert_equal(str(tp(1e10)), '(1e+10+0j)',
+ err_msg='Failed str formatting for type %s' % tp)
def test_float_type_print():
"""Check formatting when using print """
More information about the Numpy-svn
mailing list