summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-10-19 19:47:59 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-10-19 19:47:59 (GMT)
commiteda95e9db3e15ebc19979eab948a75272d8cbdcf (patch)
tree9e374c5cf279d600943f57543adccf902b6d5c09 /Lib
parentbc740a6951b2d234fc69936c7ff4713a503f20cf (diff)
downloadcpython-eda95e9db3e15ebc19979eab948a75272d8cbdcf.zip
cpython-eda95e9db3e15ebc19979eab948a75272d8cbdcf.tar.gz
cpython-eda95e9db3e15ebc19979eab948a75272d8cbdcf.tar.bz2
Merged revisions 75537,75539 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r75537 | antoine.pitrou | 2009-10-19 21:37:25 +0200 (lun., 19 oct. 2009) | 3 lines egreen is Derk Drukker + fix NEWS formatting ........ r75539 | antoine.pitrou | 2009-10-19 21:43:09 +0200 (lun., 19 oct. 2009) | 4 lines Issue #7080: locale.strxfrm() raises a MemoryError on 64-bit non-Windows platforms, and assorted locale fixes by Derk Drukker. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/locale.py3
-rw-r--r--Lib/test/test_locale.py49
2 files changed, 41 insertions, 11 deletions
diff --git a/Lib/locale.py b/Lib/locale.py
index 54d4c0e..f74207d 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -575,14 +575,13 @@ else:
# returning nothing will crash the
# interpreter.
result = 'UTF-8'
-
setlocale(LC_CTYPE, oldloc)
- return result
else:
result = nl_langinfo(CODESET)
if not result and sys.platform == 'darwin':
# See above for explanation
result = 'UTF-8'
+ return result
### Database
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
index 65639ad..8dfaf90 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -8,12 +8,10 @@ enUS_locale = None
def get_enUS_locale():
global enUS_locale
- if sys.platform == 'darwin':
- raise unittest.SkipTest("Locale support on MacOSX is minimal")
if sys.platform.startswith("win"):
tlocs = ("En", "English")
else:
- tlocs = ("en_US.UTF-8", "en_US.US-ASCII", "en_US")
+ tlocs = ("en_US.UTF-8", "en_US.ISO8859-1", "en_US.US-ASCII", "en_US")
oldlocale = locale.setlocale(locale.LC_NUMERIC)
for tloc in tlocs:
try:
@@ -309,6 +307,39 @@ class TestFrFRNumberFormatting(FrFRCookedTest, BaseFormattingTest):
grouping=True, international=True)
+class TestCollation(unittest.TestCase):
+ # Test string collation functions
+
+ def test_strcoll(self):
+ self.assertLess(locale.strcoll('a', 'b'), 0)
+ self.assertEqual(locale.strcoll('a', 'a'), 0)
+ self.assertGreater(locale.strcoll('b', 'a'), 0)
+
+ def test_strxfrm(self):
+ self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
+
+
+class TestEnUSCollation(BaseLocalizedTest, TestCollation):
+ # Test string collation functions with a real English locale
+
+ locale_type = locale.LC_ALL
+
+ def setUp(self):
+ BaseLocalizedTest.setUp(self)
+ enc = codecs.lookup(locale.getpreferredencoding(False) or 'ascii').name
+ if enc not in ('utf-8', 'iso8859-1', 'cp1252'):
+ raise unittest.SkipTest('encoding not suitable')
+ if enc != 'iso8859-1' and (sys.platform == 'darwin' or
+ sys.platform.startswith('freebsd')):
+ raise unittest.SkipTest('wcscoll/wcsxfrm have known bugs')
+
+ def test_strcoll_with_diacritic(self):
+ self.assertLess(locale.strcoll('à', 'b'), 0)
+
+ def test_strxfrm_with_diacritic(self):
+ self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
+
+
class TestMiscellaneous(unittest.TestCase):
def test_getpreferredencoding(self):
# Invoke getpreferredencoding to make sure it does not cause exceptions.
@@ -317,11 +348,10 @@ class TestMiscellaneous(unittest.TestCase):
# If encoding non-empty, make sure it is valid
codecs.lookup(enc)
- if hasattr(locale, "strcoll"):
- def test_strcoll_3303(self):
- # test crasher from bug #3303
- self.assertRaises(TypeError, locale.strcoll, "a", None)
- self.assertRaises(TypeError, locale.strcoll, b"a", None)
+ def test_strcoll_3303(self):
+ # test crasher from bug #3303
+ self.assertRaises(TypeError, locale.strcoll, "a", None)
+ self.assertRaises(TypeError, locale.strcoll, b"a", None)
def test_main():
@@ -331,6 +361,7 @@ def test_main():
TestEnUSNumberFormatting,
TestCNumberFormatting,
TestFrFRNumberFormatting,
+ TestCollation
]
# SkipTest can't be raised inside unittests, handle it manually instead
try:
@@ -339,7 +370,7 @@ def test_main():
if verbose:
print("Some tests will be disabled: %s" % e)
else:
- tests += [TestNumberFormatting]
+ tests += [TestNumberFormatting, TestEnUSCollation]
run_unittest(*tests)
if __name__ == '__main__':