Exemplo n.º 1
0
def test_store_cache() -> None:
    """Test store for caching."""
    with Fun(MockServer()):
        s = ui.put("bla bla")
        s2 = ui.put(b"bla bla")
        assert s != s2  # type:ignore
        assert ui.take(s) == "bla bla"
        assert ui.take(s2) == b"bla bla"
Exemplo n.º 2
0
def test_store_cache_jsons() -> None:
    """Test store for caching."""
    with Fun(MockServer()):
        # more complex data types
        li = ui.put([1, 2, 3])
        assert ui.take(li) == [1, 2, 3]

        di = ui.put({"fun": 3})
        assert ui.take(di) == {"fun": 3}
Exemplo n.º 3
0
def test_morph() -> None:
    """Test store for caching."""
    with Fun(MockServer()):
        db, store = _context.get_connection()
        dat = ui.put(b"bla bla")
        morph = fp.morph(lambda x: x.decode().upper().encode(), dat)
        run_op(db, store, morph.parent)
        assert ui.take(morph) == b"BLA BLA"

        dat = ui.put("bla bla")
        morph = fp.morph(lambda x: x.upper(), dat, name="CAPITALIZE_THIS")
        run_op(db, store, morph.parent)
        assert ui.take(morph) == "BLA BLA"
Exemplo n.º 4
0
def test_rm() -> None:
    """Test rm."""
    with Fun(MockServer(), options(distributed=False)):
        dat = ui.put("bla bla")
        # removing const artefact raises
        with pytest.raises(AttributeError):
            ui.reset(dat)
        ui.take(dat)

        def upper(x: str) -> str:
            return x.upper()

        m1 = fp.morph(upper, dat)
        m2 = fp.morph(lambda x: x + x, m1)
        ui.execute(m2)
        assert ui.take(m2) == "BLA BLABLA BLA"

        ui.reset(m1)
        with pytest.raises(UnwrapError):
            # deletion works
            ui.take(m1)

        with pytest.raises(UnwrapError):
            # and it's recursive
            ui.take(m2)

        # re run
        ui.execute(m2)
        assert ui.take(m2) == "BLA BLABLA BLA"
Exemplo n.º 5
0
def test_store_takeout() -> None:
    """Test store for caching."""
    with Fun(MockServer()):
        s = ui.put(3)
        with tempfile.NamedTemporaryFile() as f:
            ui.takeout(s, f.name)
            with open(f.name, "r") as f2:
                assert json.loads(f2.read()) == 3
Exemplo n.º 6
0
def test_reduce() -> None:
    """Test store for caching."""
    with Fun(MockServer()):
        db, store = _context.get_connection()
        dat = ui.put("bla bla")
        morph = fp.morph(lambda x: x.upper(), dat)

        def join(x: str, y: str) -> str:
            return x + y

        red = fp.reduce(join, morph, dat)

        run_op(db, store, morph.parent)
        run_op(db, store, red.parent)
        assert ui.take(red) == "BLA BLAbla bla"
Exemplo n.º 7
0
def test_multi_reduce() -> None:
    """Test store for caching."""
    with Fun(MockServer()):
        db, store = _context.get_connection()
        dat = ui.put("bla bla")
        morph = fp.morph(lambda x: x.upper(), dat)

        def join(*x: str) -> str:
            out = ""
            for el in x:
                out += el
            return out

        red = fp.reduce(join, morph, dat, "|wat")

        run_op(db, store, morph.parent)
        run_op(db, store, red.parent)
        assert ui.take(red) == "BLA BLAbla bla|wat"
Exemplo n.º 8
0
def test_py() -> None:
    """Test multiple output py()."""
    with Fun(MockServer()):
        db, store = _context.get_connection()
        dat = ui.put("Bla Bla")

        def fun(a: str) -> Tuple[str, str]:
            return a.upper(), a.lower()

        x1, x2 = fp.py(
            fun,
            dat,
            out=[Encoding.json, Encoding.json],
            strict=True,
        )
        run_op(db, store, x1.parent)
        assert ui.take(x1) == "BLA BLA"
        assert ui.take(x2) == "bla bla"