From d8fcd5a8a46fbbab7db38bb5328da6ab05d6b5e6 Mon Sep 17 00:00:00 2001 From: Elvis Pranskevichus Date: Fri, 21 Sep 2018 17:30:05 -0400 Subject: [PATCH 1/3] bpo-34537: Fix test_gdb:test_strings with LC_ALL=C 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 | 16 +++++++++++++++- .../2018-09-21-17-33-41.bpo-34537.GImYtZ.rst | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Tests/2018-09-21-17-33-41.bpo-34537.GImYtZ.rst diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index c2ca57a4a04f6f..571bde2a71cf85 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -321,7 +321,21 @@ 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())') + + if err: + raise RuntimeError( + 'unable to determine the preferred encoding ' + 'of embedded Python in GDB.') + + encoding = out.strip() + 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 00000000000000..2d18fc633123e4 --- /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. From e28d2c6cb76e10a770d0b06aa57ffd7a94af8a53 Mon Sep 17 00:00:00 2001 From: Elvis Pranskevichus Date: Fri, 21 Sep 2018 18:40:35 -0400 Subject: [PATCH 2/3] Fix review comments. --- Lib/test/test_gdb.py | 10 +++++++--- .../Tests/2018-09-21-17-33-41.bpo-34537.GImYtZ.rst | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index 571bde2a71cf85..d475c026900ac2 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -331,10 +331,14 @@ def test_strings(self): if err: raise RuntimeError( - 'unable to determine the preferred encoding ' - 'of embedded Python in GDB.') + f'unable to determine the preferred encoding ' + f'of embedded Python in GDB: {err}') - encoding = out.strip() + encoding = out.rstrip() + if not encoding: + raise RuntimeError( + f'unable to determine the preferred encoding ' + f'of embedded Python in GDB: the command returned no output') def check_repr(text): try: 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 index 2d18fc633123e4..b64a6a762cdb69 100644 --- 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 @@ -1,2 +1,2 @@ -Fix test_gdb:test_strings when LC_ALL=C and GDB was compiled with Python 3.6 -or earlier. +Fix ``test_gdb.test_strings()`` when ``LC_ALL=C`` and GDB was compiled with +Python 3.6 or earlier. From eb693a0d1e6cf98c6379076e2e30f1c927ae4403 Mon Sep 17 00:00:00 2001 From: Elvis Pranskevichus Date: Fri, 21 Sep 2018 19:17:30 -0400 Subject: [PATCH 3/3] Nit --- Lib/test/test_gdb.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index d475c026900ac2..93a2c7dd57587e 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -329,16 +329,11 @@ def test_strings(self): '--eval-command', 'python import locale; print(locale.getpreferredencoding())') - if err: - raise RuntimeError( - f'unable to determine the preferred encoding ' - f'of embedded Python in GDB: {err}') - encoding = out.rstrip() - if not encoding: + if err or not encoding: raise RuntimeError( f'unable to determine the preferred encoding ' - f'of embedded Python in GDB: the command returned no output') + f'of embedded Python in GDB: {err}') def check_repr(text): try: