def test_reify_recursion_limit(): import platform a_lv = var() b, _ = gen_long_chain(a_lv, 10) res = reify(b, {a_lv: "a"}) assert res == gen_long_chain("a", 10)[0] r_limit = sys.getrecursionlimit() try: sys.setrecursionlimit(100) b, _ = gen_long_chain(a_lv, 200) res = reify(b, {a_lv: "a"}) exp_res, _ = gen_long_chain("a", 200) if platform.python_implementation().lower() != "pypy": # CPython has stack limit issues when comparing nested lists, but # PyPy doesn't. with pytest.raises(RecursionError): assert res == exp_res sys.setrecursionlimit(300) assert res == exp_res finally: sys.setrecursionlimit(r_limit)
def test_unify_chain_stream_large(size, benchmark): a_lv = var() form, lvars = gen_long_chain(a_lv, size, use_lvars=True) term, _ = gen_long_chain("a", size) res = benchmark(unify, form, term, {}) assert res[a_lv] == "a"
def test_reify_chain_stack(size, benchmark): a_lv = var() form = gen_long_chain(a_lv, size) term = gen_long_chain("a", size) res = benchmark(reify_stack, form, {a_lv: "a"}) assert res == term
def test_unify_chain_stack(size, benchmark): a_lv = var() form = gen_long_chain(a_lv, size) term = gen_long_chain("a", size) res = benchmark(unify_stack, form, term, {}) assert res[a_lv] == "a"
def test_reify_chain_stack(size, benchmark): a_lv = var() form, lvars = gen_long_chain(a_lv, size, use_lvars=True) term, _ = gen_long_chain("a", size) lvars.update({a_lv: "a"}) res = benchmark(reify_stack, form, lvars) assert res == term
def test_unify_recursion_limit(): a_lv = var() b, _ = gen_long_chain("a") b_var, _ = gen_long_chain(a_lv) s = unify(b, b_var, {}) assert s[a_lv] == "a"
def test_reify_chain_stream_large(size, benchmark): a_lv = var() form, lvars = gen_long_chain(a_lv, size, use_lvars=True) term, _ = gen_long_chain("a", size) lvars.update({a_lv: "a"}) res = benchmark(reify, form, lvars) if size < sys.getrecursionlimit(): assert res == term else: with pytest.raises(RecursionError): assert res == term