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")
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")
def test_attribute(tracer, rpc_stub): class A: pass a1 = A() a2 = A() a2.y = 1 tracer.start() a1.x = a2 # STORE_ATTR a1.x.y = 2 # LOAD_ATTR, STORE_ATTR del a1.x # DELETE_ATTR tracer.stop() assert tracer.events == [ InitialValue( lineno=14, target=Symbol("a2"), value='{"y": 1}', repr="<test_attribute.test_attribute.<locals>.A object>", ), InitialValue( lineno=14, target=Symbol("a1"), value="{}", repr="<test_attribute.test_attribute.<locals>.A object>", ), Mutation( lineno=14, target=Symbol("a1"), sources={Symbol("a2"), Symbol("a1")}, value='{"x": {"y": 1}}', repr="<test_attribute.test_attribute.<locals>.A object>", ), Mutation( lineno=15, target=Symbol("a1"), sources={Symbol("a1")}, value='{"x": {"y": 2}}', repr="<test_attribute.test_attribute.<locals>.A object>", ), Mutation( lineno=16, target=Symbol("a1"), sources={Symbol("a1")}, value="{}", repr="<test_attribute.test_attribute.<locals>.A object>", ), ] from utils import assert_GetFrame assert_GetFrame(rpc_stub, "test_attribute")
def test_attribute(tracer, mocked_responses): class A: pass a1 = A() a2 = A() a2.y = 1 tracer.start() a1.x = a2 # STORE_ATTR a1.x.y = 2 # LOAD_ATTR, STORE_ATTR del a1.x # DELETE_ATTR tracer.stop() assert tracer.events == [ InitialValue( lineno=-1, target=Symbol("a2"), value='{"y":1}', repr="<test_attribute.test_attribute.<locals>.A object>", ), InitialValue( lineno=-1, target=Symbol("a1"), value="{}", repr="<test_attribute.test_attribute.<locals>.A object>", ), Mutation( lineno=14, target=Symbol("a1"), sources={Symbol("a2"), Symbol("a1")}, value='{"x":{"y":1}}', repr="<test_attribute.test_attribute.<locals>.A object>", ), Mutation( lineno=15, target=Symbol("a1"), sources={Symbol("a1")}, value='{"x":{"y":2}}', repr="<test_attribute.test_attribute.<locals>.A object>", ), Mutation( lineno=16, target=Symbol("a1"), sources={Symbol("a1")}, value="{}", repr="<test_attribute.test_attribute.<locals>.A object>", ), ]
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, ), ]
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")
def test_container(tracer, test_server): a = b = 1 c = 2 e = 0 tracer.start() d = [a, b] # BUILD_LIST d = (a, b) # BUILD_TUPLE d = {a, b} # BUILD_SET d = {a: b} # BUILD_MAP d = {1: a, 2: b} # BUILD_CONST_KEY_MAP d[a] = c # STORE_SUBSCR del d[a] # DELETE_SUBSCR d = [a, b, c][e:c] # BUILD_SLICE,[1,1,2][0:2] d = [b, b, c][e:c:a] # BUILD_SLICE,[1,1,2][0:2:1] os.environ["foo"] = "bar" # STORE_SUBSCR without emitting any event. tracer.stop() assert tracer.events == [ InitialValue(target=Symbol("a"), value="1", lineno=13), InitialValue(target=Symbol("b"), value="1", lineno=13), Binding( target=Symbol("d"), value="[1,1]", sources={Symbol("a"), Symbol("b")}, lineno=13, ), Binding( target=Symbol("d"), value="[1,1]", sources={Symbol("a"), Symbol("b")}, lineno=14, ), Binding( target=Symbol("d"), value="[1]", sources={Symbol("a"), Symbol("b")}, lineno=15, ), Binding( target=Symbol("d"), value='{"1":1}', sources={Symbol("a"), Symbol("b")}, lineno=16, ), Binding( target=Symbol("d"), value='{"1":1,"2":1}', sources={Symbol("a"), Symbol("b")}, lineno=17, ), InitialValue(target=Symbol("c"), value="2", lineno=18), Mutation( target=Symbol("d"), value='{"1":2,"2":1}', sources={Symbol("d"), Symbol("a"), Symbol("c")}, lineno=18, ), Mutation( target=Symbol("d"), value='{"2":1}', sources={Symbol("d"), Symbol("a")}, lineno=19, ), InitialValue(target=Symbol("e"), value="0", lineno=20), Binding( target=Symbol("d"), value="[1,1]", sources={Symbol("a"), Symbol("b"), Symbol("c"), Symbol("e")}, lineno=20, ), Binding( target=Symbol("d"), value="[1,1]", sources={Symbol("a"), Symbol("b"), Symbol("c"), Symbol("e")}, lineno=21, ), ] test_server.assert_frame_sent("test_container")
def test_container(tracer, rpc_stub): a = b = 1 c = 2 e = 0 tracer.start() d = [a, b] # BUILD_LIST d = (a, b) # BUILD_TUPLE d = {a, b} # BUILD_SET d = {a: b} # BUILD_MAP d = {1: a, 2: b} # BUILD_CONST_KEY_MAP d[a] = c # STORE_SUBSCR del d[a] # DELETE_SUBSCR d = [a, b, c][e:c] # BUILD_SLICE, [1, 1, 2][0:2] d = [b, b, c][e:c:a] # BUILD_SLICE, [1, 1, 2][0:2:1] tracer.stop() assert tracer.events == [ InitialValue(target=Symbol("a"), value=1, lineno=12), InitialValue(target=Symbol("b"), value=1, lineno=12), Binding( target=Symbol("d"), value=[1, 1], sources={Symbol("a"), Symbol("b")}, lineno=12, ), Binding( target=Symbol("d"), value=(1, 1), sources={Symbol("a"), Symbol("b")}, lineno=13, ), Binding( target=Symbol("d"), value={1}, sources={Symbol("a"), Symbol("b")}, lineno=14 ), Binding( target=Symbol("d"), value={1: 1}, sources={Symbol("a"), Symbol("b")}, lineno=15, ), Binding( target=Symbol("d"), value={1: 1, 2: 1}, sources={Symbol("a"), Symbol("b")}, lineno=16, ), InitialValue(target=Symbol("c"), value=2, lineno=17), Mutation( target=Symbol("d"), value={1: 2, 2: 1}, sources={Symbol("d"), Symbol("a"), Symbol("c")}, lineno=17, ), Mutation( target=Symbol("d"), value={2: 1}, sources={Symbol("d"), Symbol("a")}, lineno=18, ), InitialValue(target=Symbol("e"), value=0, lineno=19), Binding( target=Symbol("d"), value=[1, 1], sources={Symbol("a"), Symbol("b"), Symbol("c"), Symbol("e")}, lineno=19, ), Binding( target=Symbol("d"), value=[1, 1], sources={Symbol("a"), Symbol("b"), Symbol("c"), Symbol("e")}, lineno=20, ), ] assert_GetFrame(rpc_stub, "test_container")