]> granicus.if.org Git - python/commitdiff
bpo-29571: Use correct locale encoding in test_re (#149)
authorNick Coghlan <ncoghlan@gmail.com>
Sat, 18 Feb 2017 09:31:22 +0000 (15:01 +0530)
committerGitHub <noreply@github.com>
Sat, 18 Feb 2017 09:31:22 +0000 (15:01 +0530)
``local.getlocale(locale.LC_CTYPE)`` and
``locale.getpreferredencoding(False)`` may give different answers
in some cases (such as the ``en_IN`` locale).

``re.LOCALE`` uses the latter, so update the test case to match.

Lib/test/test_re.py
Misc/NEWS

index 1d7fb76c383396057f10f540b9c6ebe5ec6808bb..92d2c1386de464771ce8033f37bea529d61c1190 100644 (file)
@@ -1399,7 +1399,7 @@ class ReTests(unittest.TestCase):
 
     def test_locale_flag(self):
         import locale
-        _, enc = locale.getlocale(locale.LC_CTYPE)
+        enc = locale.getpreferredencoding(False)
         # Search non-ASCII letter
         for i in range(128, 256):
             try:
index 1422627b9052a23850da728af24b812ef9036913..53f1dc6d7f0c4f3f2a644432d8fe685e96175558 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -801,6 +801,11 @@ Tools/Demos
 Tests
 -----
 
+- Issue #29571: to match the behaviour of the ``re.LOCALE`` flag,
+  test_re.test_locale_flag now uses ``locale.getpreferredencoding(False)`` to
+  determine the candidate encoding for the test regex (allowing it to correctly
+  skip the test when the default locale encoding is a multi-byte encoding)
+
 - Issue #24932: Use proper command line parsing in _testembed
 
 - Issue #28950: Disallow -j0 to be combined with -T/-l in regrtest