summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-02-28 23:08:03 (GMT)
committerGitHub <noreply@github.com>2019-02-28 23:08:03 (GMT)
commitab71f8b793f7b42853ccd2a127ae7720adc5bcb4 (patch)
treeeef5c69bee6a9eaf46c11a4e7f809ac27ea11e08
parentef17fdbc1c274dc84c2f611c40449ab84824607e (diff)
downloadcpython-ab71f8b793f7b42853ccd2a127ae7720adc5bcb4.zip
cpython-ab71f8b793f7b42853ccd2a127ae7720adc5bcb4.tar.gz
cpython-ab71f8b793f7b42853ccd2a127ae7720adc5bcb4.tar.bz2
bpo-29571: Fix test_re.test_locale_flag() (GH-12099)
Use locale.getpreferredencoding() rather than locale.getlocale() to get the locale encoding. With some locales, locale.getlocale() returns the wrong encoding. For example, on Fedora 29, locale.getlocale() returns ISO-8859-1 encoding for the "en_IN" locale, whereas locale.getpreferredencoding() reports the correct encoding: UTF-8.
-rw-r--r--Lib/test/test_re.py3
-rw-r--r--Misc/NEWS.d/next/Tests/2019-02-28-18-33-29.bpo-29571.r6b9fr.rst3
2 files changed, 4 insertions, 2 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 797d85d..0a77e6f 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1552,8 +1552,7 @@ class ReTests(unittest.TestCase):
self.assertRaises(re.error, re.compile, r'(?au)\w')
def test_locale_flag(self):
- import locale
- _, enc = locale.getlocale(locale.LC_CTYPE)
+ enc = locale.getpreferredencoding()
# Search non-ASCII letter
for i in range(128, 256):
try:
diff --git a/Misc/NEWS.d/next/Tests/2019-02-28-18-33-29.bpo-29571.r6b9fr.rst b/Misc/NEWS.d/next/Tests/2019-02-28-18-33-29.bpo-29571.r6b9fr.rst
new file mode 100644
index 0000000..0f40c98
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-02-28-18-33-29.bpo-29571.r6b9fr.rst
@@ -0,0 +1,3 @@
+Fix ``test_re.test_locale_flag()``: use ``locale.getpreferredencoding()``
+rather than ``locale.getlocale()`` to get the locale encoding. With some
+locales, ``locale.getlocale()`` returns the wrong encoding.