[Numpy-svn] r6237 - trunk/numpy/core/tests

numpy-svn@scip... numpy-svn@scip...
Mon Dec 29 02:26:07 CST 2008


Author: cdavid
Date: 2008-12-29 02:26:04 -0600 (Mon, 29 Dec 2008)
New Revision: 6237

Modified:
   trunk/numpy/core/tests/test_print.py
Log:
Add test for real float types locale independance.

Modified: trunk/numpy/core/tests/test_print.py
===================================================================
--- trunk/numpy/core/tests/test_print.py	2008-12-29 08:02:15 UTC (rev 6236)
+++ trunk/numpy/core/tests/test_print.py	2008-12-29 08:26:04 UTC (rev 6237)
@@ -1,6 +1,9 @@
 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)))
@@ -48,5 +51,52 @@
     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)))
+    finally:
+        locale.setlocale(locale.LC_NUMERIC, locale=curloc)
+
+@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)
+
+@np.testing.dec.skipif(not has_french_locale(),
+                       "Skipping locale test, French locale not found")
+def test_locale_double():
+    return _test_locale_independance(np.float64)
+
+@np.testing.dec.skipif(not has_french_locale(),
+                       "Skipping locale test, French locale not found")
+def test_locale_longdouble():
+    return _test_locale_independance(np.float96)
+
 if __name__ == "__main__":
     run_module_suite()



More information about the Numpy-svn mailing list