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)
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)
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
def test_call(): var = S._varfor(V.a) with S.isolate(): S.assign(var, _Dummy) assert var(0) == _Dummy(0)