FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.7] bpo-29571: Fix test_re.test_locale_flag() by vstinner · Pull Request #12178 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 12 additions & 2 deletions Lib/test/test_re.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1516,8 +1516,18 @@ 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)
# On Windows, Python 3.7 doesn't call setlocale(LC_CTYPE, "") at
# startup and so the LC_CTYPE locale uses Latin1 encoding by default,
# whereas getpreferredencoding() returns the ANSI code page. Set
# temporarily the LC_CTYPE locale to the user preferred encoding to
# ensure that it uses the ANSI code page.
oldloc = locale.setlocale(locale.LC_CTYPE, None)
locale.setlocale(locale.LC_CTYPE, "")
self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldloc)

# Get the current locale encoding
enc = locale.getpreferredencoding(False)

# Search non-ASCII letter
for i in range(128, 256):
try:
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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. On Windows, set
temporarily the ``LC_CTYPE`` locale to the user preferred encoding to ensure
that it uses the ANSI code page, to be consistent with
``locale.getpreferredencoding()``.

Back | FazBrowse Home | New Git URL