Skip to content

Commit

Permalink
Test both unify and reifying nonstandard objects
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AlexanderGrooff authored and brandonwillard committed Jan 9, 2021
1 parent a66b84a commit 9fef36c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tests/test_more.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ast import Num
import ast
from collections.abc import Mapping

from unification import var
Expand Down Expand Up @@ -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():
Expand All @@ -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"]
Expand Down

0 comments on commit 9fef36c

Please sign in to comment.