From 9fef36ca98f3dd83f0cd1bd223c061bdfbeb951a Mon Sep 17 00:00:00 2001 From: Alexander Grooff Date: Sat, 9 Jan 2021 11:05:05 +0100 Subject: [PATCH] Test both unify and reifying nonstandard objects Change from the previous commit only affects reifying nonstandard objects, so this change better reflects the new situation. Use the base `unify` and `reify` functions to test instead of the private functions. --- tests/test_more.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_more.py b/tests/test_more.py index 38c5923..440c1be 100644 --- a/tests/test_more.py +++ b/tests/test_more.py @@ -1,4 +1,4 @@ -from ast import Num +import ast from collections.abc import Mapping from unification import var @@ -31,10 +31,11 @@ def test_unify_object(): def test_unify_nonstandard_object(): + _unify.add((ast.AST, ast.AST, Mapping), _unify_object) x = var() - assert stream_eval(_unify_object(Num(n=1), Num(n=1), {})) == {} - assert stream_eval(_unify_object(Num(n=1), Num(n=2), {})) is False - assert stream_eval(_unify_object(Num(n=1), Num(n=x), {})) == {x: 1} + assert unify(ast.Num(n=1), ast.Num(n=1), {}) == {} + assert unify(ast.Num(n=1), ast.Num(n=2), {}) is False + assert unify(ast.Num(n=1), ast.Num(n=x), {}) == {x: 1} def test_reify_object(): @@ -47,6 +48,14 @@ def test_reify_object(): assert stream_eval(_reify_object(f, {})) is f +def test_reify_nonstandard_object(): + _reify.add((ast.AST, Mapping), _reify_object) + x = var() + assert reify(ast.Num(n=1), {}).n == 1 + assert reify(ast.Num(n=x), {}).n == x + assert reify(ast.Num(n=x), {x: 2}).n == 2 + + def test_reify_slots(): class SlotsObject(object): __slots__ = ["myattr"]