MCPcopy Index your code
hub / github.com/python/cpython / test_strings

Method test_strings

Lib/test/test_gdb/test_pretty_print.py:115–159  ·  view source on GitHub ↗

Verify the pretty-printing of unicode strings

(self)

Source from the content-addressed store, hash-verified

113
114 @support.requires_resource('cpu')
115 def test_strings(self):
116 'Verify the pretty-printing of unicode strings'
117 # We cannot simply call locale.getpreferredencoding() here,
118 # as GDB might have been linked against a different version
119 # of Python with a different encoding and coercion policy
120 # with respect to PEP 538 and PEP 540.
121 stdout, stderr = run_gdb(
122 '--eval-command',
123 'python import locale; print(locale.getpreferredencoding())')
124
125 encoding = stdout
126 if stderr or not encoding:
127 raise RuntimeError(
128 f'unable to determine the Python locale preferred encoding '
129 f'of embedded Python in GDB\n'
130 f'stdout={stdout!r}\n'
131 f'stderr={stderr!r}')
132
133 def check_repr(text):
134 try:
135 text.encode(encoding)
136 except UnicodeEncodeError:
137 self.assertGdbRepr(text, ascii(text))
138 else:
139 self.assertGdbRepr(text)
140
141 self.assertGdbRepr('')
142 self.assertGdbRepr('And now for something hopefully the same')
143 self.assertGdbRepr('string with embedded NUL here \0 and then some more text')
144
145 # Test printing a single character:
146 # U+2620 SKULL AND CROSSBONES
147 check_repr('\u2620')
148
149 # Test printing a Japanese unicode string
150 # (I believe this reads "mojibake", using 3 characters from the CJK
151 # Unified Ideographs area, followed by U+3051 HIRAGANA LETTER KE)
152 check_repr('\u6587\u5b57\u5316\u3051')
153
154 # Test a character outside the BMP:
155 # U+1D121 MUSICAL SYMBOL C CLEF
156 # This is:
157 # UTF-8: 0xF0 0x9D 0x84 0xA1
158 # UTF-16: 0xD834 0xDD21
159 check_repr(chr(0x1D121))
160
161 def test_tuples(self):
162 'Verify the pretty-printing of tuples'

Callers

nothing calls this directly

Calls 2

assertGdbReprMethod · 0.95
run_gdbFunction · 0.85

Tested by

no test coverage detected