Exemplo n.º 1
0
def test_chunk_size():
    assert (DistributedQuery(range(100), processes=2,
                             chunk_size=23).select(square).count() == 100)
    assert (DistributedQuery(range(10000), processes=2,
                             chunk_size=70).select(square).count() == 10000)
    assert (DistributedQuery(range(100), processes=2,
                             chunk_size=1000).select(square).count() == 100)
Exemplo n.º 2
0
def test_first_or_none():
    assert DistributedQuery(range(100),
                            processes=2).first_or_none(greater_than_0) > 0

    assert (DistributedQuery(
        range(100),
        processes=2).select(negative_square).first_or_none(greater_than_0) is
            None)
Exemplo n.º 3
0
def test_distributed_query_multiple_processes():
    assert DistributedQuery(range(100), processes=2).select(square).min() == 0
Exemplo n.º 4
0
def test_flatten():
    y = (DistributedQuery([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                          processes=2).flatten().to_list())
    for x in range(1, 10):
        assert x in y
Exemplo n.º 5
0
def test_contains_2():
    assert not DistributedQuery(range(100), processes=2).contains(-1)
Exemplo n.º 6
0
def test_where():
    assert (DistributedQuery(range(100),
                             processes=2).where(smaller_than_10).count() == 10)
Exemplo n.º 7
0
def test_any_2():
    assert (not DistributedQuery(range(
        10, 100), processes=2).select(add_1).any(smaller_than_10))
Exemplo n.º 8
0
def test_all_2():
    assert not DistributedQuery(range(100), processes=2).all(smaller_than_10)
Exemplo n.º 9
0
def test_context_manager():
    with DistributedQuery(range(100), processes=2) as q:
        next(iter(q))
Exemplo n.º 10
0
def test_last():
    with pytest.raises(errors.NoSuchElementError):
        DistributedQuery(
            range(100),
            processes=2).select(negative_square).last(greater_than_0)
Exemplo n.º 11
0
def test_take_one_and_close():
    q = DistributedQuery(range(100), processes=4)
    iterator = iter(q)
    next(iterator)
    q.close()
Exemplo n.º 12
0
def test_argmin():
    assert DistributedQuery(range(-4, 5)).argmin(square) == 0
Exemplo n.º 13
0
def test_argmax():
    assert DistributedQuery(range(-4, 5)).argmax(negative_square) == 0
Exemplo n.º 14
0
def test_long_query():
    assert (DistributedQuery(range(100), processes=2).select(square).where(
        smaller_than_10).select(square).where(greater_than_0).count() == 3)
Exemplo n.º 15
0
def test_sum():
    assert DistributedQuery(range(100), processes=2).sum() == 4950
Exemplo n.º 16
0
def test_all_1():
    assert DistributedQuery(range(100),
                            processes=2).select(add_1).all(greater_than_0)
Exemplo n.º 17
0
def test_mean():
    assert DistributedQuery(range(100),
                            processes=2).select(square).mean() == 3283.5
Exemplo n.º 18
0
def test_any_1():
    assert DistributedQuery(range(100),
                            processes=2).select(square).any(greater_than_0)
Exemplo n.º 19
0
def test_to_dict():
    dict_ = DistributedQuery(range(100), processes=2).to_dict(str, square)
    assert set(dict_.keys()) == {str(x) for x in range(100)}
    assert set(dict_.values()) == {x**2 for x in range(100)}
Exemplo n.º 20
0
def test_count():
    assert DistributedQuery(range(100), processes=2).count() == 100
Exemplo n.º 21
0
def test_sleep():
    assert DistributedQuery(range(9), processes=3).select(wait).count() == 9
Exemplo n.º 22
0
def test_contains_1():
    assert DistributedQuery(range(100), processes=2).contains(50)
Exemplo n.º 23
0
def test_distributed_query_single_process():
    assert DistributedQuery(range(100),
                            processes=1).select(square).max() == 99**2
Exemplo n.º 24
0
def test_contains_3():
    assert 50 in DistributedQuery(range(100), processes=2)
Exemplo n.º 25
0
def test_contains_4():
    assert -1 not in DistributedQuery(range(100), processes=2)