Ejemplo n.º 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()
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 4
0
def test_file_name():
    frame = CallFrame.current()

    assert frame.file_name == __file__
Ejemplo n.º 5
0
 class Class:
     frame = CallFrame.current()
Ejemplo n.º 6
0
def test_scope_name():
    frame = CallFrame.current()

    assert frame.scope_name == 'test_scope_name'
Ejemplo n.º 7
0
def test_resolve_global_name():
    frame = CallFrame.current()

    assert frame.resolve_name('pytest') is pytest
Ejemplo n.º 8
0
def test_get():
    stack = CallStack.current()
    frame = CallFrame.current()

    assert stack[-1] == frame
Ejemplo n.º 9
0
def test_from_frame():
    frame = CallFrame.current()
    stack = CallStack.from_frame(frame)

    assert stack[-1] == frame
Ejemplo n.º 10
0
def test_inequality():
    frame = CallFrame.current()

    assert frame != 5
Ejemplo n.º 11
0
 def func():
     return CallFrame.current()
Ejemplo n.º 12
0
def test_equality(orig_frame):
    frame = CallFrame.from_frame(orig_frame)

    assert frame == orig_frame
Ejemplo n.º 13
0
def test_resolve_nonexistent_name():
    frame = CallFrame.current()

    with pytest.raises(NameError):
        frame.resolve_name('firetruck')
Ejemplo n.º 14
0
def test_resolve_builtin_name():
    frame = CallFrame.current()

    assert frame.resolve_name('int') is int
Ejemplo n.º 15
0
def test_context():
    with CallFrame.current() as frame:
        _ = frame.parent

    with pytest.raises(Exception):
        _ = frame.parent
Ejemplo n.º 16
0
def test_resolve_local_name():
    x = object()

    frame = CallFrame.current()

    assert frame.resolve_name('x') is x
Ejemplo n.º 17
0
def test_get_current_frame():
    frame1 = inspect.currentframe()
    frame2 = CallFrame.current()

    assert frame1 == frame2
Ejemplo n.º 18
0
def test_indexing():
    stack = CallStack.current()
    frame = CallFrame.current()

    assert frame == stack[-1]
Ejemplo n.º 19
0
def test_parent_type():
    frame = CallFrame.current()

    assert isinstance(frame.parent, CallFrame)
Ejemplo n.º 20
0
def test_contains():
    stack = CallStack.current()
    frame = CallFrame.current()

    assert frame in stack
Ejemplo n.º 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