[Python-checkins] bpo-34537: Fix test_gdb:test_strings with LC_ALL=C (GH-9483)
Victor Stinner
webhook-mailer at python.org
Fri Sep 21 21:13:24 EDT 2018
https://github.com/python/cpython/commit/7279b5125e7c5d84a473d250b27d353cb7f6628e
commit: 7279b5125e7c5d84a473d250b27d353cb7f6628e
branch: master
author: Elvis Pranskevichus <elvis at magic.io>
committer: Victor Stinner <vstinner at redhat.com>
date: 2018-09-21T18:13:16-07:00
summary:
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.
files:
A Misc/NEWS.d/next/Tests/2018-09-21-17-33-41.bpo-34537.GImYtZ.rst
M Lib/test/test_gdb.py
diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
index c2ca57a4a04f..93a2c7dd5758 100644
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -321,7 +321,20 @@ def test_bytes(self):
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)
diff --git a/Misc/NEWS.d/next/Tests/2018-09-21-17-33-41.bpo-34537.GImYtZ.rst b/Misc/NEWS.d/next/Tests/2018-09-21-17-33-41.bpo-34537.GImYtZ.rst
new file mode 100644
index 000000000000..b64a6a762cdb
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2018-09-21-17-33-41.bpo-34537.GImYtZ.rst
@@ -0,0 +1,2 @@
+Fix ``test_gdb.test_strings()`` when ``LC_ALL=C`` and GDB was compiled with
+Python 3.6 or earlier.
More information about the Python-checkins
mailing list