Esempio n. 1
0
def test_binary_ops(op, enable_preinit):
    a = _Dummy(1)
    b = _Dummy(2)
    vara = S._varfor(V.a)
    varb = S._varfor(V.b)
    with _preinit(enable_preinit, vara, varb):
        with S.isolate():
            S.assign(vara, a)
            S.assign(varb, b)
            assert op(a, b) == op(vara, varb)
            assert op(a, b) == op(a, varb)
            assert op(a, b) == op(vara, b)
Esempio n. 2
0
def test_tenary_ops(op, enable_preinit):
    a = _Dummy(1)
    b = _Dummy(2)
    c = _Dummy(3)
    vara = S._varfor(V.a)
    varb = S._varfor(V.b)
    varc = S._varfor(V.c)
    with _preinit(enable_preinit, vara, varb, varc):
        with S.isolate():
            S.assign(vara, a)
            S.assign(varb, b)
            S.assign(varc, c)
            assert op(a, b, c) == op(vara, varb, varc)
            assert op(a, b, c) == op(vara, varb, c)
            assert op(a, b, c) == op(vara, b, varc)
            assert op(a, b, c) == op(vara, b, c)
Esempio n. 3
0
def test_mro_entries():
    var = S._varfor(V.a)
    with S.isolate():
        S.assign(var, _Dummy(0))

        class _SubDummy(var):
            ...

        assert _SubDummy.__bases__ == (int, _Dummy)
Esempio n. 4
0
def test_unary_ops(op, enable_preinit):
    if isinstance(op, tuple):
        op, default = op
    else:
        default = 1
    a = _Dummy(default)
    vara = S._varfor(V.a)

    with _preinit(enable_preinit, vara):
        with S.isolate():
            S.assign(vara, a)
            assert op(a) == op(vara)
Esempio n. 5
0
def test_contextmanager():
    lst = []
    obj = _Dummy(lst)

    var = S._varfor(V.a)
    with S.isolate():
        S.assign(var, obj)
        with var:
            assert lst == ["enter"]
        assert lst == ["enter", None, None, None]
        del lst[:]
        with var:
            raise RuntimeError
        assert lst[1] is RuntimeError
Esempio n. 6
0
def test_inplace_binary_ops_mutable(op, enable_preinit):
    a = _Dummy(1)
    b = _Dummy(2)
    a.immutable = False
    vara = S._varfor(V.a)
    varb = S._varfor(V.b)
    with _preinit(enable_preinit, vara, varb):
        with S.isolate():
            S.assign(vara, _Dummy(1))
            vara.immutable = False
            S.assign(varb, _Dummy(2))
            assert op(a, b) == op(vara, varb) is vara
            assert vara != _Dummy(1)
            assert varb == _Dummy(2)

    assert a != _Dummy(1)
    assert b == _Dummy(2)
Esempio n. 7
0
def test_call():
    var = S._varfor(V.a)
    with S.isolate():
        S.assign(var, _Dummy)
        assert var(0) == _Dummy(0)