Exemplo n.º 1
0
def test_merge_mutator_tweets(tweets):
    t1, t2, t3 = map(Tweet, tweets)

    result = []
    sink = to_list(result)
    start = DT(2000, 1, 1, 0, 0, 0)

    def mutator(i, f):
        delta = i.orig_created_at - f.orig_created_at
        i.created_at = start + delta
        return i

    def S(source):
        return lambda target: consume_iterable(
            consumers.mutate(
                target,
                mutator=mutator,
            ),
            source,
        )

    pipes = (S([t1, t2]), sink), (S([t3]), sink)
    merge(
        pipes,
        provider=lambda current: current.created_at,
    )

    assert result == [t1, t3, t2]
    assert [t.created_at for t in result] == [
        DT(2000, 1, 1, 0, 0),
        DT(2000, 1, 1, 0, 0),
        DT(2000, 1, 13, 17, 40, 37),
    ]
Exemplo n.º 2
0
def test_merge_tweets(tweets):
    a = tweets[:1] * 3
    b = tweets[1:2] * 4
    result = []
    sink = to_list(result)

    def S(source):
        t = lambda target: consume_iterable(
            consumers.to_tweet(target),
            source
        )

        return t

    pipes = (S(a), sink), (S(b), sink)
    merge(pipes, provider=lambda current: current.created_at)

    assert [t.created_at for t in result] == [DT(2012, 4, 13, 13, 55, 2),
                                              DT(2012, 4, 13, 13, 55, 2),
                                              DT(2012, 4, 13, 13, 55, 2),
                                              DT(2012, 4, 26, 7, 35, 39),
                                              DT(2012, 4, 26, 7, 35, 39),
                                              DT(2012, 4, 26, 7, 35, 39),
                                              DT(2012, 4, 26, 7, 35, 39),
                                              ]
Exemplo n.º 3
0
def test_merge_mutator_tweets(tweets):
    t1, t2, t3 = map(Tweet, tweets)

    result = []
    sink = to_list(result)
    start = DT(2000, 1, 1, 0, 0, 0)

    def mutator(i, f):
        delta = i.orig_created_at - f.orig_created_at
        i.created_at = start + delta
        return i

    def S(source):
        return lambda target: consume_iterable(
            consumers.mutate(
                target,
                mutator=mutator,
            ),
            source,
        )

    pipes = (S([t1, t2]), sink), (S([t3]), sink)
    merge(
        pipes,
        provider=lambda current: current.created_at,
    )

    assert result == [t1, t3, t2]
    assert [t.created_at for t in result] == [DT(2000, 1, 1, 0, 0),
                                              DT(2000, 1, 1, 0, 0),
                                              DT(2000, 1, 13, 17, 40, 37),
                                              ]
Exemplo n.º 4
0
def test_merge_empty_one():
    result = []
    sink = to_list(result)

    pipes = (
        (lambda target: consume_iterable(target, [1, 2]), sink),
        (lambda target: consume_iterable(target, []), sink),
    )

    merge(pipes)

    assert result == [1, 2]
Exemplo n.º 5
0
def test_merge(a, b):
    result = []
    sink = to_list(result)

    pipes = (
        (lambda target: consume_iterable(target, a), sink),
        (lambda target: consume_iterable(target, b), sink),
    )

    merge(pipes)

    assert result == ['a', 'aa', 'c', 'cc', 'd']
Exemplo n.º 6
0
def test_merge_empty_one():
    result = []
    sink = to_list(result)

    pipes = (
        (lambda target: consume_iterable(target, [1, 2]), sink),
        (lambda target: consume_iterable(target, []), sink),
    )

    merge(pipes)

    assert result == [1, 2]
Exemplo n.º 7
0
def test_merge(a, b):
    result = []
    sink = to_list(result)

    pipes = (
        (lambda target: consume_iterable(target, a), sink),
        (lambda target: consume_iterable(target, b), sink),
    )

    merge(pipes)

    assert result == ['a', 'aa', 'c', 'cc', 'd']
Exemplo n.º 8
0
def test_merge_different_targets(a, b):
    result_a = []
    sink_a = to_list(result_a)
    result_b = []
    sink_b = to_list(result_b)

    pipes = (
        (lambda target: consume_iterable(target, a), sink_a),
        (lambda target: consume_iterable(target, b), sink_b),
    )

    merge(pipes)

    assert result_a == list(a)
    assert result_b == list(b)
Exemplo n.º 9
0
def test_merge_different_targets(a, b):
    result_a = []
    sink_a = to_list(result_a)
    result_b = []
    sink_b = to_list(result_b)

    pipes = (
        (lambda target: consume_iterable(target, a), sink_a),
        (lambda target: consume_iterable(target, b), sink_b),
    )

    merge(pipes)

    assert result_a == list(a)
    assert result_b == list(b)
Exemplo n.º 10
0
def test_merge_mutator(a, b):
    result = []
    sink = to_list(result)

    def S(source):
        return lambda target: consume_iterable(
            consumers.mutate(
                target,
                mutator=lambda i, _: i.upper(),
            ),
            source,
        )

    pipes = (S(a), sink), (S(b), sink)
    merge(pipes)

    assert result == ['A', 'AA', 'C', 'CC', 'D']
Exemplo n.º 11
0
def test_merge_mutator(a, b):
    result = []
    sink = to_list(result)

    def S(source):
        return lambda target: consume_iterable(
            consumers.mutate(
                target,
                mutator=lambda i, _: i.upper(),
            ),
            source,
        )

    pipes = (S(a), sink), (S(b), sink)
    merge(pipes)

    assert result == ['A', 'AA', 'C', 'CC', 'D']
Exemplo n.º 12
0
def test_merge_tweets(tweets):
    a = tweets[:1] * 3
    b = tweets[1:2] * 4
    result = []
    sink = to_list(result)

    def S(source):
        t = lambda target: consume_iterable(consumers.to_tweet(target), source)

        return t

    pipes = (S(a), sink), (S(b), sink)
    merge(pipes, provider=lambda current: current.created_at)

    assert [t.created_at for t in result] == [
        DT(2012, 4, 13, 13, 55, 2),
        DT(2012, 4, 13, 13, 55, 2),
        DT(2012, 4, 13, 13, 55, 2),
        DT(2012, 4, 26, 7, 35, 39),
        DT(2012, 4, 26, 7, 35, 39),
        DT(2012, 4, 26, 7, 35, 39),
        DT(2012, 4, 26, 7, 35, 39),
    ]