示例#1
0
def test_miscellaneous(tracer, test_server):
    a = "a"
    b = "b"
    c = "c"
    d = "d"
    e = [1, 2, 3]

    tracer.start()

    x = f"{a} {b:4} {c!r} {d!r:4}"  # FORMAT_VALUE, BUILD_STRING
    x = a == b == c  # ROT_THREE, _COMPARE_OP
    e[0] += e.pop()  # DUP_TOP_TWO
    del e  # DELETE_FAST
    global g
    x = g
    g = 1  # STORE_GLOBAL
    del g  # DELETE_GLOBAL

    tracer.stop()

    assert tracer.events == [
        InitialValue(target=Symbol("a"), value='"a"', lineno=15),
        InitialValue(target=Symbol("b"), value='"b"', lineno=15),
        InitialValue(target=Symbol("c"), value='"c"', lineno=15),
        InitialValue(target=Symbol("d"), value='"d"', lineno=15),
        Binding(
            target=Symbol("x"),
            value="\"a b    'c' 'd' \"",
            sources={Symbol("a"),
                     Symbol("b"),
                     Symbol("d"),
                     Symbol("c")},
            lineno=15,
        ),
        Binding(
            target=Symbol("x"),
            value="false",
            sources={Symbol("a"), Symbol("b")},
            lineno=16,
        ),
        InitialValue(target=Symbol("e"), value="[1, 2, 3]", lineno=17),
        Mutation(target=Symbol("e"),
                 value="[1, 2]",
                 sources={Symbol("e")},
                 lineno=17),
        Mutation(target=Symbol("e"),
                 value="[4, 2]",
                 sources={Symbol("e")},
                 lineno=17),
        Deletion(target=Symbol("e"), lineno=18),
        InitialValue(target=Symbol("g"), value="0", lineno=20),
        Binding(target=Symbol("x"),
                value="0",
                sources={Symbol("g")},
                lineno=20),
        Binding(target=Symbol("g"), value="1", lineno=21),
        Deletion(target=Symbol("g"), lineno=22),
    ]

    test_server.assert_frame_sent("test_miscellaneous")
示例#2
0
def test_miscellaneous(tracer, rpc_stub):
    a = "a"
    b = "b"
    c = "c"
    d = "d"
    e = [1, 2, 3]

    tracer.start()

    x = f"{a} {b:4} {c!r} {d!r:4}"  # FORMAT_VALUE, BUILD_STRING
    x = a == b == c  # ROT_THREE, _COMPARE_OP
    e[0] += e.pop()  # DUP_TOP_TWO
    del e  # DELETE_FAST
    global g
    x = g
    g = 1  # STORE_GLOBAL
    del g  # DELETE_GLOBAL

    tracer.stop()

    assert tracer.events == [
        InitialValue(target=Symbol("a"), value="a", lineno=16),
        InitialValue(target=Symbol("b"), value="b", lineno=16),
        InitialValue(target=Symbol("c"), value="c", lineno=16),
        InitialValue(target=Symbol("d"), value="d", lineno=16),
        Binding(
            target=Symbol("x"),
            value="a b    'c' 'd' ",
            sources={Symbol("a"),
                     Symbol("b"),
                     Symbol("d"),
                     Symbol("c")},
            lineno=16,
        ),
        Binding(
            target=Symbol("x"),
            value=False,
            sources={Symbol("a"), Symbol("b")},
            lineno=17,
        ),
        InitialValue(target=Symbol("e"), value=[1, 2, 3], lineno=18),
        Mutation(target=Symbol("e"),
                 value=[1, 2],
                 sources={Symbol("e")},
                 lineno=18),
        Mutation(target=Symbol("e"),
                 value=[4, 2],
                 sources={Symbol("e")},
                 lineno=18),
        Deletion(target=Symbol("e"), lineno=19),
        InitialValue(target=Symbol("g"), value=0, lineno=21),
        Binding(target=Symbol("x"), value=0, sources={Symbol("g")}, lineno=21),
        Binding(target=Symbol("g"), value=1, lineno=22),
        Deletion(target=Symbol("g"), lineno=23),
    ]

    assert_GetFrame(rpc_stub, "test_miscellaneous")
示例#3
0
def test_module():
    assert tracer.events == [
        InitialValue(target=Symbol("x"), value="1", lineno=-1),
        Deletion(target=Symbol("x"), lineno=8),
        InitialValue(target=Symbol("__annotations__"), value="{}", lineno=-1),
        Mutation(
            target=Symbol("__annotations__"),
            value='{"y":{"py/type":"builtins.int"}}',
            sources={Symbol("__annotations__")
                     },  # `int` is a built-in so is excluded from sources.
            lineno=9,
        ),
    ]
示例#4
0
def test_module(rpc_stub):
    assert tracer.events == [
        InitialValue(target=Symbol("x"), value=1, lineno=10),
        Deletion(target=Symbol("x"), lineno=10),
        InitialValue(target=Symbol("__annotations__"), value={}, lineno=11),
        Mutation(
            target=Symbol("__annotations__"),
            value={"y": int},
            sources={Symbol("__annotations__")
                     },  # `int` is a built-in so is excluded from sources.
            lineno=11,
        ),
    ]

    assert_GetFrame(rpc_stub, "test_outside_func")
示例#5
0
def test_deref(tracer, mocked_responses):

    a = 1

    def test_deref_func():
        tracer.start()
        nonlocal a
        print(a)  # LOAD_DEREF
        a = 2  # STORE_DEREF
        del a  # DELETE_DEREF
        tracer.stop()

    test_deref_func()

    assert tracer.events == [
        InitialValue(lineno=-1, target=Symbol("a"), value="1"),
        Binding(lineno=12, target=Symbol("a"), value="2", sources=set()),
        Deletion(lineno=13, target=Symbol("a")),
    ]
示例#6
0
def test_deref(tracer, rpc_stub):

    a = 1

    def test_deref_func():
        tracer.start()
        nonlocal a
        print(a)  # LOAD_DEREF
        a = 2  # STORE_DEREF
        del a  # DELETE_DEREF
        tracer.stop()

    test_deref_func()

    assert tracer.events == [
        InitialValue(lineno=12, target=Symbol("a"), value="1"),
        Binding(lineno=13, target=Symbol("a"), value="2", sources=set()),
        Deletion(lineno=14, target=Symbol("a")),
    ]

    assert_GetFrame(rpc_stub, "test_deref_func")