def test_unify_complex(): assert unify((1, {2: 3}), (1, {2: 3}), {}) == {} assert unify((1, {2: 3}), (1, {2: 4}), {}) == False assert unify((1, {2: var(5)}), (1, {2: 4}), {}) == {var(5): 4} assert unify({1: (2, 3)}, {1: (2, var(5))}, {}) == {var(5): 3} assert unify({1: [2, 3]}, {1: [2, var(5)]}, {}) == {var(5): 3}
def test_unify_slice(): x = var('x') y = var('y') assert unify_slice(slice(1), slice(1), {}) == {} assert unify(slice(1, 2, 3), x, {}) == {x: slice(1, 2, 3)} assert unify_slice(slice(1, 2, None), slice(x, y), {}) == {x: 1, y: 2}
def test_unify_seq_registry(): seq_registry.append((Foo, lambda x: (type(x), x.a, x.b))) x = var('x') y = var('y') f, g = Foo(1, 2), Foo(x, y) assert unify(f, g, {}) == {x: 1, y: 2} seq_registry.pop()
def test_unify_isinstance_list(): class Foo2(Foo): pass x = var('x') y = var('y') f, g = Foo2(1, 2), Foo2(x, y) unify_isinstance_list.append(((Foo, Foo), unify_object)) reify_isinstance_list.append((Foo, reify_object)) assert unify(f, g, {}) assert reify(g, {x: 1, y: 2}) == f unify_isinstance_list.pop() reify_isinstance_list.pop()
def test_unify(): assert unify(1, 1, {}) == {} assert unify(1, 2, {}) == False assert unify(var(1), 2, {}) == {var(1): 2} assert unify(2, var(1), {}) == {var(1): 2}