summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_code.py
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-10-05 00:30:03 (GMT)
committerGitHub <noreply@github.com>2022-10-05 00:30:03 (GMT)
commit0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85 (patch)
treeba515469a236a046b09329fbcd49c33eb65c267d /Lib/test/test_code.py
parentc3648f4e4a12ec6efe65684facfcd08996e550ca (diff)
downloadcpython-0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85.zip
cpython-0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85.tar.gz
cpython-0ff8fd65838f9f9ed90d7a055d26a2ce9fc0ce85.tar.bz2
GH-97779: Ensure that *all* frame objects are backed by "complete" frames (GH-97845)
Diffstat (limited to 'Lib/test/test_code.py')
-rw-r--r--Lib/test/test_code.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 2fdfdd0..4e4d823 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
@@ -682,6 +683,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