def test_getstatement_empty_fullsource() -> None: def func() -> FrameType: return sys._getframe(0) f = Frame(func()) with mock.patch.object(f.code.__class__, "fullsource", None): assert f.statement == Source("")
def test_frame_getsourcelineno_myself() -> None: def func() -> FrameType: return sys._getframe(0) f = Frame(func()) source, lineno = f.code.fullsource, f.lineno assert source is not None assert source[lineno].startswith(" return sys._getframe(0)")
def __init__(self, *args): frame = sys._getframe(1) self.source = Frame(frame).statement
def test_frame_getargs() -> None: def f1(x) -> FrameType: return sys._getframe(0) fr1 = Frame(f1("a")) assert fr1.getargs(var=True) == [("x", "a")] def f2(x, *y) -> FrameType: return sys._getframe(0) fr2 = Frame(f2("a", "b", "c")) assert fr2.getargs(var=True) == [("x", "a"), ("y", ("b", "c"))] def f3(x, **z) -> FrameType: return sys._getframe(0) fr3 = Frame(f3("a", b="c")) assert fr3.getargs(var=True) == [("x", "a"), ("z", {"b": "c"})] def f4(x, *y, **z) -> FrameType: return sys._getframe(0) fr4 = Frame(f4("a", "b", c="d")) assert fr4.getargs(var=True) == [("x", "a"), ("y", ("b", )), ("z", { "c": "d" })]