bpo-34537: Fix test_gdb:test_strings with LC_ALL=C (GH-9483)

We cannot simply call locale.getpreferredencoding() here,
as GDB might have been linked against a different version
of Python with a different encoding and coercion policy
with respect to PEP 538 and PEP 540.

Thanks to Victor Stinner for a hint on how to fix this.
(cherry picked from commit 7279b5125e)

Co-authored-by: Elvis Pranskevichus <elvis@magic.io>
This commit is contained in:
Miss Islington (bot) 2018-09-21 18:29:34 -07:00 committed by GitHub
parent e45662c28b
commit e5fde1f992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -321,7 +321,20 @@ class PrettyPrintTests(DebuggerTests):
def test_strings(self):
'Verify the pretty-printing of unicode strings'
encoding = locale.getpreferredencoding()
# We cannot simply call locale.getpreferredencoding() here,
# as GDB might have been linked against a different version
# of Python with a different encoding and coercion policy
# with respect to PEP 538 and PEP 540.
out, err = run_gdb(
'--eval-command',
'python import locale; print(locale.getpreferredencoding())')
encoding = out.rstrip()
if err or not encoding:
raise RuntimeError(
f'unable to determine the preferred encoding '
f'of embedded Python in GDB: {err}')
def check_repr(text):
try:
text.encode(encoding)

View File

@ -0,0 +1,2 @@
Fix ``test_gdb.test_strings()`` when ``LC_ALL=C`` and GDB was compiled with
Python 3.6 or earlier.