示例#1
0
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
示例#2
0
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
示例#3
0
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", ), (), {})
示例#4
0
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",), (), {})
示例#5
0
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
示例#6
0
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
示例#7
0
def test_create_named_node():
    g = Graph(node(a, "ping"))

    assert _node_def_equals(g.ping, g, a, ("ping", ), (), {})
示例#8
0
def test_node_named():
    assert node(a, name="boop") == (a, "boop")
示例#9
0
def test_node():
    assert node(a) == (a, None)
示例#10
0
def test_create_named_node():
    g = Graph(node(a, "ping"))

    assert _node_def_equals(g.ping, g, a, ("ping",), (), {})
示例#11
0
def test_node_named():
    assert node(a, name="boop") == (a, "boop")
示例#12
0
def test_node():
    assert node(a) == (a, None)