Exemple #1
0
def test_implicit(ser_method):
    assert is_implicit("a") is None
    m = implicit("a")
    assert is_implicit(m) is True
    m = optional("a", implicit=1)
    assert is_implicit(m) is 1

    assert dep_renamed(m, "R")._implicit == m._implicit
    assert ser_method(m)._implicit == m._implicit
 def nester(ra: RenArgs):
     dep = ra.name
     if ra.typ == "op":
         return True
     if ra.typ.endswith(".jsonpart"):
         return False
     if dep == "tasks":
         return True
     # if is_sfxed(dep):
     #     return modifier_withset(
     #         dep, sfx_list=[f"{ra.parent.name}.{s}" for s in dep._sfx_list]
     #     )
     if dep == "daily_tasks":
         return dep_renamed(dep, lambda n: f"{n}/{ra.parent.name}")
     return False
Exemple #3
0
def test_compose_nest_dict(caplog):
    pipe = compose(
        "t",
        compose(
            "p1",
            operation(
                str,
                name="op1",
                needs=[sfx("a"), "aa"],
                provides=[sfxed("S1", "g"), sfxed("S2", "h")],
            ),
        ),
        compose(
            "p2",
            operation(
                str,
                name="op2",
                needs=sfx("a"),
                provides=["a", sfx("b")],
                aliases=[("a", "b")],
            ),
        ),
        nest={
            "op1": True,
            "op2": lambda n: "p2.op2",
            "aa": False,
            sfx("a"): True,
            "b": lambda n: f"PP.{n}",
            sfxed("S1", "g"): True,
            sfxed("S2", "h"): lambda n: dep_renamed(n, "ss2"),
            sfx("b"): True,
        },
    )
    got = str(pipe.ops)
    print(got)
    assert got == re.sub(
        r"[\n ]{2,}",  # collapse all space-chars into a single space
        " ",
        """
        [FnOp(name='p1.op1', needs=[sfx('p1.a'), 'aa'],
         provides=[sfxed('p1.S1', 'g'), sfxed('ss2', 'h')], fn='str'),
        FnOp(name='p2.op2', needs=[sfx('p2.a')],
         provides=['a', sfx('p2.b'), 'PP.b'], aliases=[('a', 'PP.b')], fn='str')]

        """.strip(),
    )
    for record in caplog.records:
        assert record.levelname != "WARNING"
Exemple #4
0
def test_modifs_rename_fn(mod, exp, ser_method):
    renamer = lambda n: f"p.{n}"
    dep = mod()
    got = dep_renamed(dep, renamer)
    assert repr(got) == exp
    assert repr(ser_method(got)) == exp
    assert modifier_kws(got) == modifier_kws(dep)

    if getattr(dep, "_sideffected", None):
        # Check not just(!) `_repr` has changed.
        assert got._sideffected != dep._sideffected

    if getattr(dep, "_jsonp", None):
        assert got._jsonp != dep._jsonp
        assert got._jsonp == jsonp_path(got)
        assert got._jsonp == jsonp_path(str(got))
Exemple #5
0
def test_modifs_rename_str(mod, exp, ser_method):
    got = dep_renamed(mod(), "D")
    print(repr(got))
    assert repr(got) == exp
    assert repr(ser_method(got)) == exp
Exemple #6
0
 def renamer(na):
     assert na.op
     assert not na.parent
     return dep_renamed(na.name, lambda name: f"PP.{name}")