[Python-checkins] cpython (merge 3.2 -> default): Add a test for issue #1813: getlocale() failing under a Turkish locale
antoine.pitrou
python-checkins at python.org
Sun Jul 24 02:43:23 CEST 2011
http://hg.python.org/cpython/rev/fe0caf8c48d2
changeset: 71491:fe0caf8c48d2
parent: 71488:01d18277c40b
parent: 71490:a77a4df54b95
user: Antoine Pitrou <solipsis at pitrou.net>
date: Sun Jul 24 02:41:54 2011 +0200
summary:
Add a test for issue #1813: getlocale() failing under a Turkish locale
(not a problem under 3.x)
files:
Lib/test/test_codecs.py | 14 ++++++++++++++
Lib/test/test_locale.py | 13 +++++++++++++
Misc/NEWS | 2 ++
Python/codecs.c | 2 +-
4 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1,6 +1,7 @@
from test import support
import unittest
import codecs
+import locale
import sys, _testcapi, io
class Queue(object):
@@ -1230,6 +1231,19 @@
self.assertRaises(TypeError, codecs.getwriter)
self.assertRaises(LookupError, codecs.getwriter, "__spam__")
+ def test_lookup_issue1813(self):
+ # Issue #1813: under Turkish locales, lookup of some codecs failed
+ # because 'I' is lowercased as "ı" (dotless i)
+ oldlocale = locale.getlocale(locale.LC_CTYPE)
+ self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
+ try:
+ locale.setlocale(locale.LC_CTYPE, 'tr_TR')
+ except locale.Error:
+ # Unsupported locale on this system
+ self.skipTest('test needs Turkish locale')
+ c = codecs.lookup('ASCII')
+ self.assertEqual(c.name, 'ascii')
+
class StreamReaderTest(unittest.TestCase):
def setUp(self):
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -391,6 +391,19 @@
# crasher from bug #7419
self.assertRaises(locale.Error, locale.setlocale, 12345)
+ def test_getsetlocale_issue1813(self):
+ # Issue #1813: setting and getting the locale under a Turkish locale
+ oldlocale = locale.getlocale()
+ self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
+ try:
+ locale.setlocale(locale.LC_CTYPE, 'tr_TR')
+ except locale.Error:
+ # Unsupported locale on this system
+ self.skipTest('test needs Turkish locale')
+ loc = locale.getlocale()
+ locale.setlocale(locale.LC_CTYPE, loc)
+ self.assertEqual(loc, locale.getlocale())
+
def test_main():
tests = [
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -237,6 +237,8 @@
Library
-------
+- Issue #1813: Fix codec lookup under Turkish locales.
+
- Issue #12591: Improve support of "universal newlines" in the subprocess
module: the piped streams can now be properly read from or written to.
diff --git a/Python/codecs.c b/Python/codecs.c
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -69,7 +69,7 @@
if (ch == ' ')
ch = '-';
else
- ch = tolower(Py_CHARMASK(ch));
+ ch = Py_TOLOWER(Py_CHARMASK(ch));
p[i] = ch;
}
p[i] = '\0';
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list