diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-05 05:46:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 05:46:34 (GMT) |
commit | 015b49ac05eddcb7f653ed2c80daba24ff396fd9 (patch) | |
tree | 7930e4c30215dca26464997ef4d7877c603967d5 /Lib/test/test_code.py | |
parent | 8c517d88fb5ac6f1145128804fe10d5ef9d12b07 (diff) | |
download | cpython-015b49ac05eddcb7f653ed2c80daba24ff396fd9.zip cpython-015b49ac05eddcb7f653ed2c80daba24ff396fd9.tar.gz cpython-015b49ac05eddcb7f653ed2c80daba24ff396fd9.tar.bz2 |
[3.11] GH-97779: Ensure that *all* frame objects are backed by "complete" frames (GH-97886)
(cherry picked from commit 0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85)
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
Diffstat (limited to 'Lib/test/test_code.py')
-rw-r--r-- | Lib/test/test_code.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index 2386cf6..d3e2012 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -132,6 +132,7 @@ import doctest import unittest import textwrap import weakref +import dis try: import ctypes @@ -671,6 +672,38 @@ class CodeLocationTest(unittest.TestCase): self.check_lines(misshappen) self.check_lines(bug93662) + @cpython_only + def test_code_new_empty(self): + # If this test fails, it means that the construction of PyCode_NewEmpty + # needs to be modified! Please update this test *and* PyCode_NewEmpty, + # so that they both stay in sync. + def f(): + pass + PY_CODE_LOCATION_INFO_NO_COLUMNS = 13 + f.__code__ = f.__code__.replace( + co_firstlineno=42, + co_code=bytes( + [ + dis.opmap["RESUME"], 0, + dis.opmap["LOAD_ASSERTION_ERROR"], 0, + dis.opmap["RAISE_VARARGS"], 1, + ] + ), + co_linetable=bytes( + [ + (1 << 7) + | (PY_CODE_LOCATION_INFO_NO_COLUMNS << 3) + | (3 - 1), + 0, + ] + ), + ) + self.assertRaises(AssertionError, f) + self.assertEqual( + list(f.__code__.co_positions()), + 3 * [(42, 42, None, None)], + ) + if check_impl_detail(cpython=True) and ctypes is not None: py = ctypes.pythonapi |