Source code for priops.test.test_direct
"""Tests addition ``X() + Y()``."""
import priops
from priops.test.classes import X, Y, Z
import nose.tools
[docs]def add_xy(x, y):
"""Adds an :class:`~priops.test.classes.X` instance *x* with an
:class:`~priops.test.classes.Y` instance *y*."""
return x.x + y.y
p = priops.Priop()
edge_add_xy = priops.CallableEdge(
input_node=priops.ClassNode(items=[X, Y]),
output_node=priops.ClassNode(item=int),
callable=add_xy, name='Add X + Y')
p.append(edge_add_xy)
cpf = priops.ClassPathfinder(
priop=p, output_node=priops.ClassNode(item=None), max_components=1,
max_weight=1)
[docs]def test_succeeds():
"""Test whether ``X(1) + Y(2) == 3``."""
nose.tools.eq_(cpf(X(1), Y(2)), 3)
@nose.tools.raises(priops.NoPath)
[docs]def test_fails():
"""Tests that ``X(1)`` cannot be coerced with ``Z(3)``."""
cpf(X(1), Z(3))