예제 #1
0
def test_solution_accessor_simple():
    acc = (operator.contains, operator.getitem, operator.setitem,
           operator.delitem)

    copy_values = compose(
        "copy values in solution: a+b-->A+BB",
        operation(
            (lambda *a: a),
            needs=[modify("a", accessor=acc),
                   modify("b", accessor=acc)],
            provides=[modify("A", accessor=acc),
                      modify("BB", accessor=acc)],
        ),
    )
    sol = copy_values.compute({"a": 1, "b": 2})
    assert sol == {"a": 1, "b": 2, "A": 1, "BB": 2}
예제 #2
0
def test_jsonp_and_conveyor_fn_complex_NOT_LAYERED(solution_layered_false):
    pipe = compose(
        "t",
        operation(
            name="op1",
            needs=["i/a", "i/a"],  # dupe jsonp needs
            provides=["r/a", modify("a")],
        )(),
        operation(lambda x: (x, 2 * x),
                  name="op2",
                  needs=["r/a"],
                  provides=["r/A", "r/AA"]),
    )
    inp = {"i": {"a": 1}}
    sol = pipe.compute(inp, layered_solution=solution_layered_false)
    assert sol == {**inp, "r": {"a": 1, "A": 1, "AA": 2}, "a": 1}
    sol = pipe.compute(inp,
                       outputs="r",
                       layered_solution=solution_layered_false)
    assert sol == {"r": {"a": 1, "A": 1, "AA": 2}}
    sol = pipe.compute(inp,
                       outputs=["r/A", "r/AA"],
                       layered_solution=solution_layered_false)
    assert sol == {
        "r": {
            "a": 1,
            "A": 1,
            "AA": 2
        }
    }  ## FIXME: should have evicted r/a!
    sol = pipe.compute(inp,
                       outputs="r/AA",
                       layered_solution=solution_layered_false)
    assert sol == {"r": {"a": 1, "AA": 2}}  ## FIXME: should have evicted r/a!
예제 #3
0
def test_jsonp_disabled():
    no_jsonp_res = operation(
        fn=None,
        name="copy a+b-->A+BB",
        needs=[modify("inputs/a"), modify("inputs/b")],
        provides=["RESULTS/A", modify("RESULTS/BB", jsonp=False)],
    )
    assert "provides=['RESULTS/A'($), RESULTS/BB" in str(no_jsonp_res)
    res = compose("", no_jsonp_res).compute({"inputs": {"a": 1, "b": 2}})
    assert res == {
        "inputs": {
            "a": 1,
            "b": 2
        },
        "RESULTS": {
            "A": 1
        },
        "RESULTS/BB": 2
    }

    no_jsonp_inp = operation(
        name="copy a+b-->A+BB",
        needs=["inputs/a", modify("inputs/b", jsonp=False)],
        provides=["RESULTS/A", "RESULTS/BB"],
    )()
    assert "needs=['inputs/a'($), inputs/b]" in str(no_jsonp_inp)
    res = compose("", no_jsonp_inp).compute({
        "inputs": {
            "a": 1
        },
        "inputs/b": 2
    })
    assert res == {
        "inputs": {
            "a": 1
        },
        "inputs/b": 2,
        "RESULTS": {
            "A": 1,
            "BB": 2
        }
    }
예제 #4
0
            not in "_repr _func _sideffected _sfx_list _keyword _optional _jsonp".split()
        }
    return {}


def test_serialize_modifier(ser_method):
    s = sfxed("foo", "gg")
    assert repr(ser_method(s)) == repr(s)
    assert modifier_kws(ser_method(s)) == modifier_kws(s)


## construct in lambdas, not to crash pytest while modifying core _Modifier
@pytest.mark.parametrize(
    "mod, exp",
    [
        (lambda: modify("b", accessor=acc), "b"),
        (lambda: keyword("b", None), "b"),
        (lambda: keyword("b", ""), "b"),
        (lambda: keyword("b", "bb"), "b"),
        (lambda: optional("b"), "b"),
        (lambda: optional("b", "bb"), "b"),
        (lambda: vararg("c"), "c"),
        (lambda: varargs("d"), "d"),
        (lambda: modify("/d"), "/d"),
        (lambda: modify("/d/"), "/d/"),
        (lambda: modify("/d", jsonp=False), "/d"),
        (lambda: modify("/d/", jsonp=False), "/d/"),
        (lambda: sfx("e"), "sfx('e')"),
        (lambda: sfx("e", optional=1), "sfx('e')"),
        (lambda: sfxed("f", "a", "b"), "sfxed('f', 'a', 'b')"),
        (lambda: sfxed("f", "ff", keyword="F"), "sfxed('f', 'ff')"),