[pypy-commit] pypy py3k: Fix all tests in module/_locale
amauryfa
noreply at buildbot.pypy.org
Wed Oct 19 23:11:14 CEST 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48240:149eb1fd7f2a
Date: 2011-10-19 22:31 +0200
http://bitbucket.org/pypy/pypy/changeset/149eb1fd7f2a/
Log: Fix all tests in module/_locale
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -73,8 +73,7 @@
if self.unicodedata_handler:
return self.unicodedata_handler
try:
- w_builtin = space.getbuiltinmodule('__builtin__')
- w_import = space.getattr(w_builtin, space.wrap("__import__"))
+ w_import = space.getattr(space.builtin, space.wrap("__import__"))
w_unicodedata = space.call_function(w_import,
space.wrap("unicodedata"))
w_getcode = space.getattr(w_unicodedata, space.wrap("_get_code"))
diff --git a/pypy/module/_locale/interp_locale.py b/pypy/module/_locale/interp_locale.py
--- a/pypy/module/_locale/interp_locale.py
+++ b/pypy/module/_locale/interp_locale.py
@@ -21,7 +21,7 @@
def _fixup_ulcase(space):
stringmod = space.call_function(
- space.getattr(space.getbuiltinmodule('__builtin__'),
+ space.getattr(space.getbuiltinmodule('builtins'),
space.wrap('__import__')), space.wrap('string'))
# create uppercase map string
ul = []
@@ -69,6 +69,12 @@
groups.append(space.wrap(0))
return space.newlist(groups)
+def charp2uni(space, s):
+ "Convert a char* pointer to unicode according to the current locale"
+ w_bytes = space.wrapbytes(rffi.charp2str(s))
+ # XXX use mbstowcs()
+ return space.call_method(w_bytes, "decode", space.wrap("utf-8"))
+
def localeconv(space):
"() -> dict. Returns numeric and monetary locale-specific parameters."
lp = rlocale.localeconv()
@@ -77,25 +83,25 @@
w_result = space.newdict()
w = space.wrap
space.setitem(w_result, w("decimal_point"),
- w(rffi.charp2str(lp.c_decimal_point)))
+ charp2uni(space, lp.c_decimal_point))
space.setitem(w_result, w("thousands_sep"),
- w(rffi.charp2str(lp.c_thousands_sep)))
+ charp2uni(space, lp.c_thousands_sep))
space.setitem(w_result, w("grouping"),
_w_copy_grouping(space, rffi.charp2str(lp.c_grouping)))
space.setitem(w_result, w("int_curr_symbol"),
- w(rffi.charp2str(lp.c_int_curr_symbol)))
+ charp2uni(space, lp.c_int_curr_symbol))
space.setitem(w_result, w("currency_symbol"),
- w(rffi.charp2str(lp.c_currency_symbol)))
+ charp2uni(space, lp.c_currency_symbol))
space.setitem(w_result, w("mon_decimal_point"),
- w(rffi.charp2str(lp.c_mon_decimal_point)))
+ charp2uni(space, lp.c_mon_decimal_point))
space.setitem(w_result, w("mon_thousands_sep"),
- w(rffi.charp2str(lp.c_mon_thousands_sep)))
+ charp2uni(space, lp.c_mon_thousands_sep))
space.setitem(w_result, w("mon_grouping"),
_w_copy_grouping(space, rffi.charp2str(lp.c_mon_grouping)))
space.setitem(w_result, w("positive_sign"),
- w(rffi.charp2str(lp.c_positive_sign)))
+ charp2uni(space, lp.c_positive_sign))
space.setitem(w_result, w("negative_sign"),
- w(rffi.charp2str(lp.c_negative_sign)))
+ charp2uni(space, lp.c_negative_sign))
space.setitem(w_result, w("int_frac_digits"),
w(lp.c_int_frac_digits))
space.setitem(w_result, w("frac_digits"),
@@ -115,29 +121,11 @@
return w_result
-_strcoll = rlocale.external('strcoll', [rffi.CCHARP, rffi.CCHARP], rffi.INT)
_wcscoll = rlocale.external('wcscoll', [rffi.CWCHARP, rffi.CWCHARP], rffi.INT)
def strcoll(space, w_s1, w_s2):
"string,string -> int. Compares two strings according to the locale."
- if space.is_true(space.isinstance(w_s1, space.w_str)) and \
- space.is_true(space.isinstance(w_s2, space.w_str)):
-
- s1, s2 = space.str_w(w_s1), space.str_w(w_s2)
- s1_c = rffi.str2charp(s1)
- s2_c = rffi.str2charp(s2)
- try:
- return space.wrap(_strcoll(s1_c, s2_c))
- finally:
- rffi.free_charp(s1_c)
- rffi.free_charp(s2_c)
-
- #if not space.is_true(space.isinstance(w_s1, space.w_unicode)) and \
- # not space.is_true(space.isinstance(w_s2, space.w_unicode)):
- # raise OperationError(space.w_ValueError,
- # space.wrap("strcoll arguments must be strings"))
-
s1, s2 = space.unicode_w(w_s1), space.unicode_w(w_s2)
s1_c = rffi.unicode2wcharp(s1)
diff --git a/pypy/module/_locale/test/test_locale.py b/pypy/module/_locale/test/test_locale.py
--- a/pypy/module/_locale/test/test_locale.py
+++ b/pypy/module/_locale/test/test_locale.py
@@ -35,6 +35,7 @@
_locale.setlocale(_locale.LC_ALL,
space.str_w(cls.w_language_pl))
except _locale.Error:
+ raise
py.test.skip("necessary locales not installed")
# Windows forbids the UTF-8 character set since Windows XP.
@@ -160,11 +161,11 @@
_locale.setlocale(_locale.LC_ALL, self.language_pl)
assert _locale.strcoll("a", "b") < 0
assert _locale.strcoll(
- u"\N{LATIN SMALL LETTER A WITH OGONEK}".encode(self.encoding_pl),
+ u"\N{LATIN SMALL LETTER A WITH OGONEK}",
"b") < 0
assert _locale.strcoll(
- u"\N{LATIN SMALL LETTER C WITH ACUTE}".encode(self.encoding_pl),
+ u"\N{LATIN SMALL LETTER C WITH ACUTE}",
"b") > 0
assert _locale.strcoll("c", "b") > 0
@@ -173,17 +174,6 @@
raises(TypeError, _locale.strcoll, 1, "b")
raises(TypeError, _locale.strcoll, "b", 1)
- def test_strcoll_unicode(self):
- import _locale
-
- _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
-
- raises(TypeError, _locale.strcoll, 1, u"b")
- raises(TypeError, _locale.strcoll, u"b", 1)
-
def test_strxfrm(self):
# TODO more tests would be nice
import _locale
More information about the pypy-commit
mailing list