[Numpy-svn] r6233 - branches/fix_float_format/numpy/core/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Dec 28 22:49:15 EST 2008


Author: cdavid
Date: 2008-12-28 21:49:09 -0600 (Sun, 28 Dec 2008)
New Revision: 6233

Modified:
   branches/fix_float_format/numpy/core/tests/test_print.py
Log:
Use parametric tests for format tests so that it is clearer which type is failing.

Modified: branches/fix_float_format/numpy/core/tests/test_print.py
===================================================================
--- branches/fix_float_format/numpy/core/tests/test_print.py	2008-12-29 03:23:59 UTC (rev 6232)
+++ branches/fix_float_format/numpy/core/tests/test_print.py	2008-12-29 03:49:09 UTC (rev 6233)
@@ -1,34 +1,37 @@
 import numpy as np
 from numpy.testing import *
 
-class TestPrint(TestCase):
+def check_float_type(tp):
+    for x in [0, 1,-1, 1e10, 1e20] :
+        assert_equal(str(tp(x)), str(float(x)))
 
-    def test_float_types(self) :
-        """ Check formatting.
+def test_float_types():
+    """ Check formatting.
 
-            This is only for the str function, and only for simple types.
-            The precision of np.float and np.longdouble aren't the same as the
-            python float precision.
+        This is only for the str function, and only for simple types.
+        The precision of np.float and np.longdouble aren't the same as the
+        python float precision.
 
-        """
-        for t in [np.float, np.double, np.longdouble] :
-            for x in [0, 1,-1, 1e10, 1e20] :
-                assert_equal(str(t(x)), str(float(x)))
+    """
+    for t in [np.float, np.double, np.longdouble] :
+        yield check_float_type, t
 
-    def test_complex_types(self) :
-        """Check formatting.
+def check_complex_type(tp):
+    for x in [0, 1,-1, 1e10, 1e20] :
+        assert_equal(str(tp(x)), str(complex(x)))
+        assert_equal(str(tp(x*1j)), str(complex(x*1j)))
+        assert_equal(str(tp(x + x*1j)), str(complex(x + x*1j)))
 
-            This is only for the str function, and only for simple types.
-            The precision of np.float and np.longdouble aren't the same as the
-            python float precision.
+def test_complex_types():
+    """Check formatting.
 
-        """
-        for t in [np.cfloat, np.cdouble, np.clongdouble] :
-            for x in [0, 1,-1, 1e10, 1e20] :
-                assert_equal(str(t(x)), str(complex(x)))
-                assert_equal(str(t(x*1j)), str(complex(x*1j)))
-                assert_equal(str(t(x + x*1j)), str(complex(x + x*1j)))
+        This is only for the str function, and only for simple types.
+        The precision of np.float and np.longdouble aren't the same as the
+        python float precision.
 
+    """
+    for t in [np.cfloat, np.cdouble, np.clongdouble] :
+        yield check_complex_type, t
 
 if __name__ == "__main__":
     run_module_suite()




More information about the Numpy-svn mailing list