summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_monitoring.py
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-08-13 09:25:44 (GMT)
committerGitHub <noreply@github.com>2024-08-13 09:25:44 (GMT)
commitfe23f8ed970425828de20fb48750fa89da914886 (patch)
tree4bcd11c9d4f579a73345b0212d126e764c5ba662 /Lib/test/test_monitoring.py
parent0e207f3e7adc6a0fdbe1482ce01163ff04d5ddcb (diff)
downloadcpython-fe23f8ed970425828de20fb48750fa89da914886.zip
cpython-fe23f8ed970425828de20fb48750fa89da914886.tar.gz
cpython-fe23f8ed970425828de20fb48750fa89da914886.tar.bz2
GH-122821: Simplify compilation of while statements to ensure consistency of offsets for sys.monitoring (GH-122934)
Diffstat (limited to 'Lib/test/test_monitoring.py')
-rw-r--r--Lib/test/test_monitoring.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_monitoring.py b/Lib/test/test_monitoring.py
index 8ef8c37..351f106 100644
--- a/Lib/test/test_monitoring.py
+++ b/Lib/test/test_monitoring.py
@@ -1446,9 +1446,27 @@ class BranchRecorder(JumpRecorder):
+class JumpOffsetRecorder:
+
+ event_type = E.JUMP
+ name = "jump"
+
+ def __init__(self, events, offsets=False):
+ self.events = events
+
+ def __call__(self, code, from_, to):
+ self.events.append((self.name, code.co_name, from_, to))
+
+class BranchOffsetRecorder(JumpOffsetRecorder):
+
+ event_type = E.BRANCH
+ name = "branch"
+
+
JUMP_AND_BRANCH_RECORDERS = JumpRecorder, BranchRecorder
JUMP_BRANCH_AND_LINE_RECORDERS = JumpRecorder, BranchRecorder, LineRecorder
FLOW_AND_LINE_RECORDERS = JumpRecorder, BranchRecorder, LineRecorder, ExceptionRecorder, ReturnRecorder
+BRANCH_OFFSET_RECORDERS = BranchOffsetRecorder,
class TestBranchAndJumpEvents(CheckEvents):
maxDiff = None
@@ -1538,6 +1556,24 @@ class TestBranchAndJumpEvents(CheckEvents):
('return', 'func', None),
('line', 'get_events', 11)])
+ def test_while_offset_consistency(self):
+
+ def foo(n=0):
+ while n<4:
+ pass
+ n += 1
+ return None
+
+ in_loop = ('branch', 'foo', 10, 14)
+ exit_loop = ('branch', 'foo', 10, 30)
+ self.check_events(foo, recorders = BRANCH_OFFSET_RECORDERS, expected = [
+ in_loop,
+ in_loop,
+ in_loop,
+ in_loop,
+ exit_loop])
+
+
class TestLoadSuperAttr(CheckEvents):
RECORDERS = CallRecorder, LineRecorder, CRaiseRecorder, CReturnRecorder