Пример #1
0
def test_map():

    p = Pipe(["1234", "2345", "3456"])

    q = p.map(lambda x: x[1], show_progress=True, eager=True)

    assert q.list_items == ["2", "3", "4"]
Пример #2
0
def test_map_args_kwargs():
    def w(item, ind=1):
        time.sleep(1)
        return item[ind]

    p = Pipe(["1234", "2345", "3456"])
    q = p.map(w, kwargs={"ind": 3}, show_progress=True)
    assert q.list_items == ["4", "5", "6"]
Пример #3
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"]
Пример #4
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)
Пример #5
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]
Пример #6
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"]