]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34537: Fix test_gdb:test_strings with LC_ALL=C (GH-9483)
authorElvis Pranskevichus <elvis@magic.io>
Sat, 22 Sep 2018 01:13:16 +0000 (21:13 -0400)
committerVictor Stinner <vstinner@redhat.com>
Sat, 22 Sep 2018 01:13:16 +0000 (18:13 -0700)
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.

Lib/test/test_gdb.py
Misc/NEWS.d/next/Tests/2018-09-21-17-33-41.bpo-34537.GImYtZ.rst [new file with mode: 0644]

index c2ca57a4a04f6f6eaeb3c207bb083156f42b2e51..93a2c7dd57587e1b642efd7b930088069682bf69 100644 (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)
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 (file)
index 0000000..b64a6a7
--- /dev/null
@@ -0,0 +1,2 @@
+Fix ``test_gdb.test_strings()`` when ``LC_ALL=C`` and GDB was compiled with
+Python 3.6 or earlier.