Esempio n. 1
0
def test_inject_defaults():
    @S.inject
    def f(x, a=V.a):
        assert x == a

    with S.patch_local({V.a: 1}):
        f(1)

    with S.patch_local({V.a: 2}):
        f(2)

    del f
    stats.check(DECL=3, CELL=2, SCOPE=2)
Esempio n. 2
0
def test_inject_kwdefaults_with_namespace():
    @S.inject
    def f(x, a2=V.a - 0, a=V):
        assert x == a == a2

    with S.patch_local({V.a: 1}):
        f(1)

    with S.patch_local({V.a: 2}):
        f(2)

    del f
    stats.check(DECL=4, CELL=2, SCOPE=2, NAMESPACE=0)
Esempio n. 3
0
def test_inject_mixed_defaults_with_namespace():
    @S.inject
    def f(x, a=V.NS[...], *, a2=V.NS.a - 0):
        assert x == a == a2

    with S.patch_local({V.NS.a: 1}):
        f(1)

    with S.patch_local({V.NS.a: 2}):
        f(2)

    del f
    stats.check(DECL=5, CELL=2, SCOPE=2, NAMESPACE=1)
Esempio n. 4
0
def test_value_refcnt():
    value = object()
    global A
    with S.isolate():
        S.assign(A, value)
        with S.patch():
            S.assign(A, value)
            with S.shield():
                S.assign(A, value)
                with S.patch_local():
                    S.assign(A, value)
                    with S.shield_local():
                        S.assign(A, value)
                        with S.isolate_local():
                            S.assign(A, value)
    A = None
    assert stats.SCOPE_ALLOCATED == stats.SCOPE_FREED == 6
    assert stats.CELL_ALLOCATED == 4
    assert stats.CELL_FREED == 4
    assert stats.DECL_FREED == 1

    assert sys.getrefcount(value) == 2