Ejemplo n.º 1
0
def test_map_args_callable_object():
    class A:
        def __call__(self, x, r):
            return x[r]

    p = Pipe(["1234", "2345", "3456"])
    q = p.map(A(), args=(2,))
    assert q.list_items == ["3", "4", "5"]
Ejemplo n.º 2
0
def test_not_supressed():
    class A:
        def __call__(self, x, r):
            if x == 5:
                raise ValueError("5 not allowed")

    p = Pipe(range(6))
    with pytest.raises(Exception):
        q = p.map(A(), args=(5,), eager=True)
Ejemplo n.º 3
0
def test_supressed():
    class A:
        def __call__(self, x, r):
            if x == 5:
                raise ValueError("5 not allowed")
            return x

    p = Pipe(range(6))
    q = p.map(A(), args=(2,), eager=True, suppress_errors=True)

    assert q.list_items == [0, 1, 2, 3, 4, None]
Ejemplo n.º 4
0
def test_multimap_sleep_callable_obj():

    p = Pipe(range(10))
    q = p.multi_map(A(), show_progress=True)
Ejemplo n.º 5
0
def test_map_args():

    p = Pipe(["1234", "2345", "3456"])
    q = p.map(lambda x, r: x[r], args=(2,))
    assert q.list_items == ["3", "4", "5"]
Ejemplo n.º 6
0
def test_multimap_sleep():

    p = Pipe(range(10))
    q = p.multi_map(sleeper, show_progress=True)
Ejemplo n.º 7
0
def test_chain():

    p = Pipe([(1, 2, 3), (4, 5, 6, 7)])
    q = p.chain()
    assert q.list_items == [1, 2, 3, 4, 5, 6, 7]
Ejemplo n.º 8
0
def test_split():

    p = Pipe(["a1234", "a2345", "b3456"])
    q = p.split(n=2)
    assert len(q.list_items) == 2
Ejemplo n.º 9
0
def test_group_by():

    p = Pipe(["a1234", "a2345", "b3456"])
    q = p.group_by(key=lambda item: "a" in item)
    assert q.list_items == [(True, ["a1234", "a2345"]), (False, ["b3456"])]
Ejemplo n.º 10
0
def test_multi_map_args_kwargs():

    p = Pipe(["1234", "2345", "3456"])
    q = p.multi_map(globalw, kwargs={"ind": 3})
    assert q.list_items == ["4", "5", "6"]