[3.14] gh-133711: Fix test_readline.test_nonascii() for UTF-8 Mode (GH-134841) (#134851)

gh-133711: Fix test_readline.test_nonascii() for UTF-8 Mode (GH-134841)

Skip the test if the Python UTF-8 Mode is enabled and the LC_CTYPE
encoding is not UTF-8.
(cherry picked from commit 4635115c3f)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2025-05-28 18:10:37 +02:00 committed by GitHub
parent 24404494fb
commit 072d03352c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
""" """
Very minimal unittests for parts of the readline module. Very minimal unittests for parts of the readline module.
""" """
import codecs
import locale import locale
import os import os
import sys import sys
@ -231,6 +232,13 @@ def test_nonascii(self):
# writing and reading non-ASCII bytes into/from a TTY works, but # writing and reading non-ASCII bytes into/from a TTY works, but
# readline or ncurses ignores non-ASCII bytes on read. # readline or ncurses ignores non-ASCII bytes on read.
self.skipTest(f"the LC_CTYPE locale is {loc!r}") self.skipTest(f"the LC_CTYPE locale is {loc!r}")
if sys.flags.utf8_mode:
encoding = locale.getencoding()
encoding = codecs.lookup(encoding).name # normalize the name
if encoding != "utf-8":
# gh-133711: The Python UTF-8 Mode ignores the LC_CTYPE locale
# and always use the UTF-8 encoding.
self.skipTest(f"the LC_CTYPE encoding is {encoding!r}")
try: try:
readline.add_history("\xEB\xEF") readline.add_history("\xEB\xEF")