[Numpy-svn] r6248 - branches/fix_float_format/numpy/core/tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Dec 29 23:47:42 EST 2008
Author: cdavid
Date: 2008-12-29 22:47:38 -0600 (Mon, 29 Dec 2008)
New Revision: 6248
Modified:
branches/fix_float_format/numpy/core/tests/test_print.py
Log:
Refactor a bit redirected output print test.
Modified: branches/fix_float_format/numpy/core/tests/test_print.py
===================================================================
--- branches/fix_float_format/numpy/core/tests/test_print.py 2008-12-30 04:41:37 UTC (rev 6247)
+++ branches/fix_float_format/numpy/core/tests/test_print.py 2008-12-30 04:47:38 UTC (rev 6248)
@@ -72,43 +72,32 @@
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')] :
- 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
+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)
+ 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, 'inf', 'nan', '-inf'] :
+ _test_redirected_print(float(x), 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, 1e10, 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)
-
def test_float_type_print():
"""Check formatting when using print """
for t in [np.float32, np.double, np.longdouble] :
More information about the Numpy-svn
mailing list