mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[3.11] bpo-43950: handle wide unicode characters in tracebacks (GH-28150) (#111373)
This commit is contained in:
parent
762aba72eb
commit
22cde39fbf
6 changed files with 189 additions and 15 deletions
|
@ -893,7 +893,62 @@ class TracebackErrorLocationCaretTests(unittest.TestCase):
|
|||
f" callable()",
|
||||
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 4}, in f",
|
||||
f" print(1, www(",
|
||||
f" ^^^^",
|
||||
f" ^^^^^^^",
|
||||
]
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_byte_offset_with_wide_characters_term_highlight(self):
|
||||
def f():
|
||||
说明说明 = 1
|
||||
şçöğıĤellö = 0 # not wide but still non-ascii
|
||||
return 说明说明 / şçöğıĤellö
|
||||
|
||||
actual = self.get_exception(f)
|
||||
expected = [
|
||||
f"Traceback (most recent call last):",
|
||||
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
|
||||
f" callable()",
|
||||
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 3}, in f",
|
||||
f" return 说明说明 / şçöğıĤellö",
|
||||
f" ~~~~~~~~~^~~~~~~~~~~~",
|
||||
]
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_byte_offset_with_emojis_term_highlight(self):
|
||||
def f():
|
||||
return "✨🐍" + func_说明说明("📗🚛",
|
||||
"📗🚛") + "🐍"
|
||||
|
||||
actual = self.get_exception(f)
|
||||
expected = [
|
||||
f"Traceback (most recent call last):",
|
||||
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
|
||||
f" callable()",
|
||||
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 1}, in f",
|
||||
f' return "✨🐍" + func_说明说明("📗🚛",',
|
||||
f" ^^^^^^^^^^^^^",
|
||||
]
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_byte_offset_wide_chars_subscript(self):
|
||||
def f():
|
||||
my_dct = {
|
||||
"✨🚛✨": {
|
||||
"说明": {
|
||||
"🐍🐍🐍": None
|
||||
}
|
||||
}
|
||||
}
|
||||
return my_dct["✨🚛✨"]["说明"]["🐍"]["说明"]["🐍🐍"]
|
||||
|
||||
actual = self.get_exception(f)
|
||||
expected = [
|
||||
f"Traceback (most recent call last):",
|
||||
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
|
||||
f" callable()",
|
||||
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 8}, in f",
|
||||
f' return my_dct["✨🚛✨"]["说明"]["🐍"]["说明"]["🐍🐍"]',
|
||||
f" ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^",
|
||||
]
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue