Exemplo n.º 1
0
def test_partition_size_one():
    source = Stream()

    source.partition(1, timeout=.01).sink(lambda x: None)

    for i in range(10):
        source.emit(i)
Exemplo n.º 2
0
def test_partition():
    source = Stream()
    L = source.partition(2).sink_to_list()

    for i in range(10):
        source.emit(i)

    assert L == [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
Exemplo n.º 3
0
def test_partition_key_callable():
    source = Stream()
    L = source.partition(2, key=lambda x: x % 2).sink_to_list()

    for i in range(10):
        source.emit(i)

    assert L == [(0, 2), (1, 3), (4, 6), (5, 7)]
Exemplo n.º 4
0
def test_partition_key():
    source = Stream()
    L = source.partition(2, key=0).sink_to_list()

    for i in range(4):
        source.emit((i % 2, i))

    assert L == [((0, 0), (0, 2)), ((1, 1), (1, 3))]
Exemplo n.º 5
0
def test_partition_timeout():
    source = Stream()
    L = source.partition(10, timeout=0.01).sink_to_list()

    for i in range(5):
        source.emit(i)

    sleep(0.1)

    assert L == [(0, 1, 2, 3, 4)]
Exemplo n.º 6
0
def test_partition_ref_counts():
    source = Stream()
    _ = source.partition(2)

    for i in range(10):
        r = RefCounter()
        source.emit(i, metadata=[{'ref': r}])
        if i % 2 == 0:
            assert r.count == 1
        else:
            assert r.count == 0
Exemplo n.º 7
0
def test_partition_timeout_cancel():
    source = Stream()
    L = source.partition(3, timeout=0.1).sink_to_list()

    for i in range(3):
        source.emit(i)

    sleep(0.09)
    source.emit(3)
    sleep(0.02)

    assert L == [(0, 1, 2)]

    sleep(0.09)

    assert L == [(0, 1, 2), (3, )]
Exemplo n.º 8
0
def test_partition_metadata():
    source = Stream()
    L = metadata(source.partition(2)).sink_to_list()

    source.emit(0)
    source.emit(1, metadata=[{'v': 1}])
    source.emit(2, metadata=[{'v': 2}])
    source.emit(3, metadata=[{'v': 3}])
    assert L == [
        [{
            'v': 1
        }],  # first emit when 1 is introduced. 0 has no metadata
        [{
            'v': 2
        }, {
            'v': 3
        }]  # second emit
    ]
Exemplo n.º 9
0
def test_partition_str():
    source = Stream()
    s = source.partition(2)
    assert str(s) == '<partition; n=2>'