[pypy-svn] r62314 - in pypy/trunk/pypy/module/_locale: . test

afa at codespeak.net afa at codespeak.net
Mon Mar 2 01:10:32 CET 2009


Author: afa
Date: Mon Mar  2 01:10:29 2009
New Revision: 62314

Modified:
   pypy/trunk/pypy/module/_locale/__init__.py
   pypy/trunk/pypy/module/_locale/interp_locale.py
   pypy/trunk/pypy/module/_locale/test/test_locale.py
Log:
Port most of the _locale module to windows


Modified: pypy/trunk/pypy/module/_locale/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/_locale/__init__.py	(original)
+++ pypy/trunk/pypy/module/_locale/__init__.py	Mon Mar  2 01:10:29 2009
@@ -1,4 +1,5 @@
 from pypy.interpreter.mixedmodule import MixedModule
+from pypy.module._locale import interp_locale
 
 class Module(MixedModule):
     """Support for POSIX locales."""
@@ -9,14 +10,21 @@
             'strcoll':                  'interp_locale.strcoll',
             'strxfrm':                  'interp_locale.strxfrm',
             #'getdefaultlocale':        'interp_locale.getdefaultlocale',
+            }
+
+    if interp_locale.HAVE_LANGINFO:
+        interpleveldefs.update({
+            'nl_langinfo':              'interp_locale.nl_langinfo',
+            })
+    if interp_locale.HAVE_LIBINTL:
+        interpleveldefs.update({
             'gettext':                  'interp_locale.gettext',
             'dgettext':                 'interp_locale.dgettext',
             'dcgettext':                'interp_locale.dcgettext',
             'textdomain':               'interp_locale.textdomain',
-            'nl_langinfo':              'interp_locale.nl_langinfo',
             'bindtextdomain':           'interp_locale.bindtextdomain',
             'bind_textdomain_codeset':  'interp_locale.bind_textdomain_codeset',
-            }
+            })
 
     appleveldefs  = {
             'Error':               'app_locale.Error',
@@ -24,7 +32,6 @@
             }
 
     def buildloaders(cls):
-        from pypy.module._locale import interp_locale
         for constant, value in interp_locale.constants.iteritems():
             Module.interpleveldefs[constant] = "space.wrap(%r)" % value
         super(Module, cls).buildloaders()

Modified: pypy/trunk/pypy/module/_locale/interp_locale.py
==============================================================================
--- pypy/trunk/pypy/module/_locale/interp_locale.py	(original)
+++ pypy/trunk/pypy/module/_locale/interp_locale.py	Mon Mar  2 01:10:29 2009
@@ -7,9 +7,17 @@
 
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 
+import sys
+
+HAVE_LANGINFO = sys.platform != 'win32'
+HAVE_LIBINTL  = sys.platform != 'win32'
+
 class CConfig:
