def test_frame_stack(): def to_code_names(frames): code_names = deque() for frame in reversed(frames): code_name = frame.f_code.co_name if code_name not in mock_code_names: break code_names.appendleft(code_name) return list(code_names) profiler = Profiler() frame = foo() frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['foo', 'bar', 'baz'] # top frame profiler = Profiler(top_frame=frame.f_back) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'baz'] # top code profiler = Profiler(top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'baz'] # both of top frame and top code profiler = Profiler(top_frame=frame.f_back, top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'baz']
def test_frame_stack(): def to_code_names(frames): code_names = deque() for frame in reversed(frames): code_name = frame.f_code.co_name if code_name not in mock_code_names: break code_names.appendleft(code_name) return list(code_names) profiler = Profiler() frame = foo() frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['foo', 'bar', 'baz'] # top frame profiler = Profiler(top_frame=frame.f_back) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'baz'] # top code profiler = Profiler(top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'baz'] # both of top frame and top code profiler = Profiler(top_frame=frame.f_back, top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'baz']
def test_frame_stack(): profiler = Profiler() frame = sys._getframe() frame_stack = profiler._frame_stack(frame) assert frame_stack[-1] is frame assert frame_stack[-2] is frame.f_back assert frame_stack[-3] is frame.f_back.f_back # top frame profiler = Profiler(top_frame=frame.f_back) frame_stack = profiler._frame_stack(frame) assert list(frame_stack) == [frame.f_back, frame] # top code profiler = Profiler(top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert list(frame_stack) == [frame.f_back, frame] # both of top frame and top code profiler = Profiler(top_frame=frame.f_back, top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert list(frame_stack) == [frame.f_back, frame]
def test_frame_stack(): def to_code_names(frames): return [f.f_code.co_name for f in frames] profiler = Profiler() frame = mock_stacked_frame(map(mock_code, ['foo', 'bar', 'baz'])) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['baz', 'bar', 'foo'] # top frame profiler = Profiler(top_frame=frame.f_back) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'foo'] # top code profiler = Profiler(top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'foo'] # both of top frame and top code profiler = Profiler(top_frame=frame.f_back, top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert to_code_names(frame_stack) == ['bar', 'foo']
def test_frame_stack(): profiler = Profiler() frame = sys._getframe() frame_stack = profiler._frame_stack(frame) assert frame_stack[-1] is frame assert frame_stack[-2] is frame.f_back assert frame_stack[-3] is frame.f_back.f_back # top frame profiler = Profiler(top_frame=frame.f_back) frame_stack = profiler._frame_stack(frame) assert list(frame_stack) == [frame.f_back, frame] # top code profiler = Profiler(top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert list(frame_stack) == [frame.f_back, frame] # both of top frame and top code profiler = Profiler(top_frame=frame.f_back, top_code=frame.f_back.f_code) frame_stack = profiler._frame_stack(frame) assert list(frame_stack) == [frame.f_back, frame]