Debian Codegraph @

rpython/rlib/test/test_rlocale.py

raw symbols SCIP
1
2 # -*- coding: utf-8 -*-
3
4 import py, sys
5 import locale as cpython_locale
6 from rpython.rlib.rlocale import setlocale, LC_ALL, LocaleError, isupper, \
7 islower, isalpha, tolower, isalnum, numeric_formatting, external
8 from rpython.rtyper.lltypesystem import rffi
9
10 class TestLocale(object):
11 def setup_class(cls):
12 try:
13 cls.oldlocale = setlocale(LC_ALL, "pl_PL.utf8")
14 except LocaleError:
15 py.test.skip("polish locale unsupported")
16
17 def teardown_class(cls):
18 if hasattr(cls, "oldlocale"):
19 setlocale(LC_ALL, cls.oldlocale)
20
21 def test_setlocale_worked(self):
22 assert u"Ą".isupper()
23 py.test.raises(LocaleError, setlocale, LC_ALL, "bla bla bla")
24 py.test.raises(LocaleError, setlocale, 1234455, None)
25
26 def test_lower_upper(self):
27 assert isupper(ord("A"))
28 assert islower(ord("a"))
29 assert not isalpha(ord(" "))
30 assert isalnum(ord("1"))
31 assert tolower(ord("A")) == ord("a")
32
33 def test_numeric_formatting():
34 dec, th, grouping = numeric_formatting()
35 assert isinstance(dec, str)
36 assert isinstance(th, str)
37 assert isinstance(grouping, str)
38
39 def test_libintl():
40 if sys.platform != "darwin" and not sys.platform.startswith("linux"):
41 py.test.skip("there is (maybe) no libintl here")
42 _gettext = external('gettext', [rffi.CCHARP], rffi.CCHARP)
43 p = rffi.str2charp("1234")
44 res = _gettext(p)
45 assert res == p
46 assert rffi.charp2str(res) == "1234"
47 rffi.free_charp(p)