def test_graph_set_global_params_kwargs(): x_func = lambda data, fudge: data + fudge def y_func(data, fudge=20): return data + fudge # Create simple graph with a global param `fudge` set to 10 # y_func is not an input node so the default value for `fudge` should not be affected there. g = pipe(node(x_func, "x"), node(y_func, "y"))(fudge=10, x=params(data=10)) assert g.x.val == 20 assert g.y.val == 30
def test_eval_node(): g = Graph(node(lambda: 5, name="thunked_const"))() # Direct evaluation assert g.thunked_const() == 5 # Cached evaluation assert g.thunked_const.val == 5
def test_node_callable(): class _Cls(object): def __call__(self): pass inst = _Cls() g = Graph(node(inst, "moof")) assert _node_def_equals(g.moof, g, inst, ("moof", ), (), {})
def test_node_callable(): class _Cls(object): def __call__(self): pass inst = _Cls() g = Graph(node(inst, "moof")) assert _node_def_equals(g.moof, g, inst, ("moof",), (), {})
def test_eval_class_callable(): class _Cls(object): def __init__(self, y): self._y = y def __call__(self, x): return x * self._y inst = _Cls(10) g = Graph(node(inst, "plop"))(plop=params(5)) assert g.plop.val == 50
def test_eval_node_memoized(): def gener(): counter = 0 while True: yield counter counter += 1 g_inst = gener() g = Graph(node(lambda: g_inst.next(), name="accumulator"))() # Assert that direct eval does not cache results assert g.accumulator() == 0 assert g.accumulator() == 1 # Assert that the function is only ever called once and then memoized assert g.accumulator.val == 2 assert g.accumulator.val == 2 assert g.accumulator.val == 2
def test_create_named_node(): g = Graph(node(a, "ping")) assert _node_def_equals(g.ping, g, a, ("ping", ), (), {})
def test_node_named(): assert node(a, name="boop") == (a, "boop")
def test_node(): assert node(a) == (a, None)
def test_create_named_node(): g = Graph(node(a, "ping")) assert _node_def_equals(g.ping, g, a, ("ping",), (), {})