bpo-34537: Fix test_gdb:test_strings with LC_ALL=C (GH-9483) · python/cpython@7279b51 (original) (raw)

Original file line number Diff line number Diff line change
@@ -321,7 +321,20 @@ def test_bytes(self):
321 321
322 322 def test_strings(self):
323 323 'Verify the pretty-printing of unicode strings'
324 -encoding = locale.getpreferredencoding()
324 +# We cannot simply call locale.getpreferredencoding() here,
325 +# as GDB might have been linked against a different version
326 +# of Python with a different encoding and coercion policy
327 +# with respect to PEP 538 and PEP 540.
328 +out, err = run_gdb(
329 +'--eval-command',
330 +'python import locale; print(locale.getpreferredencoding())')
331 +
332 +encoding = out.rstrip()
333 +if err or not encoding:
334 +raise RuntimeError(
335 +f'unable to determine the preferred encoding '
336 +f'of embedded Python in GDB: {err}')
337 +
325 338 def check_repr(text):
326 339 try:
327 340 text.encode(encoding)