summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-10-19 09:48:50 (GMT)
committerGitHub <noreply@github.com>2022-10-19 09:48:50 (GMT)
commit9be05df3997de3fe9d34525871baa375cbccd7fc (patch)
tree70a9d1b68aade5d465f3e9fa9310692e5677d1b4 /Lib/test
parente4ec8de6fa6f0a07e64f6a3e3f894926b4b0652d (diff)
downloadcpython-9be05df3997de3fe9d34525871baa375cbccd7fc.zip
cpython-9be05df3997de3fe9d34525871baa375cbccd7fc.tar.gz
cpython-9be05df3997de3fe9d34525871baa375cbccd7fc.tar.bz2
gh-98398: Fix source locations for 'assert' bytecode (GH-98405)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_compile.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index a5434d6..85f05a8 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -1215,7 +1215,6 @@ if (a or
d > 0)):
x = 42
"""
-
compiled_code, _ = self.check_positions_against_ast(snippet)
# jump if a is true:
self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_TRUE',
@@ -1233,6 +1232,23 @@ if (a or
self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_TRUE',
line=4, end_line=4, column=8, end_column=13, occurrence=2)
+ def test_multiline_assert(self):
+ snippet = """\
+assert (a > 0 and
+ bb > 0 and
+ ccc == 4), "error msg"
+"""
+ compiled_code, _ = self.check_positions_against_ast(snippet)
+ self.assertOpcodeSourcePositionIs(compiled_code, 'LOAD_ASSERTION_ERROR',
+ line=1, end_line=3, column=0, end_column=30, occurrence=1)
+ # The "error msg":
+ self.assertOpcodeSourcePositionIs(compiled_code, 'LOAD_CONST',
+ line=3, end_line=3, column=19, end_column=30, occurrence=4)
+ self.assertOpcodeSourcePositionIs(compiled_code, 'CALL',
+ line=1, end_line=3, column=0, end_column=30, occurrence=1)
+ self.assertOpcodeSourcePositionIs(compiled_code, 'RAISE_VARARGS',
+ line=1, end_line=3, column=0, end_column=30, occurrence=1)
+
def test_very_long_line_end_offset(self):
# Make sure we get the correct column offset for offsets
# too large to store in a byte.