2025-11-18 15:14:16 +00:00
|
|
|
"""Mock classes for sampling profiler tests."""
|
|
|
|
|
|
2025-12-03 03:43:47 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
|
|
# Matches the C structseq LocationInfo from _remote_debugging
|
|
|
|
|
LocationInfo = namedtuple('LocationInfo', ['lineno', 'end_lineno', 'col_offset', 'end_col_offset'])
|
|
|
|
|
|
2025-11-18 15:14:16 +00:00
|
|
|
|
|
|
|
|
class MockFrameInfo:
|
2025-12-03 03:43:47 +00:00
|
|
|
"""Mock FrameInfo for testing.
|
|
|
|
|
|
|
|
|
|
Frame format: (filename, location, funcname, opcode) where:
|
|
|
|
|
- location is a tuple (lineno, end_lineno, col_offset, end_col_offset)
|
|
|
|
|
- opcode is an int or None
|
|
|
|
|
"""
|
2025-11-18 15:14:16 +00:00
|
|
|
|
2025-12-03 03:43:47 +00:00
|
|
|
def __init__(self, filename, lineno, funcname, opcode=None):
|
2025-11-18 15:14:16 +00:00
|
|
|
self.filename = filename
|
|
|
|
|
self.funcname = funcname
|
2025-12-03 03:43:47 +00:00
|
|
|
self.opcode = opcode
|
|
|
|
|
self.location = LocationInfo(lineno, lineno, -1, -1)
|
|
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
|
return iter((self.filename, self.location, self.funcname, self.opcode))
|
|
|
|
|
|
|
|
|
|
def __getitem__(self, index):
|
|
|
|
|
return (self.filename, self.location, self.funcname, self.opcode)[index]
|
|
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
|
return 4
|
2025-11-18 15:14:16 +00:00
|
|
|
|
|
|
|
|
def __repr__(self):
|
2025-12-03 03:43:47 +00:00
|
|
|
return f"MockFrameInfo('{self.filename}', {self.location}, '{self.funcname}', {self.opcode})"
|
2025-11-18 15:14:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MockThreadInfo:
|
|
|
|
|
"""Mock ThreadInfo for testing since the real one isn't accessible."""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self, thread_id, frame_info, status=0
|
|
|
|
|
): # Default to THREAD_STATE_RUNNING (0)
|
|
|
|
|
self.thread_id = thread_id
|
|
|
|
|
self.frame_info = frame_info
|
|
|
|
|
self.status = status
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return f"MockThreadInfo(thread_id={self.thread_id}, frame_info={self.frame_info}, status={self.status})"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MockInterpreterInfo:
|
|
|
|
|
"""Mock InterpreterInfo for testing since the real one isn't accessible."""
|
|
|
|
|
|
|
|
|
|
def __init__(self, interpreter_id, threads):
|
|
|
|
|
self.interpreter_id = interpreter_id
|
|
|
|
|
self.threads = threads
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return f"MockInterpreterInfo(interpreter_id={self.interpreter_id}, threads={self.threads})"
|