summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_code.py
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-06-16 10:56:35 (GMT)
committerGitHub <noreply@github.com>2022-06-16 10:56:35 (GMT)
commitdf091e14d8c5b25b9094ebb86857e30adc8e5abb (patch)
tree099e40124823defc9d684955632e06ccafd0c924 /Lib/test/test_code.py
parent6e280326625eb5235131c0105cf72720419fcfda (diff)
downloadcpython-df091e14d8c5b25b9094ebb86857e30adc8e5abb.zip
cpython-df091e14d8c5b25b9094ebb86857e30adc8e5abb.tar.gz
cpython-df091e14d8c5b25b9094ebb86857e30adc8e5abb.tar.bz2
[3.11] GH-93662: Make sure that column offsets are correct in multi-line method calls. (GH-93673) (#93895)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Lib/test/test_code.py')
-rw-r--r--Lib/test/test_code.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 1bb138e..a6857dc 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -574,6 +574,15 @@ def positions_from_location_table(code):
for _ in range(length):
yield (line, end_line, col, end_col)
+def dedup(lst, prev=object()):
+ for item in lst:
+ if item != prev:
+ yield item
+ prev = item
+
+def lines_from_postions(positions):
+ return dedup(l for (l, _, _, _) in positions)
+
def misshappen():
"""
@@ -606,6 +615,13 @@ def misshappen():
) else p
+def bug93662():
+ example_report_generation_message= (
+ """
+ """
+ ).strip()
+ raise ValueError()
+
class CodeLocationTest(unittest.TestCase):
@@ -616,10 +632,23 @@ class CodeLocationTest(unittest.TestCase):
self.assertEqual(l1, l2)
self.assertEqual(len(pos1), len(pos2))
-
def test_positions(self):
self.check_positions(parse_location_table)
self.check_positions(misshappen)
+ self.check_positions(bug93662)
+
+ def check_lines(self, func):
+ co = func.__code__
+ lines1 = list(dedup(l for (_, _, l) in co.co_lines()))
+ lines2 = list(lines_from_postions(positions_from_location_table(co)))
+ for l1, l2 in zip(lines1, lines2):
+ self.assertEqual(l1, l2)
+ self.assertEqual(len(lines1), len(lines2))
+
+ def test_lines(self):
+ self.check_lines(parse_location_table)
+ self.check_lines(misshappen)
+ self.check_lines(bug93662)
if check_impl_detail(cpython=True) and ctypes is not None: