def test_bind_variables(self): """ Test binding of values """ function = Function({'x': 4}, [ Method(node('x'), node('y')), Method(node('y'), node('z')) ]) bound = function.bind_variables({'y': 10, 'z': 20}) assert_equal(bound, {'x': 4, 'y': 10, 'z': 20}) bound = function.bind_variables( {'y': 10, 'z': 20}, lambda n, x: str(x)) assert_equal(bound, {'x': '4', 'y': '10', 'z': '20'})
def test_bind_variables_bad_bound(self): """ Test that the bind_variables throw the bad_bound exception """ function = Function({'x': None}, [ Method(node('x'), node('y')), Method(node('y'), node('z')) ]) with assert_raises(BadBound): function.bind_variables({}) with assert_raises(BadBound): function.bind_variables({'x': 12, 'y': 10, 'z': 4}) with assert_raises(BadBound): function.bind_variables({'y': 10})