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

afa at codespeak.net afa at codespeak.net
Tue Dec 1 13:56:20 CET 2009


Author: afa
Date: Tue Dec  1 13:56:20 2009
New Revision: 69798

Modified:
   pypy/trunk/pypy/module/_locale/interp_locale.py
   pypy/trunk/pypy/module/_locale/test/test_locale.py
Log:
Fixes the tests for the _locale module on windows:

- Remove utf-8 constants from the file: they are not reliable when geninterp'd,
and windows XP removed support for utf-8 locale anyway.
Use the (verbose) name of the characters instead, and the cp1257 code page to handle Polish letters.

- remove some constants from the module interface,
"LOCALE_SISO3166CTRYNAME" &co can't be used with the _locale module.

Still remains: a segfault when pypy-c calls "_locale.setlocale(12345)"


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	Tue Dec  1 13:56:20 2009
@@ -131,7 +131,7 @@
 
 for name in langinfo_names:
     value = getattr(cConfig, name)
-    if value is not None:
+    if value is not None and sys.platform != 'win32':
         constants[name] = value
 
 locals().update(constants)

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	Tue Dec  1 13:56:20 2009
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 import py
 from pypy.conftest import gettestobjspace
 
@@ -11,21 +10,31 @@
             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.UTF-8")
+            cls.w_encoding_pl = cls.space.wrap("utf-8")
         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")
+            cls.w_language_pl = cls.space.wrap("Polish_Poland.1257")
+            cls.w_encoding_pl = cls.space.wrap("cp1257")
         import _locale
         # check whether used locales are installed, otherwise the tests will
         # fail
         current = _locale.setlocale(_locale.LC_ALL)
         try:
             try:
-                _locale.setlocale(_locale.LC_ALL, space.str_w(cls.w_language_en))
-                _locale.setlocale(_locale.LC_ALL, space.str_w(cls.w_language_utf8))
-                _locale.setlocale(_locale.LC_ALL, space.str_w(cls.w_language_pl))
+                _locale.setlocale(_locale.LC_ALL,
+                                  space.str_w(cls.w_language_en))
+                _locale.setlocale(_locale.LC_ALL,
+                                  space.str_w(cls.w_language_pl))
             except _locale.Error:
                 py.test.skip("necessary locales not installed")
+
+            # Windows forbids the UTF-8 character set since Windows XP.
+            try:
+                _locale.setlocale(_locale.LC_ALL,
+                                  space.str_w(cls.w_language_utf8))
+            except _locale.Error:
+                del cls.w_language_utf8
         finally:
             _locale.setlocale(_locale.LC_ALL, current)
 
@@ -76,13 +85,9 @@
             for i in range(1, 13):
                 _LANGINFO_NAMES.append("MON_%d" % i)
                 _LANGINFO_NAMES.append("ABMON_%d" % i)
-        else:
-            _LANGINFO_NAMES = ('LOCALE_USER_DEFAULT LOCALE_SISO639LANGNAME '
-                            'LOCALE_SISO3166CTRYNAME LOCALE_IDEFAULTLANGUAGE '
-                            '').split()
 
-        for constant in _LANGINFO_NAMES:
-            assert hasattr(_locale, constant)
+            for constant in _LANGINFO_NAMES:
+                assert hasattr(_locale, constant)
 
     def test_setlocale(self):
         import _locale
@@ -95,6 +100,8 @@
         assert _locale.setlocale(_locale.LC_ALL)
 
     def test_string_ulcase(self):
+        if not hasattr(self, 'language_utf8'):
+            skip("No utf8 locale on this platform")
         import _locale, string
 
         lcase = "abcdefghijklmnopqrstuvwxyz"
@@ -143,9 +150,13 @@
 
         _locale.setlocale(_locale.LC_ALL, self.language_pl)
         assert _locale.strcoll("a", "b") < 0
-        assert _locale.strcoll("ą", "b") < 0
-
-        assert _locale.strcoll("ć", "b") > 0
+        assert _locale.strcoll(
+            u"\N{LATIN SMALL LETTER A WITH OGONEK}".encode(self.encoding_pl),
+            "b") < 0
+
+        assert _locale.strcoll(
+            u"\N{LATIN SMALL LETTER C WITH ACUTE}".encode(self.encoding_pl),
+            "b") > 0
         assert _locale.strcoll("c", "b") > 0
 
         assert _locale.strcoll("b", "b") == 0



More information about the Pypy-commit mailing list