[Numpy-svn] r6239 - in branches/fix_float_format: . numpy/core/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Dec 29 22:19:57 EST 2008


Author: cdavid
Date: 2008-12-29 21:19:53 -0600 (Mon, 29 Dec 2008)
New Revision: 6239

Modified:
   branches/fix_float_format/
   branches/fix_float_format/numpy/core/tests/test_print.py
Log:
Merged revisions 6236-6238 via svnmerge from 
http://svn.scipy.org/svn/numpy/trunk

........
  r6236 | cdavid | 2008-12-29 17:02:15 +0900 (Mon, 29 Dec 2008) | 1 line
  
  Add nan/inf tests for formatting.
........
  r6237 | cdavid | 2008-12-29 17:26:04 +0900 (Mon, 29 Dec 2008) | 1 line
  
  Add test for real float types locale independance.
........
  r6238 | cdavid | 2008-12-29 17:35:06 +0900 (Mon, 29 Dec 2008) | 1 line
  
  Clearer error messages for formatting failures.
........



Property changes on: branches/fix_float_format
___________________________________________________________________
Name: svnmerge-integrated
   - /branches/distutils-revamp:1-2752 /branches/dynamic_cpu_configuration:1-6101 /branches/multicore:1-3687 /branches/numpy-mingw-w64:1-6150 /branches/visualstudio_manifest:1-6077 /trunk:1-6221
   + /branches/distutils-revamp:1-2752 /branches/dynamic_cpu_configuration:1-6101 /branches/multicore:1-3687 /branches/numpy-mingw-w64:1-6150 /branches/visualstudio_manifest:1-6077 /trunk:1-6238

Modified: branches/fix_float_format/numpy/core/tests/test_print.py
===================================================================
--- branches/fix_float_format/numpy/core/tests/test_print.py	2008-12-29 08:35:06 UTC (rev 6238)
+++ branches/fix_float_format/numpy/core/tests/test_print.py	2008-12-30 03:19:53 UTC (rev 6239)
@@ -1,9 +1,13 @@
 import numpy as np
 from numpy.testing import *
 
+import locale
+import sys
+
 def check_float_type(tp):
     for x in [0, 1,-1, 1e10, 1e20] :
-        assert_equal(str(tp(x)), str(float(x)))
+        assert_equal(str(tp(x)), str(float(x)),
+                     err_msg='Failed str formatting for type %s' % tp)
 
 def test_float_types():
     """ Check formatting.
@@ -16,11 +20,30 @@
     for t in [np.float32, np.double, np.longdouble] :
         yield check_float_type, t
 
+def check_nan_inf_float(tp):
+    for x in [float('inf'), float('-inf'), float('nan')]:
+        assert_equal(str(tp(x)), str(float(x)),
+                     err_msg='Failed str formatting for type %s' % tp)
+
+def test_nan_inf_float():
+    """ 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.
+
+    """
+    for t in [np.float32, np.double, np.longdouble] :
+        yield check_nan_inf_float, t
+
 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)))
+        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)),
+                     err_msg='Failed str formatting for type %s' % tp)
+        assert_equal(str(tp(x + x*1j)), str(complex(x + x*1j)),
+                     err_msg='Failed str formatting for type %s' % tp)
 
 def test_complex_types():
     """Check formatting.
@@ -33,5 +56,53 @@
     for t in [np.complex64, np.cdouble, np.clongdouble] :
         yield check_complex_type, t
 
+def has_french_locale():
+    curloc = locale.getlocale(locale.LC_NUMERIC)
+    try:
+        if not sys.platform == 'win32':
+            locale.setlocale(locale.LC_NUMERIC, 'fr_FR')
+        else:
+            locale.setlocale(locale.LC_NUMERIC, 'FRENCH')
+
+        st = True
+    except:
+        st = False
+    finally:
+        locale.setlocale(locale.LC_NUMERIC, locale=curloc)
+
+    return st
+
+def _test_locale_independance(tp):
+    # XXX: How to query locale on a given system ?
+
+    # French is one language where the decimal is ',' not '.', and should be
+    # relatively common on many systems
+    curloc = locale.getlocale(locale.LC_NUMERIC)
+    try:
+        if not sys.platform == 'win32':
+            locale.setlocale(locale.LC_NUMERIC, 'fr_FR')
+        else:
+            locale.setlocale(locale.LC_NUMERIC, 'FRENCH')
+
+        assert_equal(str(tp(1.2)), str(float(1.2)),
+                     err_msg='Failed locale test for type %s' % tp)
+    finally:
+        locale.setlocale(locale.LC_NUMERIC, locale=curloc)
+
+ at np.testing.dec.skipif(not has_french_locale(),
+                       "Skipping locale test, French locale not found")
+def test_locale_single():
+    return _test_locale_independance(np.float32)
+
+ at np.testing.dec.skipif(not has_french_locale(),
+                       "Skipping locale test, French locale not found")
+def test_locale_double():
+    return _test_locale_independance(np.double)
+
+ at np.testing.dec.skipif(not has_french_locale(),
+                       "Skipping locale test, French locale not found")
+def test_locale_longdouble():
+    return _test_locale_independance(np.longdouble)
+
 if __name__ == "__main__":
     run_module_suite()




More information about the Numpy-svn mailing list