示例#1
0
def test_get_surrounding_function_no_parent():
    frame = CallFrame.current()

    while frame.parent is not None:
        frame = frame.parent

    # Make sure this doesn't crash
    _ = frame.get_surrounding_function()
示例#2
0
def test_attrs():
    frame1 = inspect.currentframe()
    frame2 = CallFrame.from_frame(frame1)

    assert frame2.parent == frame1.f_back
    assert frame2.locals is frame1.f_locals
    assert frame2.globals is frame1.f_globals
    assert frame2.builtins is frame1.f_builtins
    assert frame2.code_object is frame1.f_code
示例#3
0
def test_toplevel_frame_has_no_parent():
    frame = inspect.currentframe()

    while frame.f_back is not None:
        frame = frame.f_back

    frame = CallFrame.from_frame(frame)

    assert frame.parent is None
示例#4
0
def test_file_name():
    frame = CallFrame.current()

    assert frame.file_name == __file__
示例#5
0
 class Class:
     frame = CallFrame.current()
示例#6
0
def test_scope_name():
    frame = CallFrame.current()

    assert frame.scope_name == 'test_scope_name'
示例#7
0
def test_resolve_global_name():
    frame = CallFrame.current()

    assert frame.resolve_name('pytest') is pytest
示例#8
0
def test_get():
    stack = CallStack.current()
    frame = CallFrame.current()

    assert stack[-1] == frame
示例#9
0
def test_from_frame():
    frame = CallFrame.current()
    stack = CallStack.from_frame(frame)

    assert stack[-1] == frame
示例#10
0
def test_inequality():
    frame = CallFrame.current()

    assert frame != 5
示例#11
0
 def func():
     return CallFrame.current()
示例#12
0
def test_equality(orig_frame):
    frame = CallFrame.from_frame(orig_frame)

    assert frame == orig_frame
示例#13
0
def test_resolve_nonexistent_name():
    frame = CallFrame.current()

    with pytest.raises(NameError):
        frame.resolve_name('firetruck')
示例#14
0
def test_resolve_builtin_name():
    frame = CallFrame.current()

    assert frame.resolve_name('int') is int
示例#15
0
def test_context():
    with CallFrame.current() as frame:
        _ = frame.parent

    with pytest.raises(Exception):
        _ = frame.parent
示例#16
0
def test_resolve_local_name():
    x = object()

    frame = CallFrame.current()

    assert frame.resolve_name('x') is x
示例#17
0
def test_get_current_frame():
    frame1 = inspect.currentframe()
    frame2 = CallFrame.current()

    assert frame1 == frame2
示例#18
0
def test_indexing():
    stack = CallStack.current()
    frame = CallFrame.current()

    assert frame == stack[-1]
示例#19
0
def test_parent_type():
    frame = CallFrame.current()

    assert isinstance(frame.parent, CallFrame)
示例#20
0
def test_contains():
    stack = CallStack.current()
    frame = CallFrame.current()

    assert frame in stack
示例#21
0
import pytest

import inspect
from introspection import CallFrame

GLOBAL_FRAME = CallFrame.current()


@pytest.mark.parametrize('orig_frame', [
    inspect.currentframe(),
    CallFrame(inspect.currentframe()),
])
def test_equality(orig_frame):
    frame = CallFrame.from_frame(orig_frame)

    assert frame == orig_frame


def test_inequality():
    frame = CallFrame.current()

    assert frame != 5


def test_get_current_frame():
    frame1 = inspect.currentframe()
    frame2 = CallFrame.current()

    assert frame1 == frame2