]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-29571: Fix test_re.test_locale_flag() (GH-12099)
authorVictor Stinner <vstinner@redhat.com>
Thu, 28 Feb 2019 23:08:03 +0000 (00:08 +0100)
committerGitHub <noreply@github.com>
Thu, 28 Feb 2019 23:08:03 +0000 (00:08 +0100)
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.

Lib/test/test_re.py
Misc/NEWS.d/next/Tests/2019-02-28-18-33-29.bpo-29571.r6b9fr.rst [new file with mode: 0644]

index 797d85d0629c94b23159ea330746bbead08e6e48..0a77e6fe9edc03690a84c385cb3a89ebf340a0f3 100644 (file)
@@ -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 (file)
index 0000000..0f40c98
--- /dev/null
@@ -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.