Exemplo n.º 1
0
def test_apply_error():
    # check that the additional print statements works
    # invalid rule object (no match / apply methods)
    rules = [None]

    with pytest.raises(AttributeError):
        apply(None, None, rules)
Exemplo n.º 2
0
def test_toolz_reduceby__is_not_supported():
    from toolz.curried import reduceby

    transform = reduceby(lambda i: i % 2, lambda a, b: a + b)
    data = db.from_sequence([1, 2, 3, 4, 5, 6, 7], npartitions=3)

    with pytest.raises(ValueError):
        apply(transform, data).compute()
Exemplo n.º 3
0
def test_generic_callable():
    obj = db.from_sequence(range(10), npartitions=3)

    actual = apply(lambda bag: bag.sum(), obj)
    expected = sum(range(10))

    assert actual.compute() == expected
Exemplo n.º 4
0
def test_flowly_tz_update_dict():
    obj = dict(l=db.from_sequence([1, 2, 3, 4], npartitions=3))

    transform = itemsetter(
        # varargs are also allowed
        dict(max=chained(op.itemgetter('l'), max)),
        min=chained(op.itemgetter('l'), min),
        sum=chained(op.itemgetter('l'), sum),
    )

    actual = apply(transform, obj).compute()

    assert actual == dict(l=[1, 2, 3, 4], min=1, max=4, sum=10)
Exemplo n.º 5
0
except ImportError:
    import builtins

import math
import operator as op

import dask.bag as db
import pytest

from flowly.dsk import apply
from flowly.tz import apply_concat, chained, seq

executors = [
    lambda graph, obj: graph(obj),
    lambda graph, obj: apply(graph, obj).compute(),
]


@pytest.mark.parametrize('executor', executors)
def test_dags(executor):
    # build dags by using itemgetter and dicts
    scope = dict(
        a=db.from_sequence(range(0, 10), npartitions=3),
        b=db.from_sequence(range(10, 20), npartitions=3),
        c=db.from_sequence(range(20, 30), npartitions=3),
    )

    graph = chained(
        apply_concat([
            chained(op.itemgetter('a'), sum, seq),
Exemplo n.º 6
0
def test_unknown_func():
    obj = db.from_sequence(range(10), npartitions=3)

    with pytest.raises(ValueError):
        apply(obj, None)
Exemplo n.º 7
0
def test_flowly_tz_seq():
    obj = item_from_object(42)
    actual = apply(seq, obj)

    assert actual.compute() == [42]
Exemplo n.º 8
0
except ImportError:
    import builtins

import math
import operator as op

import dask.bag as db
import pytest

from flowly.dsk import apply
from flowly.tz import apply_concat, chained, seq

executors = [
    lambda graph, obj: graph(obj),
    lambda graph, obj: apply(graph, obj).compute(),
]


@pytest.mark.parametrize('executor', executors)
def test_dags(executor):
    # build dags by using itemgetter and dicts
    scope = dict(
        a=db.from_sequence(range(0, 10), npartitions=3),
        b=db.from_sequence(range(10, 20), npartitions=3),
        c=db.from_sequence(range(20, 30), npartitions=3),
    )

    graph = chained(
        apply_concat([
            chained(op.itemgetter('a'), sum, seq),