From 329e74df8929dbdbf8bfc60d51a0268f8289926f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 28 Feb 2019 18:30:28 +0100 Subject: [PATCH] bpo-29571: 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. 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 | 3 +-- .../NEWS.d/next/Tests/2019-02-28-18-33-29.bpo-29571.r6b9fr.rst | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2019-02-28-18-33-29.bpo-29571.r6b9fr.rst diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 797d85d0629c94..0a77e6fe9edc03 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1552,8 +1552,7 @@ def test_ascii_and_unicode_flag(self): 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 00000000000000..0f40c98514ce9b --- /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.