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.
This commit is contained in:
Victor Stinner 2019-03-01 00:08:03 +01:00 committed by GitHub
parent ef17fdbc1c
commit ab71f8b793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View 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:

View File

@ -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.