+    includes = ['locale.h', 'limits.h']
+    if HAVE_LANGINFO:
+        includes += ['langinfo.h']
     _compilation_info_ = ExternalCompilationInfo(
-        includes = ['locale.h', 'langinfo.h', 'limits.h']
+        includes=includes,
     )
     lconv = platform.Struct("struct lconv", [
             # Numeric (non-monetary) information.

Modified: pypy/trunk/pypy/module/_locale/test/test_locale.py
==============================================================================
--- pypy/trunk/pypy/module/_locale/test/test_locale.py	(original)
+++ pypy/trunk/pypy/module/_locale/test/test_locale.py	Mon Mar  2 01:10:29 2009
@@ -6,6 +6,14 @@
 class AppTestLocaleTrivia:
     def setup_class(cls):
         cls.space = gettestobjspace(usemodules=['_locale'])
+        if sys.platform != 'win32':
+            cls.w_language_en = cls.space.wrap("en_US")
+            cls.w_language_utf8 = cls.space.wrap("en_US.UTF-8")
+            cls.w_language_pl = cls.space.wrap("pl_PL")
+        else:
+            cls.w_language_en = cls.space.wrap("English_US")
+            cls.w_language_utf8 = cls.space.wrap("English_US.65001")
+            cls.w_language_pl = cls.space.wrap("Polish_Poland")
 
     def test_import(self):
         import _locale
@@ -14,22 +22,24 @@
         import locale
         assert locale
 
-    def test_contants(self):
+    def test_constants(self):
         _CONSTANTS = (
             'LC_CTYPE',
             'LC_NUMERIC',
             'LC_TIME',
             'LC_COLLATE',
             'LC_MONETARY',
-            'LC_MESSAGES',
             'LC_ALL',
-            'LC_PAPER',
-            'LC_NAME',
-            'LC_ADDRESS',
-            'LC_TELEPHONE',
-            'LC_MEASUREMENT',
-            'LC_IDENTIFICATION',
             'CHAR_MAX',
+
+            # These are optional
+            #'LC_MESSAGES',
+            #'LC_PAPER',
+            #'LC_NAME',
+            #'LC_ADDRESS',
+            #'LC_TELEPHONE',
+            #'LC_MEASUREMENT',
+            #'LC_IDENTIFICATION',
         )
 
         import _locale
@@ -40,9 +50,9 @@
     def test_setlocale(self):
         import _locale
 
-        raises(TypeError, _locale.setlocale, "", "en_US")
+        raises(TypeError, _locale.setlocale, "", self.language_en)
         raises(TypeError, _locale.setlocale, _locale.LC_ALL, 6)
-        raises(_locale.Error, _locale.setlocale, 123456, "en_US")
+        raises(_locale.Error, _locale.setlocale, 123456, self.language_en)
 
         assert _locale.setlocale(_locale.LC_ALL, None)
         assert _locale.setlocale(_locale.LC_ALL)
@@ -53,11 +63,11 @@
         lcase = "abcdefghijklmnopqrstuvwxyz"
         ucase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
-        _locale.setlocale(_locale.LC_ALL, "en_US.UTF-8")
+        _locale.setlocale(_locale.LC_ALL, self.language_utf8)
         assert string.lowercase == lcase
         assert string.uppercase == ucase
 
-        _locale.setlocale(_locale.LC_ALL, "en_US")
+        _locale.setlocale(_locale.LC_ALL, self.language_en)
 
         assert string.lowercase != lcase
         assert string.uppercase != ucase
@@ -94,7 +104,7 @@
     def test_strcoll(self):
         import _locale
 
-        _locale.setlocale(_locale.LC_ALL, "pl_PL.UTF-8")
+        _locale.setlocale(_locale.LC_ALL, self.language_pl)
         assert _locale.strcoll("a", "b") < 0
         assert _locale.strcoll("ą", "b") < 0
 
@@ -109,7 +119,7 @@
     def test_strcoll_unicode(self):
         import _locale
 
-        _locale.setlocale(_locale.LC_ALL, "pl_PL.UTF-8")
+        _locale.setlocale(_locale.LC_ALL, self.language_pl)
         assert _locale.strcoll(u"b", u"b") == 0
         assert _locale.strcoll(u"a", u"b") < 0
         assert _locale.strcoll(u"b", u"a") > 0
@@ -129,7 +139,7 @@
 
         raises(TypeError, _locale.strxfrm, 1)
 
-        _locale.setlocale(_locale.LC_ALL, "pl_PL.UTF-8")
+        _locale.setlocale(_locale.LC_ALL, self.language_pl)
         a = "1234"
         b = _locale.strxfrm(a)
         assert a is not b
@@ -138,12 +148,16 @@
         import _locale
         import locale
 
-        _locale.setlocale(_locale.LC_ALL, "en_US.UTF-8")
+        _locale.setlocale(_locale.LC_ALL, self.language_en)
         assert locale.str(1.1) == '1.1'
-        _locale.setlocale(_locale.LC_ALL, "pl_PL.UTF-8")
+        _locale.setlocale(_locale.LC_ALL, self.language_pl)
         assert locale.str(1.1) == '1,1'
 
     def test_text(self):
+        import sys
+        if sys.platform == 'win32':
+            skip("No gettext on Windows")
+
         # TODO more tests would be nice
         import _locale
 
@@ -153,6 +167,10 @@
         assert _locale.textdomain("1234") == "1234"
 
     def test_nl_langinfo(self):
+        import sys
+        if sys.platform == 'win32':
+            skip("No langinfo on Windows")
+
         import _locale
 
         langinfo_consts = [
@@ -221,6 +239,10 @@
         raises(TypeError, _locale.nl_langinfo, None)
     
     def test_bindtextdomain(self):
+        import sys
+        if sys.platform == 'win32':
+            skip("No textdomain on Windows")
+
         # TODO more tests would be nice
         import _locale
 
@@ -228,6 +250,10 @@
         raises(OSError, _locale.bindtextdomain, '', '1')
 
     def test_bind_textdomain_codeset(self):
+        import sys
+        if sys.platform == 'win32':
+            skip("No textdomain on Windows")
+
         import _locale
 
         assert _locale.bind_textdomain_codeset('/', None) is None



More information about the Pypy-commit mailing list